From dbf49219b5604dacc3358b551b9400539846ef61 Mon Sep 17 00:00:00 2001 From: mingeun0507 Date: Thu, 25 May 2023 23:01:14 +0900 Subject: [PATCH] =?UTF-8?q?Fix(#171):=2000=EC=9D=B4=20=EB=B0=94=EB=80=8C?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectRemembranceResponseDto.java | 12 ++++++++--- .../service/project/ProjectService.java | 20 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/_8attery/seesaw/dto/api/response/ProjectRemembranceResponseDto.java b/src/main/java/com/_8attery/seesaw/dto/api/response/ProjectRemembranceResponseDto.java index 1762fc2..88b8f8c 100644 --- a/src/main/java/com/_8attery/seesaw/dto/api/response/ProjectRemembranceResponseDto.java +++ b/src/main/java/com/_8attery/seesaw/dto/api/response/ProjectRemembranceResponseDto.java @@ -4,8 +4,9 @@ import lombok.*; import java.util.List; +import java.util.stream.Collectors; -@Getter +@Data @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ProjectRemembranceResponseDto { private Long remembranceId; @@ -15,10 +16,15 @@ public class ProjectRemembranceResponseDto { private List qnaList; @Builder - public ProjectRemembranceResponseDto(Long remembranceId, RemembranceType remembranceType, List qnaList) { + public ProjectRemembranceResponseDto(Long remembranceId, RemembranceType remembranceType, List qnaList, String userName, String emotion) { this.remembranceId = remembranceId; this.type = remembranceType; - this.qnaList = qnaList; + this.qnaList = qnaList.stream().peek( + qnaDto -> { + qnaDto.setQuestion(qnaDto.question.replace("00님", userName + "님")); + qnaDto.setQuestion(qnaDto.question.replace("00감정", emotion)); + } + ).collect(Collectors.toList()); } @Data diff --git a/src/main/java/com/_8attery/seesaw/service/project/ProjectService.java b/src/main/java/com/_8attery/seesaw/service/project/ProjectService.java index 18840be..d687946 100644 --- a/src/main/java/com/_8attery/seesaw/service/project/ProjectService.java +++ b/src/main/java/com/_8attery/seesaw/service/project/ProjectService.java @@ -57,6 +57,17 @@ @Slf4j public class ProjectService { private static final long[] REPORT_FLOW = new long[]{77L, 83L, 78L, 84L, 80L, 88L, 81L, 89L, 82L, 90L}; + + public static final Map emotionStringMap = new HashMap<>( + Map.of( + Emotion.LIKE, "행복", + Emotion.NICE, "뿌듯함", + Emotion.IDK, "아쉬움", + Emotion.ANGRY, "힘듦", + Emotion.SAD, "슬픔" + ) + ); + private final ProjectQuestionRepository projectQuestionRepository; private final ProjectRepository projectRepository; private final ProjectRepositoryCustom projectRepositoryCustom; @@ -258,7 +269,7 @@ public ProjectQuestionResponseDto getRandomRegularQuestion(Long userId) { @Transactional public ProjectRemembranceResponseDto addRemembranceToProject(Long userId, ProjectRemembranceRequestDto projectRemembranceRequestDto) { - serviceUtils.retrieveUserById(userId); + User retrievedUser = serviceUtils.retrieveUserById(userId); Project retrievedProject = serviceUtils.retrieveProjectById(projectRemembranceRequestDto.getProjectId()); if (projectRemembranceRepositoryCustom.existsByProjectIdAndType(projectRemembranceRequestDto.getProjectId(), projectRemembranceRequestDto.getType())) { @@ -274,6 +285,7 @@ public ProjectRemembranceResponseDto addRemembranceToProject(Long userId, Projec emotionMap.put(Emotion.ANGRY, retrievedProjectEmotion.getAngryCnt()); emotionMap.put(Emotion.SAD, retrievedProjectEmotion.getSadCnt()); + ProjectRemembrance projectRemembrance = projectRemembranceRepository.save( ProjectRemembrance.builder() .project(retrievedProject) @@ -299,17 +311,21 @@ public ProjectRemembranceResponseDto addRemembranceToProject(Long userId, Projec .remembranceId(projectRemembrance.getId()) .qnaList(projectRemembranceRepositoryCustom.findQnaListByRemembranceId(projectRemembrance.getId())) .remembranceType(projectRemembrance.getType()) + .userName(retrievedUser.getNickName()) + .emotion(emotionStringMap.get(projectRemembrance.getEmotion())) .build(); } public ProjectRemembranceResponseDto getProjectRemembrance(Long userId, Long remembranceId) { - serviceUtils.retrieveUserById(userId); + User retrievedUser = serviceUtils.retrieveUserById(userId); ProjectRemembrance retrievedRemembrance = serviceUtils.retrieveProjectRemembranceById(remembranceId); return ProjectRemembranceResponseDto .builder() .remembranceId(retrievedRemembrance.getId()) .qnaList(projectRemembranceRepositoryCustom.findQnaListByRemembranceId(remembranceId)) + .userName(retrievedUser.getNickName()) + .emotion(emotionStringMap.get(retrievedRemembrance.getEmotion())) .remembranceType(retrievedRemembrance.getType()) .build(); }