Skip to content

Commit

Permalink
[PAGOPA-1618] adjustment to doc: first impl (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: pagopa-github-bot <[email protected]>
Co-authored-by: aacitelli <[email protected]>
  • Loading branch information
3 people authored Mar 26, 2024
1 parent d544d7d commit 343cdc7
Show file tree
Hide file tree
Showing 13 changed files with 3,107 additions and 3,455 deletions.
2,950 changes: 1,379 additions & 1,571 deletions openapi/openapi.json

Large diffs are not rendered by default.

1,061 changes: 499 additions & 562 deletions openapi/openapi_ec.json

Large diffs are not rendered by default.

1,409 changes: 686 additions & 723 deletions openapi/openapi_helpdesk.json

Large diffs are not rendered by default.

1,042 changes: 467 additions & 575 deletions openapi/openapi_io.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public interface ITransactionController {
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, array = @ArraySchema(schema = @Schema(name = "TransactionListItem", implementation = TransactionListItem.class)))),
@ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found the transaction.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "422", description = "Unable to process the request.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@Operation(summary = "Retrieve the paged transaction list from biz events.", security = {
Expand All @@ -69,7 +68,6 @@ ResponseEntity<List<TransactionListItem>> getTransactionList(
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(name = "TransactionDetailResponse", implementation = TransactionDetailResponse.class))),
@ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found the transaction.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "422", description = "Unable to process the request.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@GetMapping(value = "/{transaction-id}", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -84,11 +82,10 @@ ResponseEntity<TransactionDetailResponse> getTransactionDetails(
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)),
@ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not found the transaction.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "422", description = "Unable to process the request.", content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@PostMapping(value = "/{transaction-id}/disable", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity disableTransaction(
ResponseEntity<Void> disableTransaction(
@RequestHeader("x-fiscal-code") @NotBlank String fiscalCode,
@Parameter(description = "The id of the transaction.", required = true) @NotBlank @PathVariable("transaction-id") String transactionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BizEventsViewCart {
private String transactionId;
private String eventId;
private String subject;
private long amount;
private String amount;
private UserDetail payee;
private UserDetail debtor;
private String refNumberValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum AppError {
INVALID_FISCAL_CODE(HttpStatus.BAD_REQUEST, INVALID_DATA, "Provided Fiscal Code %s is invalid"),

VIEW_USER_NOT_FOUND_WITH_TAX_CODE(HttpStatus.NOT_FOUND, VIEW_USER_NOT_FOUND, "Not found a biz-events-view-user with the given tax code"),
VIEW_USER_NOT_FOUND_WITH_TRANSACTION_ID(HttpStatus.NOT_FOUND, VIEW_USER_NOT_FOUND, "Not found a biz-events-view-user with id %s"),
VIEW_USER_NOT_FOUND_WITH_TRANSACTION_ID(HttpStatus.NOT_FOUND, VIEW_USER_NOT_FOUND, "Not found a biz-events-view-user with tax code %s and id %s"),
VIEW_GENERAL_NOT_FOUND_WITH_TRANSACTION_ID(HttpStatus.NOT_FOUND, VIEW_GENERAL_NOT_FOUND, "Not found a biz-events-view-general with id %s"),
VIEW_CART_NOT_FOUND_WITH_TRANSACTION_ID_AND_TAX_CODE(HttpStatus.NOT_FOUND, VIEW_CART_NOT_FOUND, "Not found a biz-events-view-cart with id %s for the given tax code"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewUser;
import it.gov.pagopa.bizeventsservice.model.response.transaction.CartItem;
import it.gov.pagopa.bizeventsservice.model.response.transaction.InfoTransaction;

import it.gov.pagopa.bizeventsservice.util.DateValidator;
import it.gov.pagopa.bizeventsservice.model.response.transaction.*;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

@Component
public class ConvertViewsToTransactionDetailResponse {
private ConvertViewsToTransactionDetailResponse(){}

@Value("transaction.payee.cartName")

private static String payeeCartName;

private static final List<String> LIST_RECEIPT_DATE_FORMAT_IN = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss");
private static final String RECEIPT_DATE_FORMAT_OUT = "yyyy-MM-dd'T'HH:mm:ssX";

@Value("${transaction.payee.cartName:Pagamento Multiplo}")
public void setPayeeCartName(String payeeCartNameValue){
payeeCartName = payeeCartNameValue;
}

public static TransactionDetailResponse convertTransactionDetails(BizEventsViewGeneral bizEventsViewGeneral, List<BizEventsViewCart> listOfCartViews) {
List<CartItem> listOfCartItems = new ArrayList<>();
Expand Down Expand Up @@ -46,7 +62,7 @@ public static TransactionDetailResponse convertTransactionDetails(BizEventsViewG
.transactionId(bizEventsViewGeneral.getTransactionId())
.authCode(bizEventsViewGeneral.getAuthCode())
.rrn(bizEventsViewGeneral.getRrn())
.transactionDate(bizEventsViewGeneral.getTransactionDate())
.transactionDate(dateFormatZoned(bizEventsViewGeneral.getTransactionDate()))
.pspName(bizEventsViewGeneral.getPspName())
.walletInfo(bizEventsViewGeneral.getWalletInfo())
.payer(bizEventsViewGeneral.getPayer())
Expand All @@ -71,7 +87,7 @@ public static TransactionListItem convertTransactionListItem(BizEventsViewUser v
.payeeName(listOfCartViews.size() > 1 ? payeeCartName : listOfCartViews.get(0).getPayee().getName())
.payeeTaxCode(listOfCartViews.size() > 1 ? "" : listOfCartViews.get(0).getPayee().getTaxCode())
.amount(currencyFormat(totalAmount.get().toString()))
.transactionDate(viewUser.getTransactionDate())
.transactionDate(dateFormatZoned(viewUser.getTransactionDate()))
.isCart(listOfCartViews.size() > 1)
.build();
}
Expand All @@ -83,4 +99,24 @@ private static String currencyFormat(String value) {
numberFormat.setMinimumFractionDigits(2);
return numberFormat.format(valueToFormat);
}

private static String dateFormatZoned(String date) {
String dateSub = StringUtils.substringBeforeLast(date, ".");
if (!DateValidator.isValid(dateSub, RECEIPT_DATE_FORMAT_OUT)) {
return dateFormat(dateSub);
}
return dateSub;
}


private static String dateFormat(String date) {
for (String format: LIST_RECEIPT_DATE_FORMAT_IN) {
if (DateValidator.isValid(date, format)) {
LocalDateTime ldt = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(format));
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneOffset.UTC);
return DateTimeFormatter.ofPattern(RECEIPT_DATE_FORMAT_OUT).format(zdt);
}
}
throw new DateTimeException("The date ["+date+"] is not in one of the expected formats "+LIST_RECEIPT_DATE_FORMAT_IN+" and cannot be parsed");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.gov.pagopa.bizeventsservice.service.impl;

import com.azure.cosmos.models.PartitionKey;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewCart;
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewGeneral;
Expand All @@ -15,20 +14,15 @@
import it.gov.pagopa.bizeventsservice.repository.BizEventsViewGeneralRepository;
import it.gov.pagopa.bizeventsservice.repository.BizEventsViewUserRepository;
import it.gov.pagopa.bizeventsservice.service.ITransactionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
@Slf4j
public class TransactionService implements ITransactionService {

private final BizEventsViewGeneralRepository bizEventsViewGeneralRepository;
Expand Down Expand Up @@ -104,7 +98,7 @@ public void disableTransaction(String fiscalCode, String transactionId) {
List<BizEventsViewUser> listOfViewUser = this.bizEventsViewUserRepository
.getBizEventsViewUserByTaxCodeAndTransactionId(fiscalCode, transactionId);
if (listOfViewUser.size() != 1) {
throw new AppException(AppError.VIEW_USER_NOT_FOUND_WITH_TRANSACTION_ID);
throw new AppException(AppError.VIEW_USER_NOT_FOUND_WITH_TRANSACTION_ID, fiscalCode, transactionId);
}
BizEventsViewUser bizEventsViewUser = listOfViewUser.get(0);
bizEventsViewUser.setHidden(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.gov.pagopa.bizeventsservice.util;

import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateValidator {

private DateValidator() {}

public static boolean isValid(final String value, final String datePattern) {
try {
LocalDateTime.parse(value, DateTimeFormatter.ofPattern(datePattern));
} catch (DateTimeException e) {
return false;
}
return true;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ azure.cosmos.biz-events-view-cart-container-name=biz-events-view-cart
logging.level.root=INFO
logging.level.it.gov.pagopa=INFO

springdoc.group-configs[0].group=all
springdoc.group-configs[0].displayName=Biz-Events All
springdoc.group-configs[0].paths-to-match=/**


Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.gov.pagopa.bizeventsservice.service;

import com.azure.cosmos.models.PartitionKey;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewCart;
import it.gov.pagopa.bizeventsservice.entity.view.BizEventsViewGeneral;
Expand All @@ -19,6 +18,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ContextConfiguration;

import java.util.*;

Expand All @@ -28,6 +28,7 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest
@ContextConfiguration
public class TransactionServiceTest {
public static final String INVALID_FISCAL_CODE = "invalidFiscalCode";
public static final int PAGE_SIZE = 5;
Expand All @@ -41,8 +42,8 @@ public class TransactionServiceTest {
private BizEventsViewCartRepository bizEventsViewCartRepository;

private TransactionService transactionService;
@Value("transaction.payee.cartName")
private static String payeeCartName;
@Value("${transaction.payee.cartName:Pagamento Multiplo}")
private String payeeCartName;

@BeforeEach
void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ public class ViewGenerator {
public static final String AUTH_CODE = "authCode";
public static final String RRN = "rrn";
public static final String PSP_NAME = "pspName";
public static final String TRANSACTION_DATE = "transactionDate";
public static final String TRANSACTION_DATE = "2024-03-22T10:23:46.157186";
public static final String TRANSACTION_DATE_ZULU = "2024-03-22T10:23:46Z";
public static final String BRAND = "brand";
public static final String ACCOUNT_HOLDER = "accountHolder";
public static final String BLURRED_NUMBER = "blurredNumber";
public static final String PAYER_NAME = "payerName";
public static final String EVENT_ID = "eventId";
public static final String SUBJECT = "subject";
public static final String PAYEE_NAME = "payeeName";
public static final long AMOUNT = 100L;
public static final String AMOUNT = "100";
public static final String FORMATTED_AMOUNT = "100,00";
public static final String FORMATTED_GRAND_TOTAL = "500,00";
public static final String PAYEE_TAX_CODE = "payeeTaxCode";
Expand Down Expand Up @@ -55,7 +56,7 @@ public static BizEventsViewGeneral generateBizEventsViewGeneral(){
.paymentMethod(PaymentMethodType.AD)
.rrn(RRN)
.pspName(PSP_NAME)
.transactionDate(TRANSACTION_DATE)
.transactionDate(TRANSACTION_DATE_ZULU)
.walletInfo(WalletInfo.builder()
.brand(BRAND)
.accountHolder(ACCOUNT_HOLDER)
Expand Down

0 comments on commit 343cdc7

Please sign in to comment.