Skip to content

Commit

Permalink
Merge pull request #137 from NkwaTambe/feature/4-Implement-the-checkB…
Browse files Browse the repository at this point in the history
…alance

feat(backend): Update API endpoint to use phone number for balance ch…
  • Loading branch information
NkwaTambe authored Jun 12, 2024
2 parents df6551c + 0ac8bd5 commit 7d992cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

@Repository
public interface UserRepository extends JpaRepository<User, String> {

Optional<User> findByPhoneNumber(String phoneNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

//implementing an empty interface
public interface CheckBalance {
Double checkBalance(String userId) throws UsernameNotFoundException;
Double checkBalance(String phoneNumber) throws UsernameNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public CheckBalanceController(CheckBalance checkBalanceService, UserRepository u
this.userRepository = userRepository;
}

@GetMapping("/{userId}")
public ResponseEntity<String> checkBalance(@PathVariable String userId) {
Optional<User> user = userRepository.findByPhoneNumber(userId);

@GetMapping("/{phoneNumber}")
public ResponseEntity<String> checkBalance(@PathVariable String phoneNumber) {
Optional<User> user = userRepository.findByPhoneNumber(phoneNumber);
if (user.isPresent()) {
Double balance = checkBalanceService.checkBalance(userId);
return ResponseEntity.ok("Balance for user ID" + " : " + balance);
Double balance = checkBalanceService.checkBalance(phoneNumber);
return ResponseEntity.ok("Balance for user phoneNumber" + " : " + balance);

} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found");
}
}
}

0 comments on commit 7d992cb

Please sign in to comment.