diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java index 43735d23..758c8079 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/controller/SurveyUnitController.java @@ -7,6 +7,7 @@ import fr.insee.survey.datacollectionmanagement.exception.NotMatchException; import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit; import fr.insee.survey.datacollectionmanagement.questioning.dto.SearchSurveyUnitDto; +import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitDetailsDto; import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitDto; import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService; import io.swagger.v3.oas.annotations.Operation; @@ -50,6 +51,7 @@ public class SurveyUnitController { @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad Request") }) + @Deprecated public Page getSurveyUnits( @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer size, @@ -79,13 +81,13 @@ public Page searchSurveyUnits( @Operation(summary = "Search for a survey unit by its id") @GetMapping(value = Constants.API_SURVEY_UNITS_ID, produces = "application/json") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SurveyUnitDto.class))), + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SurveyUnitDetailsDto.class))), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad Request") }) - public SurveyUnitDto findSurveyUnit(@PathVariable("id") String id) { + public SurveyUnitDetailsDto findSurveyUnit(@PathVariable("id") String id) { SurveyUnit surveyUnit = surveyUnitService.findbyId(StringUtils.upperCase(id)); - return convertToDto(surveyUnit); + return convertToDetailsDto(surveyUnit); } @@ -119,7 +121,7 @@ public ResponseEntity putSurveyUnit(@PathVariable("id") String id } return ResponseEntity.status(responseStatus) - .body(convertToDto(surveyUnitService.saveSurveyUnitAndAddress(surveyUnit))); + .body(convertToDto(surveyUnitService.saveSurveyUnitAddressComments(surveyUnit))); } @@ -130,6 +132,7 @@ public ResponseEntity putSurveyUnit(@PathVariable("id") String id @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") }) + @Deprecated public void deleteSurveyUnit(@PathVariable("id") String id) { SurveyUnit surveyUnit = surveyUnitService.findbyId(StringUtils.upperCase(id)); @@ -146,6 +149,11 @@ private SurveyUnitDto convertToDto(SurveyUnit surveyUnit) { return modelMapper.map(surveyUnit, SurveyUnitDto.class); } + private SurveyUnitDetailsDto convertToDetailsDto(SurveyUnit surveyUnit) { + return modelMapper.map(surveyUnit, SurveyUnitDetailsDto.class); + } + + private SurveyUnit convertToEntity(SurveyUnitDto surveyUnitDto) { return modelMapper.map(surveyUnitDto, SurveyUnit.class); } diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java index 56a0ae90..ef54a65c 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnit.java @@ -33,6 +33,9 @@ public class SurveyUnit { @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) private SurveyUnitAddress surveyUnitAddress; + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + private Set surveyUnitComments; + @Override public String toString() { return "SurveyUnit [idSu=" + idSu + ", identificationCode=" + identificationCode + ", identificationName=" diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java new file mode 100644 index 00000000..e861a982 --- /dev/null +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/domain/SurveyUnitComment.java @@ -0,0 +1,20 @@ +package fr.insee.survey.datacollectionmanagement.questioning.domain; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.Date; + +@Entity +@Getter +@Setter +public class SurveyUnitComment { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "su_comment_seq") + private Long id; + @Column(length = 2000) + private String comment; + private String author; + private Date date; +} diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java new file mode 100644 index 00000000..36287dd8 --- /dev/null +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/dto/SurveyUnitDetailsDto.java @@ -0,0 +1,20 @@ +package fr.insee.survey.datacollectionmanagement.questioning.dto; + +import jakarta.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.Setter; + +import java.util.Set; + +@Getter +@Setter +public class SurveyUnitDetailsDto { + + @NotBlank + private String idSu; + private String identificationCode; + private String identificationName; + private SurveyUnitAddressDto address; + private Set comments; + +}