Skip to content

Commit

Permalink
fix: controller dto
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Nov 18, 2024
1 parent d8dfbb8 commit a62a5ee
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommentOutputDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningCommentService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class QuestioningCommentController {
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Not found")
})
public void postQuestioningComment(@PathVariable Long id, @Valid @RequestBody QuestioningCommentInputDto questioningCommentDto) {
public QuestioningCommentOutputDto postQuestioningComment(@PathVariable Long id, @Valid @RequestBody QuestioningCommentInputDto questioningCommentDto) {

Questioning questioning = questioningService.findbyId(id);
QuestioningComment questioningComment = questioningCommentService.convertToEntity(questioningCommentDto);
Expand All @@ -56,6 +57,7 @@ public void postQuestioningComment(@PathVariable Long id, @Valid @RequestBody Qu
setQuestioningComments.add(newQuestioningComment);
questioning.setQuestioningComments(setQuestioningComments);
questioningService.saveQuestioning(questioning);
return questioningCommentService.convertToOutputDto(newQuestioningComment);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import fr.insee.survey.datacollectionmanagement.constants.Constants;
import fr.insee.survey.datacollectionmanagement.questioning.domain.Questioning;
import fr.insee.survey.datacollectionmanagement.questioning.domain.QuestioningCommunication;
import fr.insee.survey.datacollectionmanagement.questioning.dto.QuestioningCommunicationDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningCommunicationService;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
Expand All @@ -32,17 +32,12 @@ public class QuestioningCommunicationController {

@Operation(summary = "Search for questioning communications by questioning id")
@GetMapping(value = Constants.API_QUESTIONING_ID_QUESTIONING_COMMUNICATIONS, produces = "application/json")
public ResponseEntity<?> findQuestioningCommunicationsByQuestioningId(@PathVariable("id") Long id) {
public List<QuestioningCommunicationDto> findQuestioningCommunicationsByQuestioningId(@PathVariable("id") Long id) {
Questioning questioning = questioningService.findbyId(id);
Set<QuestioningCommunication> setQe = questioning.getQuestioningCommunications();
return ResponseEntity.status(HttpStatus.OK)
.body(setQe.stream()
.map(questioningCommunicationService::convertToDto).toList());
return setQe.stream().map(questioningCommunicationService::convertToDto).toList();

}





}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentOutputDto;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitCommentService;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -46,22 +47,21 @@ public class SurveyUnitCommentController {
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Not found")
})
public void postSurveyUnitComment(@PathVariable String id, @Valid @RequestBody SurveyUnitCommentInputDto surveyUnitCommentDto) {
public SurveyUnitCommentOutputDto postSurveyUnitComment(@PathVariable String id, @Valid @RequestBody SurveyUnitCommentInputDto surveyUnitCommentDto) {

SurveyUnit surveyUnit = surveyUnitService.findbyId(id);
SurveyUnitComment surveyUnitComment = convertToEntity(surveyUnitCommentDto);
SurveyUnitComment surveyUnitComment = surveyUnitCommentService.convertToEntity(surveyUnitCommentDto);
surveyUnitComment.setDate(new Date());
SurveyUnitComment newSurveyUnitComment = surveyUnitCommentService.saveSurveyUnitComment(surveyUnitComment);
Set<SurveyUnitComment> setSurveyUnitComments = surveyUnit.getSurveyUnitComments();
setSurveyUnitComments.add(newSurveyUnitComment);
surveyUnit.setSurveyUnitComments(setSurveyUnitComments);
surveyUnitService.saveSurveyUnit(surveyUnit);
return surveyUnitCommentService.convertToOutputDto(surveyUnit);

}

private SurveyUnitComment convertToEntity(SurveyUnitCommentInputDto surveyUnitCommentDto) {
return modelMapper.map(surveyUnitCommentDto, SurveyUnitComment.class);
}



}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package fr.insee.survey.datacollectionmanagement.questioning.service;

import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentOutputDto;

public interface SurveyUnitCommentService {

SurveyUnitComment saveSurveyUnitComment(SurveyUnitComment surveyUnitComment);

SurveyUnitComment convertToEntity(SurveyUnitCommentInputDto surveyUnitCommentDto);

SurveyUnitCommentOutputDto convertToOutputDto(SurveyUnit surveyUnit);


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package fr.insee.survey.datacollectionmanagement.questioning.service.impl;

import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnit;
import fr.insee.survey.datacollectionmanagement.questioning.domain.SurveyUnitComment;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentInputDto;
import fr.insee.survey.datacollectionmanagement.questioning.dto.SurveyUnitCommentOutputDto;
import fr.insee.survey.datacollectionmanagement.questioning.repository.SurveyUnitCommentRepository;
import fr.insee.survey.datacollectionmanagement.questioning.service.SurveyUnitCommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -13,8 +17,19 @@
public class SurveyUnitCommentServiceImpl implements SurveyUnitCommentService {

private final SurveyUnitCommentRepository surveyUnitCommentRepository;
private final ModelMapper modelMapper;
@Override
public SurveyUnitComment saveSurveyUnitComment(SurveyUnitComment surveyUnitComment) {
return surveyUnitCommentRepository.save(surveyUnitComment);
}

@Override
public SurveyUnitComment convertToEntity(SurveyUnitCommentInputDto surveyUnitCommentDto) {
return modelMapper.map(surveyUnitCommentDto, SurveyUnitComment.class);
}

@Override
public SurveyUnitCommentOutputDto convertToOutputDto(SurveyUnit surveyUnit) {
return modelMapper.map(surveyUnit, SurveyUnitCommentOutputDto.class);
}
}

0 comments on commit a62a5ee

Please sign in to comment.