Skip to content

Commit

Permalink
feat: update survey unit endpoints for pilotage management front
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Aug 7, 2024
1 parent bc079fb commit 44a85b8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class SurveyUnitController {
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
@Deprecated
public Page<SurveyUnitDto> getSurveyUnits(
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "20") Integer size,
Expand Down Expand Up @@ -79,13 +81,13 @@ public Page<SearchSurveyUnitDto> 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);

}

Expand Down Expand Up @@ -119,7 +121,7 @@ public ResponseEntity<SurveyUnitDto> putSurveyUnit(@PathVariable("id") String id
}

return ResponseEntity.status(responseStatus)
.body(convertToDto(surveyUnitService.saveSurveyUnitAndAddress(surveyUnit)));
.body(convertToDto(surveyUnitService.saveSurveyUnitAddressComments(surveyUnit)));

}

Expand All @@ -130,6 +132,7 @@ public ResponseEntity<SurveyUnitDto> 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));

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SurveyUnitComment> surveyUnitComments;

@Override
public String toString() {
return "SurveyUnit [idSu=" + idSu + ", identificationCode=" + identificationCode + ", identificationName="
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<SurveyUnitCommentOutputDto> comments;

}

0 comments on commit 44a85b8

Please sign in to comment.