Skip to content

Commit

Permalink
Add get mapping for check balance
Browse files Browse the repository at this point in the history
  • Loading branch information
bifrurcated committed Jan 13, 2024
1 parent b9f08e0 commit 0d1b10d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.UUID;

@RestController
@RequestMapping("api/v1/wallet")
@RequestMapping("/api/v1")
public class WalletController {

private final WalletService walletService;
Expand Down Expand Up @@ -40,4 +40,11 @@ public WalletResponse wallet(@RequestBody WalletRequest request) {

return new WalletResponse(wallet.getId(), wallet.getAmount());
}

public record BalanceResponse(Float amount){}
@GetMapping("/wallets/{WALLET_UUID}")
public BalanceResponse balance(@PathVariable(value = "WALLET_UUID") UUID id) {
Float amount = walletService.amount(id);
return new BalanceResponse(amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;
import java.util.UUID;


Expand Down Expand Up @@ -39,7 +38,7 @@ public Wallet reduceAmount(UUID id, Float amount) {
return walletRepo.save(wallet);
}

public void amount() {

public Float amount(UUID id) {
return walletRepo.findById(id).orElseThrow(WalletNotFoundError::new).getAmount();
}
}

0 comments on commit 0d1b10d

Please sign in to comment.