Skip to content

Commit

Permalink
Mapper fix (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitolo-Andrea authored Oct 23, 2024
1 parent 299ef7f commit 1d80e4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CitizenConsentObjectToDTOMapper {

public CitizenConsentDTO map(CitizenConsent citizenConsent){
return CitizenConsentDTO.builder()
.hashedFiscalCode(citizenConsent.getHashedFiscalCode())
.tppState(citizenConsent.getTppState())
.tppId(citizenConsent.getTppId())
.creationDate(citizenConsent.getCreationDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public CitizenServiceImpl(CitizenRepository citizenRepository, CitizenConsentObj
this.mapperToObject = mapperToObject;
this.exceptionMap = exceptionMap;
}

@Override
public Mono<CitizenConsentDTO> createCitizenConsent(CitizenConsentDTO citizenConsentDTO) {
CitizenConsent citizenConsent = mapperToObject.map(citizenConsentDTO);
Expand All @@ -41,10 +40,16 @@ public Mono<CitizenConsentDTO> createCitizenConsent(CitizenConsentDTO citizenCon
citizenConsent.setCreationDate(LocalDateTime.now());
citizenConsent.setLastUpdateDate(LocalDateTime.now());
log.info("[EMD-CITIZEN][CREATE] Received consent: {}",inputSanify(citizenConsent.toString()));
return citizenRepository.save(citizenConsent)
.map(mapperToDTO::map)
.doOnSuccess(savedConsent -> log.info("[EMD][CREATE-CITIZEN-CONSENT] Created"));

return citizenRepository.findById(hashedFiscalCode)
.flatMap(existingConsent -> {
log.info("[EMD][CREATE-CITIZEN-CONSENT] Citizen consent already exists");
return Mono.just(mapperToDTO.map(existingConsent));
})
.switchIfEmpty(
citizenRepository.save(citizenConsent)
.doOnSuccess(savedConsent -> log.info("[EMD][CREATE-CITIZEN-CONSENT] Created new citizen consent"))
.map(mapperToDTO::map)
);
}

@Override
Expand All @@ -54,7 +59,7 @@ public Mono<CitizenConsentDTO> updateChannelState(String fiscalCode, String tppI
,hashedFiscalCode, inputSanify(tppId), tppState);
return citizenRepository.findByHashedFiscalCodeAndTppId(hashedFiscalCode, tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException
(ExceptionName.CITIZEN_NOT_ONBOARDED,"Citizen not founded during update state process")))
(ExceptionName.CITIZEN_NOT_ONBOARDED,"Citizen consent not founded during update state process")))
.flatMap(citizenConsent -> {
citizenConsent.setTppState(tppState);
citizenConsent.setLastUpdateDate(LocalDateTime.now());
Expand All @@ -70,9 +75,9 @@ public Mono<CitizenConsentDTO> getConsentStatus(String fiscalCode, String tppId)
log.info("[EMD-CITIZEN][GET-CONSENT-STATUS] Received hashedFiscalCode: {} and tppId: {}",hashedFiscalCode,inputSanify(tppId));
return citizenRepository.findByHashedFiscalCodeAndTppId(hashedFiscalCode, tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException
(ExceptionName.CITIZEN_NOT_ONBOARDED,"Citizen not founded during get process ")))
(ExceptionName.CITIZEN_NOT_ONBOARDED,"Citizen consent not founded during get process ")))
.map(mapperToDTO::map)
.doOnSuccess(consent -> log.info("[EMD-CITIZEN][GET-CONSENT-STATUS] Consent found:: {}",consent));
.doOnSuccess(consent -> log.info("[EMD-CITIZEN][GET-CONSENT-STATUS] Consent consent found:: {}",consent));

}

Expand Down

0 comments on commit 1d80e4c

Please sign in to comment.