Skip to content

Commit 7fe394e

Browse files
and-moraskymoronigufedcurciorubertiniangelosca24dariopelliccioli
authored
fix: Promote to Main (#219)
Co-authored-by: skymoronigu <50320390+skymoronigu@users.noreply.github.com> Co-authored-by: Andrea Morabito <78792023+and-mora@users.noreply.github.com> Co-authored-by: fedcurciorubertini <federico.curciorubertini@nttdata.com> Co-authored-by: angelosca24 <angelo.scagliola@nttdata.com> Co-authored-by: dariopelliccioli <105275365+dariopelliccioli@users.noreply.github.com>
2 parents a4bf7ef + 9a229f5 commit 7fe394e

29 files changed

+814
-50
lines changed

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
5151
<version>2.8.13</version>
5252
</dependency>
53+
<dependency>
54+
<groupId>com.azure.spring</groupId>
55+
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
56+
</dependency>
5357

5458
<!--3rd party library-->
5559
<dependency>
@@ -136,7 +140,13 @@
136140
<type>pom</type>
137141
<scope>import</scope>
138142
</dependency>
139-
143+
<dependency>
144+
<groupId>com.azure.spring</groupId>
145+
<artifactId>spring-cloud-azure-dependencies</artifactId>
146+
<version>5.23.0</version>
147+
<type>pom</type>
148+
<scope>import</scope>
149+
</dependency>
140150
</dependencies>
141151
</dependencyManagement>
142152

src/main/java/it/gov/pagopa/common/web/exception/ErrorManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.lang.Nullable;
99
import org.springframework.web.bind.annotation.ExceptionHandler;
1010
import org.springframework.web.bind.annotation.RestControllerAdvice;
11+
import org.springframework.web.server.MissingRequestValueException;
1112
import org.springframework.web.server.ServerWebExchange;
1213

1314
import java.util.Optional;
@@ -22,6 +23,14 @@ public ErrorManager(@Nullable ErrorDTO defaultErrorDTO) {
2223
this.defaultErrorDTO = Optional.ofNullable(defaultErrorDTO)
2324
.orElse(new ErrorDTO("Error", "Something gone wrong"));
2425
}
26+
27+
@ExceptionHandler(MissingRequestValueException.class)
28+
protected ResponseEntity<ErrorDTO> handleRequestValueException(
29+
MissingRequestValueException error, ServerWebExchange exchange) {
30+
logClientException(error, exchange);
31+
return ResponseEntity.badRequest().body(new ErrorDTO("INVALID_REQUEST", error.getMessage()));
32+
}
33+
2534
@ExceptionHandler(RuntimeException.class)
2635
protected ResponseEntity<ErrorDTO> handleException(RuntimeException error, ServerWebExchange exchange) {
2736
logClientException(error, exchange);

src/main/java/it/gov/pagopa/idpay/transactions/controller/PointOfSaleTransactionController.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package it.gov.pagopa.idpay.transactions.controller;
22

3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.media.Content;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
7+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
8+
import it.gov.pagopa.common.web.dto.ErrorDTO;
9+
import it.gov.pagopa.idpay.transactions.dto.DownloadInvoiceResponseDTO;
310
import it.gov.pagopa.idpay.transactions.dto.PointOfSaleTransactionsListDTO;
411
import org.springframework.data.domain.Pageable;
512
import org.springframework.data.domain.Sort;
613
import org.springframework.data.web.PageableDefault;
14+
import org.springframework.http.MediaType;
715
import org.springframework.web.bind.annotation.*;
816
import reactor.core.publisher.Mono;
917

@@ -19,4 +27,44 @@ Mono<PointOfSaleTransactionsListDTO> getPointOfSaleTransactions(
1927
@RequestParam(required = false) String fiscalCode,
2028
@RequestParam(required = false) String status,
2129
@PageableDefault(sort = "elaborationDateTime", direction = Sort.Direction.DESC) Pageable pageable);
30+
31+
/**
32+
* Provides method to download an invoice file of a rewarded transaction
33+
* @param merchantId obtained through a header parameter, used to check if the transaction required is referred to the same merchant
34+
* @param pointOfSaleId obtained through a header parameter, used to check if the transaction required is referred to the same point of sale
35+
* @param transactionId
36+
* @return Mono containing an instance of DownloadInvoiceResponseDTO, containing the invoice url
37+
*/
38+
@Operation(summary = "downloadInvoiceFile",
39+
description = "Return invoice file download URL")
40+
@ApiResponses(value = {
41+
@ApiResponse(responseCode = "200", description = "Return file signed url",
42+
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
43+
schema = @Schema(implementation = DownloadInvoiceResponseDTO.class)
44+
)),
45+
@ApiResponse(responseCode = "400", description = "Bad Request",
46+
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
47+
schema = @Schema(implementation = ErrorDTO.class))),
48+
@ApiResponse(responseCode = "401",
49+
description = "Unauthorized", content = @Content(schema = @Schema())),
50+
@ApiResponse(responseCode = "403",
51+
description = "Forbidden", content = @Content(schema = @Schema())),
52+
@ApiResponse(responseCode = "404", description = "Invoice not found",
53+
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
54+
schema = @Schema(implementation = ErrorDTO.class))),
55+
@ApiResponse(responseCode = "429",
56+
description = "Too many requests", content = @Content(schema = @Schema())),
57+
@ApiResponse(responseCode = "500",
58+
description = "Service error", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
59+
schema = @Schema(implementation = ErrorDTO.class))),
60+
@ApiResponse(responseCode = "503",
61+
description = "Service unavailable",
62+
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
63+
schema = @Schema(implementation = ErrorDTO.class)))
64+
})
65+
@GetMapping("/{pointOfSaleId}/transactions/{transactionId}/download")
66+
Mono<DownloadInvoiceResponseDTO> downloadInvoiceFile(
67+
@RequestHeader("x-merchant-id") String merchantId,
68+
@PathVariable("pointOfSaleId") String pointOfSaleId,
69+
@PathVariable("transactionId") String transactionId);
2270
}

