-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ADORSYS-GIS/feat-create-project-ledgers-d…
…eposit-account-rest-api Implement ledgers deposit rest api
- Loading branch information
Showing
25 changed files
with
865 additions
and
8 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
66 changes: 66 additions & 0 deletions
66
...unt-rest-api/src/main/java/de/adorsys/ledgers/deposit/api/exception/ExceptionAdvisor.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,66 @@ | ||
/* | ||
* Copyright (c) 2018-2024 adorsys GmbH and Co. KG | ||
* All rights are reserved. | ||
*/ | ||
|
||
package de.adorsys.ledgers.deposit.api.exception; | ||
|
||
import de.adorsys.ledgers.util.exception.DepositModuleException; | ||
import feign.FeignException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@ControllerAdvice | ||
public class ExceptionAdvisor { | ||
private static final String MESSAGE = "message"; | ||
private static final String DEV_MESSAGE = "devMessage"; | ||
private static final String CODE = "code"; | ||
private static final String ERROR_CODE = "errorCode"; | ||
private static final String DATE_TIME = "dateTime"; | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<Map<String,String>> globalExceptionHandler(Exception ex) { | ||
HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; | ||
Map<String, String> body = getHandlerContent(status, null, null, "Something went wrong during execution of your request."); | ||
log.error("INTERNAL SERVER ERROR", ex); | ||
return new ResponseEntity<>(body, status); | ||
} | ||
|
||
|
||
@ExceptionHandler(DepositModuleException.class) | ||
public ResponseEntity<Map<String,String>> handleDepositModuleException(DepositModuleException ex) { | ||
HttpStatus status = DepositHttpStatusResolver.resolveHttpStatusByCode(ex.getErrorCode()); | ||
Map<String, String> body = getHandlerContent(status, ex.getErrorCode().name(), null, ex.getDevMsg()); | ||
log.error(ex.getDevMsg()); | ||
return new ResponseEntity<>(body, status); | ||
} | ||
|
||
@ExceptionHandler(FeignException.class) | ||
public ResponseEntity<Map<String,String>> handleFeignException(FeignException ex) { | ||
HttpStatus status = HttpStatus.CONFLICT; | ||
Map<String, String> body = getHandlerContent(status, "Internal Rest Exception!", null, "Something went wrong during server internal interaction. \nPlease consult your bank for details."); | ||
log.error(ex.contentUTF8()); | ||
return new ResponseEntity<>(body, status); | ||
} | ||
|
||
|
||
//TODO Consider a separate Class for this with a builder? | ||
private Map<String, String> getHandlerContent(HttpStatus status, String errorCode, String message, String devMessage) { | ||
Map<String, String> error = new HashMap<>(); | ||
error.put(CODE, String.valueOf(status.value())); | ||
Optional.ofNullable(errorCode).ifPresent(e -> error.put(ERROR_CODE, e)); | ||
error.put(MESSAGE, message); | ||
error.put(DEV_MESSAGE, devMessage); | ||
error.put(DATE_TIME, LocalDateTime.now().toString()); | ||
return error; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...rest-api/src/main/java/de/adorsys/ledgers/deposit/api/resource/AccountMgmResourceAPI.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,72 @@ | ||
/* | ||
* Copyright (c) 2018-2024 adorsys GmbH and Co. KG | ||
* All rights are reserved. | ||
*/ | ||
|
||
package de.adorsys.ledgers.deposit.api.resource; | ||
|
||
import de.adorsys.ledgers.deposit.api.domain.account.AccountDetailsTO; | ||
import de.adorsys.ledgers.deposit.api.domain.payment.AmountTO; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import static de.adorsys.ledgers.deposit.api.utils.Constants.*; | ||
|
||
@Tag(name = "LDG022 - Accounts (Deposit Account)", description = "Provides access to the deposit account resource for members.") | ||
public interface AccountMgmResourceAPI { | ||
|
||
String BASE_PATH = "/AccountManagement"; | ||
|
||
|
||
|
||
/** | ||
* Creates a new deposit account for a user specified by ID | ||
* Account is created for the same branch as user | ||
* | ||
* @param userId user for who account is created | ||
* @param accountDetailsTO account details | ||
* @return Void | ||
*/ | ||
@Operation(summary = "Registers a new Deposit Account for a user with specified ID", | ||
description = "Registers a new deposit account and assigns account access OWNER to the current user.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Account creation successful"), | ||
@ApiResponse(responseCode = "404", description = "User with this ID not found"), | ||
@ApiResponse(responseCode = "409", description = "Account with given IBAN already exists.") | ||
}) | ||
@PostMapping | ||
ResponseEntity<Boolean> createDepositAccountForUser(@RequestParam(name = USER_ID) String userId, | ||
@RequestBody AccountDetailsTO accountDetailsTO); | ||
|
||
|
||
@GetMapping("/{accountId}") | ||
ResponseEntity<AccountDetailsTO> getAccountDetailsById(@Parameter(name = ACCOUNT_ID) @PathVariable(ACCOUNT_ID) String accountId); | ||
|
||
/** | ||
* Operation deposits cash to the deposit account | ||
* | ||
* @param accountId Account ID in Ledgers | ||
* @param amount Amount to be deposited | ||
* @return Void | ||
*/ | ||
@Operation(summary = "Deposit Cash", | ||
description = "Operation for a member to register cash in the deposit account") | ||
|
||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "202", description = "Operation was successful") | ||
}) | ||
@PostMapping("/{accountId}/cash") | ||
ResponseEntity<Void> depositCash(@PathVariable(ACCOUNT_ID) String accountId, @RequestBody AmountTO amount); | ||
|
||
@Operation(summary = "Load Extended Account Details by AccountId", | ||
description = "Returns extended account details information for the given account id. " | ||
+ "User must have access to the target account. This is also accessible to other token types like tpp token (DELEGATED_ACESS)") | ||
|
||
@PostMapping("/{accountId}/status") | ||
ResponseEntity<Boolean> changeStatus(@PathVariable(ACCOUNT_ID) String accountId);} |
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
30 changes: 30 additions & 0 deletions
30
...st-api/src/main/java/de/adorsys/ledgers/deposit/api/resource/TransactionsResourceAPI.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,30 @@ | ||
/* | ||
* Copyright (c) 2018-2023 adorsys GmbH and Co. KG | ||
* All rights are reserved. | ||
*/ | ||
|
||
package de.adorsys.ledgers.deposit.api.resource; | ||
|
||
import de.adorsys.ledgers.deposit.api.domain.account.BookingDetails; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Tag(name = "LDG014 - Transactions upload") | ||
public interface TransactionsResourceAPI { | ||
String BASE_PATH = "/transactions"; | ||
|
||
/** | ||
* Registers a new user within a given branch. | ||
* | ||
* @return user object without pin | ||
*/ | ||
@Operation(summary = "Posts transactions to Ledgers") | ||
@PostMapping | ||
ResponseEntity<Map<String, String>> transactions(@RequestBody List<BookingDetails> data); | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...st-api/src/test/java/de/adorsys/ledgers/deposit/api/exception/HttpStatusResolverTest.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,32 @@ | ||
/* | ||
* Copyright (c) 2018-2024 adorsys GmbH and Co. KG | ||
* All rights are reserved. | ||
*/ | ||
|
||
package de.adorsys.ledgers.deposit.api.exception; | ||
|
||
import de.adorsys.ledgers.util.exception.DepositErrorCode; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
|
||
@Slf4j | ||
class HttpStatusResolverTest { | ||
@Test | ||
void testDepositStatusResolverCoverage() { | ||
List<DepositErrorCode> codes = Arrays.asList(DepositErrorCode.values()); | ||
codes.forEach(c -> { | ||
boolean isNull = DepositHttpStatusResolver.resolveHttpStatusByCode(c) == null; | ||
if (isNull) { | ||
log.error("{} is missing in Resolver", c.name()); | ||
} | ||
assertFalse(isNull); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.