Skip to content

Commit

Permalink
feat: Approve transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
M4rc0Russ0 committed Aug 6, 2024
1 parent 6f1cc8e commit 56662a4
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.vavr.control.Either;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,8 +20,10 @@
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.BatchSearchRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.ExtractionRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.SearchRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.TransactionsApprove;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.BatchView;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.BatchsDetailView;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.TransactionProcessView;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.TransactionView;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -63,14 +66,14 @@ public ResponseEntity<?> listAllAction(@Valid @RequestBody SearchRequest body) {
{@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = TransactionView.class))}
)
})
@GetMapping(value = "/transactions/{transactionId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> transactionDetailSpecific(@Valid @PathVariable("transactionId") @Parameter(example = "7e9e8bcbb38a283b41eab57add98278561ab51d23a16f3e3baf3daa461b84ab4") String transactionId) {
@GetMapping(value = "/transactions/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> transactionDetailSpecific(@Valid @PathVariable("id") @Parameter(example = "7e9e8bcbb38a283b41eab57add98278561ab51d23a16f3e3baf3daa461b84ab4") String id) {

val transactionEntity = accountingCorePresentationService.transactionDetailSpecific(transactionId);
val transactionEntity = accountingCorePresentationService.transactionDetailSpecific(id);
if (transactionEntity.isEmpty()) {
val issue = Problem.builder()
.withTitle("TX_NOT_FOUND")
.withDetail(STR."Transaction with id: {\{transactionId}} could not be found")
.withDetail(STR."Transaction with id: {\{id}} could not be found")
.withStatus(Status.NOT_FOUND)
.build();

Expand Down Expand Up @@ -105,7 +108,7 @@ public ResponseEntity<?> transactionType() throws JSONException {
@Tag(name = "Transactions", description = "Transactions API")
@Operation(description = "Rejection types", responses = {
@ApiResponse(content =
{@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = RejectionCode.class)))}
{@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = RejectionCode.class)))}
)
})
@GetMapping(value = "/rejection-types", produces = MediaType.APPLICATION_JSON_VALUE, name = "Rejection types")
Expand Down Expand Up @@ -158,6 +161,29 @@ public ResponseEntity<?> extractionTrigger(@Valid @RequestBody ExtractionRequest
.body(response.toString());
}

@Tag(name = "Transactions", description = "Transactions API")
@PostMapping(value = "/transactions/approve", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "Approve transactions",
responses = {
@ApiResponse(content = {
@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(implementation = TransactionProcessView.class)))
})
}
)
public ResponseEntity<?> approveTransaction(@Valid @RequestBody TransactionsApprove transactionsApprove) {
val resul = accountingCorePresentationService.approveTransaction(transactionsApprove.getTransactionApproves());

if (resul.isEmpty()) {
return ResponseEntity
.status(HttpStatusCode.valueOf(404))
.body(resul);
}

return ResponseEntity
.status(HttpStatusCode.valueOf(202))
.body(resul);
}

@Tag(name = "Batchs", description = "Batchs API")
@PostMapping(value = "/batchs", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "Batch list",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cardanofoundation.lob.app.accounting_reporting_core.resource.model;

import io.vavr.control.Either;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -10,10 +11,13 @@
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.BatchSearchRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.ExtractionRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.SearchRequest;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests.TransactionApprove;
import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.*;
import org.cardanofoundation.lob.app.accounting_reporting_core.service.internal.AccountingCoreService;
import org.jmolecules.ddd.annotation.Service;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.zalando.problem.Problem;

import java.math.BigDecimal;
import java.time.LocalDate;
Expand Down Expand Up @@ -137,6 +141,35 @@ public void extractionTrigger(ExtractionRequest body) {

}

@Transactional
public List<TransactionProcessView> approveTransaction(List<TransactionApprove> transactionApproves) {

List<TransactionProcessView> transactionProcessViews = new java.util.ArrayList<>(List.of());
for (TransactionApprove trabsactionAp : transactionApproves) {

Either<Problem, Boolean> valor = accountingCoreService.approveTransaction(trabsactionAp.getId());

val resu = valor.fold(problem -> {
return new TransactionProcessView(
trabsactionAp.getId(),
valor.isRight(),
valor.getLeft()
);
}, success -> {
return new TransactionProcessView(
trabsactionAp.getId(),
valor.isRight(),
Problem.builder().build()
);
});


transactionProcessViews.add(resu);
}

return transactionProcessViews;
}

private Set<TransactionView> getTransaction(TransactionBatchEntity transactionBatchEntity) {
return transactionBatchEntity.getTransactions().stream()
.map(this::getTransactionView)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class TransactionApprove {
//48335c2b63cffcef2a3cd0678b65c4fb16420f51110033024209957fbd58ec4e
@Schema(example = "7e9e8bcbb38a283b41eab57add98278561ab51d23a16f3e3baf3daa461b84ab4")
private String id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cardanofoundation.lob.app.accounting_reporting_core.resource.requests;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class TransactionsApprove {
@ArraySchema(arraySchema = @Schema(example = "[ {" +
"\"id\": \"7e9e8bcbb38a283b41eab57add98278561ab51d23a16f3e3baf3daa461b84ab4\"}," +
"{\"id\": \"7bce71783ff8e6501b33ce9797097f5633c069f17e4731d96467cdb311693fcb\"}," +
"{\"id\": \"38e7e04304c86c1156128f7bdc548d51f175d5bdf83df1b3edda1832cac385dd\"}," +
"{\"id\": \"95b5fb0d3ea32847d9d6bda2ff9da0be11bd5ba3175aad6f3cacafd14f9d28a3\"}," +
"{\"id\": \"8b346f4d914fe652bde477fa3f6b630fbcf7ffd9859daf8df4fc63cdd1562e5c\"}," +
"{\"id\": \"48335c2b63cffcef2a3cd0678b65c4fb16420f51110033024209957fbd58ec4e\"}" +
"]"))

private List<TransactionApprove> transactionApproves;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cardanofoundation.lob.app.accounting_reporting_core.resource.views;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.zalando.problem.Problem;

@Getter
@Setter
@AllArgsConstructor
public class TransactionProcessView {

private String id;

private Boolean success = false;

private Problem error;
}

0 comments on commit 56662a4

Please sign in to comment.