src/main/java/it/gov/pagopa/idpay/transactions/controller/PointOfSaleTransactionControllerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.gov.pagopa.idpay.transactions.controller;
22

3+
import it.gov.pagopa.idpay.transactions.dto.DownloadInvoiceResponseDTO;
34
import it.gov.pagopa.idpay.transactions.dto.PointOfSaleTransactionsListDTO;
45
import it.gov.pagopa.idpay.transactions.dto.mapper.PointOfSaleTransactionMapper;
56
import it.gov.pagopa.idpay.transactions.service.PointOfSaleTransactionService;
@@ -40,4 +41,12 @@ public Mono<PointOfSaleTransactionsListDTO> getPointOfSaleTransactions(String me
4041
page.getTotalPages()))
4142
);
4243
}
44+
45+
@Override
46+
public Mono<DownloadInvoiceResponseDTO> downloadInvoiceFile(
47+
String merchantId, String pointOfSaleId, String transactionId) {
48+
log.info("[DOWNLOAD_TRANSACTION] Requested to download invoice for transaction {}",
49+
Utilities.sanitizeString(transactionId));
50+
return pointOfSaleTransactionService.downloadTransactionInvoice(merchantId, pointOfSaleId, transactionId);
51+
}
4352
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package it.gov.pagopa.idpay.transactions.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
public class DownloadInvoiceResponseDTO {
13+
private String invoiceUrl;
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package it.gov.pagopa.idpay.transactions.dto;
2+
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import lombok.experimental.FieldNameConstants;
8+
import lombok.experimental.SuperBuilder;
9+
10+
11+
@Data
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
@SuperBuilder(toBuilder = true)
15+
@FieldNameConstants()
16+
public class InvoiceFile {
17+
18+
private String filename;
19+
20+
}

src/main/java/it/gov/pagopa/idpay/transactions/dto/PointOfSaleTransactionDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class PointOfSaleTransactionDTO {
2020
String fiscalCode;
2121
Long effectiveAmountCents;
2222
Long rewardAmountCents;
23+
Long authorizedAmountCents;
2324
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
2425
LocalDateTime trxDate;
2526
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@@ -28,4 +29,5 @@ public class PointOfSaleTransactionDTO {
2829
String status;
2930
String channel;
3031
Map<String, String> additionalProperties;
32+
InvoiceFile invoiceFile;
3133
}

src/main/java/it/gov/pagopa/idpay/transactions/dto/RewardTransactionDTO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ public class RewardTransactionDTO {
6666
private LocalDateTime elaborationDateTime;
6767
private String channel;
6868
private Map<String, String> additionalProperties;
69+
private InvoiceFile invoiceFile;
6970
}

src/main/java/it/gov/pagopa/idpay/transactions/dto/mapper/PointOfSaleTransactionMapper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ public PointOfSaleTransactionMapper(UserRestClient userRestClient) {
1818
}
1919

2020
public Mono<PointOfSaleTransactionDTO> toDTO(RewardTransaction trx, String initiativeId, String fiscalCode) {
21+
22+
Long totalAmount = trx.getAmountCents();
23+
24+
Long rewardAmount = 0L;
25+
26+
if (trx.getRewards() != null && trx.getRewards().get(initiativeId) != null) {
27+
rewardAmount = Math.abs(trx.getRewards().get(initiativeId).getAccruedRewardCents());
28+
}
29+
30+
Long authorizedAmount = totalAmount - rewardAmount;
31+
2132
PointOfSaleTransactionDTO dto = PointOfSaleTransactionDTO.builder()
2233
.trxId(trx.getId())
2334
.effectiveAmountCents(trx.getAmountCents())
24-
.rewardAmountCents(trx.getRewards().get(initiativeId).getAccruedRewardCents())
35+
.rewardAmountCents(rewardAmount)
36+
.authorizedAmountCents(authorizedAmount)
2537
.trxDate(trx.getTrxDate())
2638
.elaborationDateTime(trx.getElaborationDateTime())
2739
.status(trx.getStatus())
2840
.channel(trx.getChannel())
2941
.fiscalCode(fiscalCode)
3042
.additionalProperties(trx.getAdditionalProperties())
43+
.invoiceFile(trx.getInvoiceFile())
3144
.build();
3245

3346
if (StringUtils.isNotBlank(fiscalCode)){

src/main/java/it/gov/pagopa/idpay/transactions/dto/mapper/RewardTransactionMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public RewardTransaction mapFromDTO(RewardTransactionDTO rewardTrxDto) {
6363
rewardTrx.setElaborationDateTime(rewardTrxDto.getElaborationDateTime());
6464
rewardTrx.setChannel(rewardTrxDto.getChannel());
6565
rewardTrx.setAdditionalProperties(rewardTrxDto.getAdditionalProperties());
66+
rewardTrx.setInvoiceFile(rewardTrxDto.getInvoiceFile());
6667
}
6768

6869
return rewardTrx;

0 commit comments

Comments
 (0)