generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P4ADEV-2179] updated API getReceiptDetail
- Loading branch information
mscarsel
committed
Feb 14, 2025
1 parent
ebe0067
commit 46ae306
Showing
14 changed files
with
725 additions
and
352 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
src/main/java/it/gov/pagopa/pu/debtpositions/mapper/ReceiptDetailPIIViewMapper.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,37 @@ | ||
package it.gov.pagopa.pu.debtpositions.mapper; | ||
|
||
import it.gov.pagopa.pu.debtpositions.citizen.service.PersonalDataService; | ||
import it.gov.pagopa.pu.debtpositions.dto.ReceiptPIIDTO; | ||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDetailDTO; | ||
import it.gov.pagopa.pu.debtpositions.model.view.receipt.ReceiptDetailNoPIIView; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ReceiptDetailPIIViewMapper { | ||
|
||
private final PersonalDataService personalDataService; | ||
private final PersonMapper personMapper; | ||
|
||
public ReceiptDetailPIIViewMapper(PersonalDataService personalDataService, | ||
PersonMapper personMapper) { | ||
this.personalDataService = personalDataService; | ||
this.personMapper = personMapper; | ||
} | ||
|
||
public ReceiptDetailDTO mapToReceiptDetailDTO(ReceiptDetailNoPIIView receiptDetailNoPIIView) { | ||
ReceiptPIIDTO pii = personalDataService.get( | ||
receiptDetailNoPIIView.getDebtorPersonalDataId(),ReceiptPIIDTO.class); | ||
return ReceiptDetailDTO.builder() | ||
.receiptId(receiptDetailNoPIIView.getReceiptId()) | ||
.iuv(receiptDetailNoPIIView.getIuv()) | ||
.paymentAmountCents(receiptDetailNoPIIView.getPaymentAmountCents()) | ||
.remittanceInformation(receiptDetailNoPIIView.getRemittanceInformation()) | ||
.debtPositionDescription(receiptDetailNoPIIView.getDebtPositionDescription()) | ||
.paymentDateTime(receiptDetailNoPIIView.getPaymentDateTime()) | ||
.pspCompanyName(receiptDetailNoPIIView.getPspCompanyName()) | ||
.iud(receiptDetailNoPIIView.getIud()) | ||
.iur(receiptDetailNoPIIView.getIur()) | ||
.debtor(personMapper.mapToDto(pii.getDebtor())) | ||
.build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/it/gov/pagopa/pu/debtpositions/model/view/receipt/ReceiptDetailNoPIIView.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,31 @@ | ||
package it.gov.pagopa.pu.debtpositions.model.view.receipt; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.io.Serializable; | ||
import java.time.OffsetDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "receipt") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class ReceiptDetailNoPIIView implements Serializable { | ||
@Id | ||
private Long receiptId; | ||
private String iuv; | ||
private Long paymentAmountCents; | ||
private String remittanceInformation; | ||
private String debtPositionDescription; | ||
private Long debtorPersonalDataId; | ||
private OffsetDateTime paymentDateTime; | ||
private String pspCompanyName; | ||
private String iud; | ||
private String iur; | ||
} |
38 changes: 38 additions & 0 deletions
38
...gov/pagopa/pu/debtpositions/repository/view/receipt/ReceiptDetailNoPIIViewRepository.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 it.gov.pagopa.pu.debtpositions.repository.view.receipt; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
import it.gov.pagopa.pu.debtpositions.model.view.receipt.ReceiptDetailNoPIIView; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.Repository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
import org.springframework.data.rest.core.annotation.RestResource; | ||
|
||
@RepositoryRestResource(path = "receipts-detail-view") | ||
public interface ReceiptDetailNoPIIViewRepository extends Repository<ReceiptDetailNoPIIView, Long> { | ||
@RestResource(exported = false) | ||
@Query(value = "SELECT new ReceiptDetailNoPIIView(" | ||
+ "r.receiptId as receiptId, " | ||
+ "i.iuv as iuv, " | ||
+ "r.paymentAmountCents as paymentAmountCents, " | ||
+ "i.remittanceInformation as remittanceInformation, " | ||
+ "dp.description as debtPositionDescription, " | ||
+ "i.personalDataId as debtorPersonalDataId, " | ||
+ "r.paymentDateTime as paymentDateTime, " | ||
+ "r.pspCompanyName as pspCompanyName, " | ||
+ "i.iud as iud, " | ||
+ "i.iur as iur " | ||
+ ") " | ||
+ "FROM ReceiptDetailNoPIIView r " | ||
+ "JOIN InstallmentNoPII i ON r.receiptId = i.receiptId " | ||
+ "JOIN PaymentOption po ON i.paymentOptionId = po.paymentOptionId " | ||
+ "JOIN DebtPosition dp ON po.debtPositionId = dp.debtPositionId " | ||
+ "JOIN DebtPositionTypeOrg dpto ON dp.debtPositionTypeOrgId = dpto.debtPositionTypeOrgId " | ||
+ "JOIN DebtPositionTypeOrgOperators dptoo ON dpto.debtPositionTypeOrgId = dptoo.debtPositionTypeOrgId " | ||
+ "WHERE r.receiptId = :receiptId " | ||
+ "AND dptoo.operatorExternalUserId = :operatorExternalUserId ") | ||
Optional<ReceiptDetailNoPIIView> findReceiptDetailView( | ||
@Parameter(required = true) @Param("receiptId") Long receiptId, | ||
@Parameter(required = true) @Param("operatorExternalUserId") String operatorExternalUserId); | ||
} |
7 changes: 7 additions & 0 deletions
7
...t/gov/pagopa/pu/debtpositions/repository/view/receipt/ReceiptDetailPIIViewRepository.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,7 @@ | ||
package it.gov.pagopa.pu.debtpositions.repository.view.receipt; | ||
|
||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDetailDTO; | ||
|
||
public interface ReceiptDetailPIIViewRepository { | ||
ReceiptDetailDTO getReceiptDetail(Long receiptId, String operatorExternalUserId); | ||
} |
29 changes: 29 additions & 0 deletions
29
...v/pagopa/pu/debtpositions/repository/view/receipt/ReceiptDetailPIIViewRepositoryImpl.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,29 @@ | ||
package it.gov.pagopa.pu.debtpositions.repository.view.receipt; | ||
|
||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDetailDTO; | ||
import it.gov.pagopa.pu.debtpositions.exception.custom.NotFoundException; | ||
import it.gov.pagopa.pu.debtpositions.mapper.ReceiptDetailPIIViewMapper; | ||
import it.gov.pagopa.pu.debtpositions.model.view.receipt.ReceiptDetailNoPIIView; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ReceiptDetailPIIViewRepositoryImpl implements ReceiptDetailPIIViewRepository { | ||
private final ReceiptDetailNoPIIViewRepository receiptDetailNoPIIViewRepository; | ||
private final ReceiptDetailPIIViewMapper receiptDetailPIIViewMapper; | ||
|
||
public ReceiptDetailPIIViewRepositoryImpl( | ||
ReceiptDetailNoPIIViewRepository receiptDetailNoPIIViewRepository, | ||
ReceiptDetailPIIViewMapper receiptDetailPIIViewMapper) { | ||
this.receiptDetailNoPIIViewRepository = receiptDetailNoPIIViewRepository; | ||
this.receiptDetailPIIViewMapper = receiptDetailPIIViewMapper; | ||
} | ||
|
||
@Override | ||
public ReceiptDetailDTO getReceiptDetail(Long receiptId, String operatorExternalUserId) { | ||
ReceiptDetailNoPIIView receiptDetailNoPIIView = receiptDetailNoPIIViewRepository.findReceiptDetailView(receiptId, operatorExternalUserId) | ||
.orElseThrow(() -> new NotFoundException( | ||
"ReceiptDetailNoPIIView having receiptId %d and operatorExternalUserId %s not found".formatted( | ||
receiptId, operatorExternalUserId))); | ||
return receiptDetailPIIViewMapper.mapToReceiptDetailDTO(receiptDetailNoPIIView); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/it/gov/pagopa/pu/debtpositions/service/ReceiptService.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,9 +1,10 @@ | ||
package it.gov.pagopa.pu.debtpositions.service; | ||
|
||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDTO; | ||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDetailDTO; | ||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptWithAdditionalNodeDataDTO; | ||
|
||
public interface ReceiptService { | ||
ReceiptDTO createReceipt(ReceiptWithAdditionalNodeDataDTO receiptDTO); | ||
ReceiptDTO getReceiptDetail(Long receiptId); | ||
ReceiptDetailDTO getReceiptDetail(Long receiptId, String operatorExternalUserId); | ||
} |
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
50 changes: 50 additions & 0 deletions
50
src/test/java/it/gov/pagopa/pu/debtpositions/mapper/ReceiptDetailPIIViewMapperTest.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,50 @@ | ||
package it.gov.pagopa.pu.debtpositions.mapper; | ||
|
||
import it.gov.pagopa.pu.debtpositions.citizen.service.PersonalDataService; | ||
import it.gov.pagopa.pu.debtpositions.dto.ReceiptPIIDTO; | ||
import it.gov.pagopa.pu.debtpositions.dto.generated.ReceiptDetailDTO; | ||
import it.gov.pagopa.pu.debtpositions.model.view.receipt.ReceiptDetailNoPIIView; | ||
import it.gov.pagopa.pu.debtpositions.util.TestUtils; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import uk.co.jemos.podam.api.PodamFactory; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ReceiptDetailPIIViewMapperTest { | ||
|
||
private final PodamFactory podamFactory = TestUtils.getPodamFactory(); | ||
|
||
@Mock | ||
private PersonalDataService personalDataServiceMock; | ||
|
||
@Spy | ||
private PersonMapper personMapperSpy; | ||
|
||
@InjectMocks | ||
private ReceiptDetailPIIViewMapper receiptDetailPIIViewMapper; | ||
|
||
@Test | ||
void givenValidReceiptNoPIIWhenMapToReceiptDTOThenReturnReceiptDTO() { | ||
//given | ||
ReceiptDetailNoPIIView receiptDetailNoPIIView = podamFactory.manufacturePojo(ReceiptDetailNoPIIView.class); | ||
ReceiptPIIDTO receiptPIIDTO = podamFactory.manufacturePojo(ReceiptPIIDTO.class); | ||
Mockito.when(personalDataServiceMock.get(receiptDetailNoPIIView.getDebtorPersonalDataId(),ReceiptPIIDTO.class)).thenReturn(receiptPIIDTO); | ||
//when | ||
ReceiptDetailDTO response = receiptDetailPIIViewMapper.mapToReceiptDetailDTO(receiptDetailNoPIIView); | ||
|
||
//verify | ||
Assertions.assertNotNull(response); | ||
TestUtils.reflectionEqualsByName(receiptDetailNoPIIView, response, "debtor", "payer"); | ||
TestUtils.reflectionEqualsByName(receiptPIIDTO.getDebtor(), response.getDebtor()); | ||
TestUtils.checkNotNullFields(response,"payer"); | ||
Mockito.verify(personalDataServiceMock).get(receiptDetailNoPIIView.getDebtorPersonalDataId(),ReceiptPIIDTO.class); | ||
Mockito.verify(personMapperSpy).mapToDto(receiptPIIDTO.getDebtor()); | ||
} | ||
|
||
} |
Oops, something went wrong.