-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,021 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...va/com/adorsys/gis/powerpay/powerpaybackend/errorhandling/InsufficientFundsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.errorhandling; | ||
|
||
public class InsufficientFundsException extends RuntimeException { | ||
|
||
private final String message; | ||
|
||
public InsufficientFundsException(String message) { | ||
super(message); | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ain/java/com/adorsys/gis/powerpay/powerpaybackend/repository/MoneyTransferRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.repository; | ||
|
||
import com.adorsys.gis.powerpay.powerpaybackend.domain.Transaction; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MoneyTransferRepository extends JpaRepository<Transaction, String> { | ||
} |
15 changes: 15 additions & 0 deletions
15
.../main/java/com/adorsys/gis/powerpay/powerpaybackend/repository/TransactionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.repository; | ||
|
||
import com.adorsys.gis.powerpay.powerpaybackend.domain.Transaction; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
@Repository | ||
public interface TransactionRepository extends JpaRepository<Transaction, Long> { | ||
|
||
@Query("SELECT SUM(CASE WHEN t.receiverPhoneNumber = :phoneNumber THEN t.amount ELSE -t.amount END) " + | ||
"FROM Transaction t WHERE t.receiverPhoneNumber = :phoneNumber OR t.phoneNumber = :phoneNumber") | ||
|
||
Double calculateBalaceByPhoneNumber(String phoneNumber); | ||
} |
8 changes: 8 additions & 0 deletions
8
.../java/com/adorsys/gis/powerpay/powerpaybackend/repository/UserRegistrationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import com.adorsys.gis.powerpay.powerpaybackend.domain.UserRegistration; | ||
|
||
public interface UserRegistrationRepository extends JpaRepository<UserRegistration, Integer> { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...end/src/main/java/com/adorsys/gis/powerpay/powerpaybackend/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.repository; | ||
|
||
import com.adorsys.gis.powerpay.powerpaybackend.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface UserRepository extends JpaRepository<User, String> { | ||
Optional<User> findByPhoneNumber(String phoneNumber); | ||
} |
3 changes: 3 additions & 0 deletions
3
...backend/src/main/java/com/adorsys/gis/powerpay/powerpaybackend/services/CheckBalance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.services; | ||
|
||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
//implementing an empty interface | ||
public interface CheckBalance { | ||
Double checkBalance(String userId) throws UsernameNotFoundException; | ||
} |
38 changes: 38 additions & 0 deletions
38
...c/main/java/com/adorsys/gis/powerpay/powerpaybackend/services/CheckBalanceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.services; | ||
|
||
import com.adorsys.gis.powerpay.powerpaybackend.domain.User; | ||
import com.adorsys.gis.powerpay.powerpaybackend.repository.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/api/balance") | ||
public class CheckBalanceController { | ||
@Autowired | ||
private final CheckBalance checkBalanceService; | ||
private final UserRepository userRepository; | ||
|
||
@Autowired | ||
public CheckBalanceController(CheckBalance checkBalanceService, UserRepository userRepository) { | ||
this.checkBalanceService = checkBalanceService; | ||
this.userRepository = userRepository; | ||
} | ||
|
||
@GetMapping("/{userId}") | ||
public ResponseEntity<String> checkBalance(@PathVariable String userId) { | ||
Optional<User> user = userRepository.findByPhoneNumber(userId); | ||
if (user.isPresent()) { | ||
Double balance = checkBalanceService.checkBalance(userId); | ||
return ResponseEntity.ok("Balance for user ID" + " : " + balance); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found"); | ||
} | ||
} | ||
} |
18 changes: 17 additions & 1 deletion
18
...end/src/main/java/com/adorsys/gis/powerpay/powerpaybackend/services/CheckBalanceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.services; | ||
|
||
import com.adorsys.gis.powerpay.powerpaybackend.repository.TransactionRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service // annotation to ensure classes are recognized as Spring Beans | ||
public class CheckBalanceImpl implements CheckBalance { | ||
|
||
private final TransactionRepository transactionRepository; | ||
|
||
@Autowired | ||
public CheckBalanceImpl(TransactionRepository transactionRepository){ | ||
|
||
this.transactionRepository = transactionRepository; | ||
} | ||
|
||
@Override | ||
public Double checkBalance(String phoneNumber) throws UsernameNotFoundException{ | ||
Double balance = transactionRepository.calculateBalaceByPhoneNumber(phoneNumber); | ||
return balance != null ? balance : 0.0; | ||
} | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
...ay-backend/src/main/java/com/adorsys/gis/powerpay/powerpaybackend/services/SendMoney.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.adorsys.gis.powerpay.powerpaybackend.services; | ||
import com.adorsys.gis.powerpay.powerpaybackend.domain.Transaction; | ||
|
||
//implementing an empty interface | ||
public interface SendMoney { | ||
Transaction send(String phoneNumber, String receiverPhoneNumber, Double amount, String currency, Integer id); | ||
} |
Oops, something went wrong.