Skip to content

Commit

Permalink
Merge pull request #37 from KusitmsHDmedi/feature/35-survey
Browse files Browse the repository at this point in the history
[feat] 설문 전체 조회 api
  • Loading branch information
sebbbin authored Sep 16, 2023
2 parents 9a05fbb + 8b016b9 commit e1fae97
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kusithm.hdmedi_server.domain.survey.controller;

import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.AllSurveyResponseDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResponseDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResultDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto;
Expand Down Expand Up @@ -30,8 +31,8 @@ public ResponseEntity<BaseResponse<?>> submitSurvey(@AuthenticatedUserId final H
}

@GetMapping("/all")
public ResponseEntity<BaseResponse<?>> getAllSurveys() {

public ResponseEntity<BaseResponse<?>> getAllSurveys(@AuthenticatedUserId final HDmediUser hDmediUser) {
final AllSurveyResponseDto responseDto = surveyService.getAllSurvey(hDmediUser);
return ResponseEntity.status(HttpStatus.OK)
.body(BaseResponse.of(SuccessCode.OK, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import lombok.Builder;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;

@Builder
@Data
public class BaseSurvey {
private String question;
private int score;

public static BaseSurvey createBaseSurvey(String question, int score){
public static BaseSurvey createBaseSurvey(String question, int score) {
return BaseSurvey.builder()
.question(question)
.score(score)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kusithm.hdmedi_server.domain.survey.domain;

import com.kusithm.hdmedi_server.global.common.BaseTimeEntity;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
Expand All @@ -15,18 +14,18 @@ public class EachSurvey {
private List<Respondent> parentsSurveyList;
private List<Respondent> teacherSurveyList;

public static EachSurvey createEachSurvey(){
public static EachSurvey createEachSurvey() {
return EachSurvey.builder()
.parentsSurveyList(new ArrayList<>())
.teacherSurveyList(new ArrayList<>())
.build();
}

public void addParentsSurveyList(Respondent parentsSurvey){
public void addParentsSurveyList(Respondent parentsSurvey) {
this.parentsSurveyList.add(parentsSurvey);
}

public void addTeacherSurveyList(Respondent teacherSurvey){
public void addTeacherSurveyList(Respondent teacherSurvey) {
this.teacherSurveyList.add(teacherSurvey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Builder
Expand All @@ -13,7 +12,7 @@ public class Respondent extends BaseTimeEntity {
private List<BaseSurvey> baseSurveyList;
private int totalScore;

public static Respondent createRespondent(List<BaseSurvey> baseSurveyList, int totalScore){
public static Respondent createRespondent(List<BaseSurvey> baseSurveyList, int totalScore) {
return Respondent.builder()
.baseSurveyList(baseSurveyList)
.totalScore(totalScore)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.kusithm.hdmedi_server.domain.survey.domain;

import jakarta.persistence.*;
import jakarta.persistence.Id;
import lombok.*;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
Expand All @@ -17,7 +15,7 @@ public class Survey {
private Long userId;
private EachSurvey eachSurvey;

public static Survey createSurvey(Long userId){
public static Survey createSurvey(Long userId) {
EachSurvey createdEachSurvey = EachSurvey.createEachSurvey();
return Survey.builder()
.userId(userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kusithm.hdmedi_server.domain.survey.dto.response;


import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class AllSurveyResponseDto {
private List<BaseAllSurveyResponseDto> allSurveyList;
public static AllSurveyResponseDto of(List<BaseAllSurveyResponseDto> allSurveyList){
return AllSurveyResponseDto.builder()
.allSurveyList(allSurveyList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kusithm.hdmedi_server.domain.survey.dto.response;

import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@Builder
public class BaseAllSurveyResponseDto {
private LocalDate date;
private Long surveyId;

public static BaseAllSurveyResponseDto of(LocalDate date, Long surveyId) {
return BaseAllSurveyResponseDto.builder()
.date(date)
.surveyId(surveyId)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BaseSurveyResponseDto {
private String question;
private int score;

public static BaseSurveyResponseDto of(String question, int score){
public static BaseSurveyResponseDto of(String question, int score) {
return BaseSurveyResponseDto.builder()
.question(question)
.score(score)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SurveyDetailResponseDto {
private List<BaseSurveyResponseDto> parentsSurveyList;
private List<BaseSurveyResponseDto> teacherSurveyList;

public static SurveyDetailResponseDto of(List<BaseSurveyResponseDto> parentsSurveyList, List<BaseSurveyResponseDto> teacherSurveyList){
public static SurveyDetailResponseDto of(List<BaseSurveyResponseDto> parentsSurveyList, List<BaseSurveyResponseDto> teacherSurveyList) {
return SurveyDetailResponseDto.builder()
.parentsSurveyList(parentsSurveyList)
.teacherSurveyList(teacherSurveyList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SurveyDetailResultDto {
private int teacherScore;
private String teacherMessage;

public static SurveyDetailResultDto of(int parentsScore, String parentsMessage, int teacherScore, String teacherMessage){
public static SurveyDetailResultDto of(int parentsScore, String parentsMessage, int teacherScore, String teacherMessage) {
return SurveyDetailResultDto.builder()
.parentsScore(parentsScore)
.parentsMessage(parentsMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SurveyResultResponseDto {
private int totalScore;
private String message;

public static SurveyResultResponseDto of(int totalScore, String message){
public static SurveyResultResponseDto of(int totalScore, String message) {
return SurveyResultResponseDto.builder()
.totalScore(totalScore)
.message(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.kusithm.hdmedi_server.domain.survey.domain.Survey;
import com.kusithm.hdmedi_server.domain.survey.dto.request.BaseSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.BaseSurveyResponseDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResponseDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyDetailResultDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto;
import com.kusithm.hdmedi_server.domain.survey.dto.response.*;
import com.kusithm.hdmedi_server.domain.survey.repository.SurveyRepository;
import com.kusithm.hdmedi_server.global.common.HDmediUser;
import com.kusithm.hdmedi_server.global.common.MessageSourceProvider;
Expand All @@ -18,6 +15,7 @@

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@RequiredArgsConstructor
@Transactional
Expand All @@ -36,6 +34,12 @@ public SurveyResultResponseDto processSurvey(HDmediUser hDmediUser, CreateSurvey
return SurveyResultResponseDto.of(respondent.getTotalScore(), surveyResultMessage);
}

public AllSurveyResponseDto getAllSurvey(HDmediUser hDmediUser) {
Survey currentSurvey = findSurvey(hDmediUser.getId());
List<BaseAllSurveyResponseDto> baseAllSurveyResponseDtoList = getBaseAllSurveyResponseDtoList(currentSurvey);
return AllSurveyResponseDto.of(baseAllSurveyResponseDtoList);
}

public SurveyDetailResultDto getDetailResult(HDmediUser hDmediUser, Long surveyId) {
Survey currentSurvey = findSurvey(hDmediUser.getId());
Respondent parentsRespondent = getParentsRespondent(currentSurvey, surveyId.intValue());
Expand All @@ -54,6 +58,18 @@ public SurveyDetailResponseDto getSurveyDetail(HDmediUser hDmediUser, Long surve
return SurveyDetailResponseDto.of(parentsBaseSurveyResponseDtoList, teachersBaseSurveyResponseDtoList);
}

private List<BaseAllSurveyResponseDto> getBaseAllSurveyResponseDtoList(Survey currentSurvey) {
List<Respondent> respondentList = currentSurvey.getEachSurvey().getParentsSurveyList();
List<BaseAllSurveyResponseDto> responseDtoList = IntStream.range(0, respondentList.size())
.mapToObj(idx -> BaseAllSurveyResponseDto.of(
respondentList.get(idx).getLastModifiedDate().toLocalDate(),
Long.valueOf(idx)
))
.collect(Collectors.toList());
return responseDtoList;
}


private List<BaseSurveyResponseDto> getBaseSurveyDtoListFor(Respondent respondent) {
return respondent.getBaseSurveyList().stream()
.map(baseSurvey ->
Expand Down

0 comments on commit e1fae97

Please sign in to comment.