Skip to content

Commit

Permalink
refactor: validation for contact dto
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Nov 27, 2023
1 parent 976fbcf commit 45e9f8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public ResponseEntity<?> deleteContact(@PathVariable("id") String id) {
if (contact.isPresent()) {
contactService.deleteContactAddressEvent(contact.get());

viewService.findViewByIdentifier(id).stream().forEach(c -> viewService.deleteView(c));
viewService.findViewByIdentifier(id).stream().forEach(viewService::deleteView);
questioningAccreditationService.findByContactIdentifier(id).stream().forEach(acc -> {
Questioning questioning = questioningService.findbyId(acc.getQuestioning().getId()).get();
Set<QuestioningAccreditation> newSet = questioning.getQuestioningAccreditations();
Expand All @@ -182,7 +182,7 @@ public ResponseEntity<?> deleteContact(@PathVariable("id") String id) {

private ContactDto convertToDto(Contact contact) {
ContactDto contactDto = modelMapper.map(contact, ContactDto.class);
contactDto.setCivility(contact.getGender());
contactDto.setCivility(contact.getGender().name());
return contactDto;
}

Expand All @@ -196,7 +196,7 @@ private ContactFirstLoginDto convertToFirstLoginDto(Contact contact) {

private Contact convertToEntity(ContactDto contactDto) throws ParseException, NoSuchElementException {
Contact contact = modelMapper.map(contactDto, Contact.class);
contact.setGender(contactDto.getCivility());
contact.setGender(Contact.Gender.valueOf(contactDto.getCivility()));
Optional<Contact> oldContact = contactService.findByIdentifier(contactDto.getIdentifier());
if (oldContact.isEmpty()) {
throw new NoSuchElementException();
Expand All @@ -210,7 +210,7 @@ private Contact convertToEntity(ContactDto contactDto) throws ParseException, No

private Contact convertToEntityNewContact(ContactDto contactDto) {
Contact contact = modelMapper.map(contactDto, Contact.class);
contact.setGender(contactDto.getCivility());
contact.setGender(Contact.Gender.valueOf(contactDto.getCivility()));
return contact;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.insee.survey.datacollectionmanagement.contact.dto;

import fr.insee.survey.datacollectionmanagement.contact.domain.Contact;
import fr.insee.survey.datacollectionmanagement.contact.validation.ContactGenderValid;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
Expand All @@ -14,7 +13,7 @@ public class ContactDto{
private String identifier;
private String externalId;
@ContactGenderValid
private Contact.Gender civility;
private String civility;
private String lastName;
private String firstName;
private String function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ private SupportDto convertToDto(Support support) {

private ContactDto convertToDto(Contact contact) {
ContactDto contactDto = modelMapper.map(contact, ContactDto.class);
contactDto.setCivility(contact.getGender());
contactDto.setCivility(contact.getGender().name());
return contactDto;
}

Expand Down

0 comments on commit 45e9f8f

Please sign in to comment.