Skip to content

Commit

Permalink
Fix(#171): 00이 바뀌도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mingeun0507 committed May 25, 2023
1 parent 6897230 commit dbf4921
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,10 +16,15 @@ public class ProjectRemembranceResponseDto {
private List<QnaDto> qnaList;

@Builder
public ProjectRemembranceResponseDto(Long remembranceId, RemembranceType remembranceType, List<QnaDto> qnaList) {
public ProjectRemembranceResponseDto(Long remembranceId, RemembranceType remembranceType, List<QnaDto> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Emotion, String> 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;
Expand Down Expand Up @@ -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())) {
Expand All @@ -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)
Expand All @@ -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();
}
Expand Down

0 comments on commit dbf4921

Please sign in to comment.