Skip to content

Commit

Permalink
chore: 회고 목록 변경으로 인한 수정 (#223)
Browse files Browse the repository at this point in the history
* chore: 회고 목록 조회 수정 - 작성 상태 및 분석 상태 추가

* del: service dto 삭제

* fix: dev yml 수정

* chore: 회고 마감 마감일자에 따른 분기처리

* chore: 분석 완료 여부 추가

* chore: 모든 인원이 다 작성한 경우 자동마감 처리하도록 수정

* chore: 회고 목록 조회 수정에 따른 배치 시스템 수정
  • Loading branch information
mikekks authored Sep 11, 2024
1 parent 1419e3b commit acc2184
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import org.layer.domain.question.entity.Questions;
import org.layer.domain.question.enums.QuestionType;
import org.layer.domain.question.repository.QuestionRepository;
import org.layer.domain.retrospect.entity.AnalysisStatus;
import org.layer.domain.retrospect.entity.Retrospect;
import org.layer.domain.retrospect.entity.RetrospectStatus;
import org.layer.domain.retrospect.repository.RetrospectRepository;
import org.layer.domain.space.entity.MemberSpaceRelation;
import org.layer.domain.space.entity.Team;
import org.layer.domain.space.exception.MemberSpaceRelationException;
import org.layer.domain.space.repository.MemberSpaceRelationRepository;
import org.layer.external.ai.service.AIAnalyzeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -48,6 +51,8 @@ public class AnswerService {
private final MemberRepository memberRepository;
private final AnalyzeRepository analyzeRepository;

private final AIAnalyzeService aiAnalyzeService;

private final Time time;

@Transactional
Expand Down Expand Up @@ -91,6 +96,16 @@ public void create(AnswerListCreateRequest request, Long spaceId, Long retrospec
Answer answer = new Answer(retrospectId, r.questionId(), memberId, r.answerContent(), answerStatus);
answerRepository.save(answer);
}

Answers answers = new Answers(answerRepository.findAllByRetrospectId(retrospectId));

// 마지막 답변일 경우 -> ai 분석 실행
if (answers.getWriteCount(retrospectId) == team.getTeamMemberCount()){
retrospect.updateRetrospectStatus(RetrospectStatus.DONE, time.now());
retrospect.updateAnalysisStatus(AnalysisStatus.PROCEEDING);

aiAnalyzeService.createAnalyze(spaceId, retrospectId, answers.getWriteMemberIds());
}
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ResponseEntity<RetrospectListGetResponse> updateRetrospect(@PathVariable("spaceI
ResponseEntity<RetrospectListGetResponse> deleteRetrospect(@PathVariable("spaceId") Long spaceId,
@PathVariable("retrospectId") Long retrospectId, @MemberId Long memberId);

@Operation(summary = "회고 마감", description = "특정 팀 스페이스에서 작성했던 회고를 마감하는 기능입니다. </br> Note: 스페이스 내 모든 인원이 작성해야 가능합니다.")
@Operation(summary = "회고 수동 마감", description = "특정 팀 스페이스에서 작성했던 회고를 마감하는 기능입니다. </br> Note: 스페이스 내 모든 인원이 작성해야 가능합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "회고 마감 성공",
content = @Content(mediaType = "application/json")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
import org.layer.domain.retrospect.controller.dto.request.RetrospectCreateRequest;
import org.layer.domain.retrospect.controller.dto.request.RetrospectUpdateRequest;
import org.layer.domain.retrospect.controller.dto.response.RetrospectCreateResponse;
import org.layer.domain.retrospect.controller.dto.response.RetrospectGetResponse;
import org.layer.domain.retrospect.controller.dto.response.RetrospectListGetResponse;
import org.layer.domain.retrospect.service.RetrospectService;
import org.layer.domain.retrospect.service.dto.response.RetrospectListGetServiceResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/space/{spaceId}/retrospect")
Expand All @@ -43,16 +39,7 @@ public ResponseEntity<RetrospectCreateResponse> createRetrospect(
public ResponseEntity<RetrospectListGetResponse> getRetrospects(@PathVariable("spaceId") Long spaceId,
@MemberId Long memberId) {

RetrospectListGetServiceResponse serviceResponse = retrospectService.getRetrospects(spaceId, memberId);

List<RetrospectGetResponse> retrospectGetResponses = serviceResponse.retrospects().stream()
.map(r -> RetrospectGetResponse.of(r.retrospectId(), r.title(), r.introduction(), r.isWrite(),
r.retrospectStatus(),
r.writeCount(), r.totalCount(), r.createdAt(), r.deadline()))
.toList();

return ResponseEntity.ok()
.body(RetrospectListGetResponse.of(serviceResponse.layerCount(), retrospectGetResponses));
return ResponseEntity.ok().body(retrospectService.getRetrospects(spaceId, memberId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package org.layer.domain.retrospect.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

import org.layer.domain.retrospect.entity.AnalysisStatus;
import org.layer.domain.retrospect.entity.RetrospectStatus;
import org.layer.domain.retrospect.entity.WriteStatus;

import java.time.LocalDateTime;

@Schema(name = "RetrospectGetResponse", description = "특정 회고 조회 Dto")
public record RetrospectGetResponse(
@Schema(description = "회고 id", example = "1")
Long retrospectId,
@Schema(description = "회고 이름", example = "중간 발표 이후")
String title,
@Schema(description = "회고 설명", example = "중간 발표 관련해서 KPT 회고를 해봅시다.")
String introduction,
@Schema(description = "회고 작성 여부", example = "false")
boolean isWrite,
@Schema(description = "회고 상태 : PROCEEDING 나 DONE 중에 하나입니다.", example = "PROCEEDING")
RetrospectStatus retrospectStatus,
@Schema(description = "해당 회고 응답 수", example = "4")
long writeCount,
@Schema(description = "전체 인원", example = "10")
long totalCount,
@Schema(description = "회고 생성 일자")
LocalDateTime createdAt,
@Schema(description = "회고 종료 일자")
LocalDateTime deadline
@Schema(description = "회고 id", example = "1")
Long retrospectId,
@Schema(description = "회고 이름", example = "중간 발표 이후")
String title,
@Schema(description = "회고 설명", example = "중간 발표 관련해서 KPT 회고를 해봅시다.")
String introduction,
@Schema(description = "회고 작성 상태", example = "NOT_STARTED")
WriteStatus writeStatus,
@Schema(description = "회고 상태 : PROCEEDING 나 DONE 중에 하나입니다.", example = "PROCEEDING")
RetrospectStatus retrospectStatus,
@Schema(description = "회고 작성 상태", example = "NOT_STARTED")
AnalysisStatus analysisStatus,
@Schema(description = "해당 회고 응답 수", example = "4")
long writeCount,
@Schema(description = "전체 인원", example = "10")
long totalCount,
@Schema(description = "회고 생성 일자")
LocalDateTime createdAt,
@Schema(description = "회고 종료 일자")
LocalDateTime deadline
) {
public static RetrospectGetResponse of(Long retrospectId, String title, String introduction, boolean isWrite, RetrospectStatus retrospectStatus,
long writeCount, long totalCount, LocalDateTime createdAt, LocalDateTime deadline) {
public static RetrospectGetResponse of(Long retrospectId, String title, String introduction,
WriteStatus writeStatus, RetrospectStatus retrospectStatus, AnalysisStatus analysisStatus,
long writeCount, long totalCount, LocalDateTime createdAt, LocalDateTime deadline) {

return new RetrospectGetResponse(retrospectId, title, introduction, isWrite, retrospectStatus, writeCount, totalCount, createdAt, deadline);
}
return new RetrospectGetResponse(retrospectId, title, introduction, writeStatus, retrospectStatus,
analysisStatus, writeCount, totalCount, createdAt, deadline);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import org.layer.domain.retrospect.controller.dto.request.QuestionCreateRequest;
import org.layer.domain.retrospect.controller.dto.request.RetrospectCreateRequest;
import org.layer.domain.retrospect.controller.dto.request.RetrospectUpdateRequest;
import org.layer.domain.retrospect.controller.dto.response.RetrospectGetResponse;
import org.layer.domain.retrospect.controller.dto.response.RetrospectListGetResponse;
import org.layer.domain.retrospect.entity.AnalysisStatus;
import org.layer.domain.retrospect.entity.Retrospect;
import org.layer.domain.retrospect.entity.RetrospectStatus;
import org.layer.domain.retrospect.repository.RetrospectRepository;
import org.layer.domain.retrospect.service.dto.response.RetrospectGetServiceResponse;
import org.layer.domain.retrospect.service.dto.response.RetrospectListGetServiceResponse;
import org.layer.domain.space.entity.Space;
import org.layer.domain.space.entity.Team;
import org.layer.domain.space.repository.MemberSpaceRelationRepository;
Expand Down Expand Up @@ -100,7 +101,7 @@ private Retrospect getRetrospect(RetrospectCreateRequest request, Long spaceId)
.build();
}

public RetrospectListGetServiceResponse getRetrospects(Long spaceId, Long memberId) {
public RetrospectListGetResponse getRetrospects(Long spaceId, Long memberId) {
// 해당 스페이스 팀원인지 검증
Team team = new Team(memberSpaceRelationRepository.findAllBySpaceId(spaceId));
team.validateTeamMembership(memberId);
Expand All @@ -109,13 +110,20 @@ public RetrospectListGetServiceResponse getRetrospects(Long spaceId, Long member
List<Long> retrospectIds = retrospects.stream().map(Retrospect::getId).toList();
Answers answers = new Answers(answerRepository.findAllByRetrospectIdIn(retrospectIds));

List<RetrospectGetServiceResponse> retrospectDtos = retrospects.stream()
.map(r -> RetrospectGetServiceResponse.of(r.getId(), r.getTitle(), r.getIntroduction(),
answers.hasRetrospectAnswer(memberId, r.getId()), r.getRetrospectStatus(),
answers.getWriteCount(), team.getTeamMemberCount(), r.getCreatedAt(), r.getDeadline()))
List<RetrospectGetResponse> retrospectDtos = retrospects.stream()
.map(r -> {
long writeCount = team.getTeamMemberCount();
if (r.getRetrospectStatus().equals(RetrospectStatus.DONE)) {
writeCount = answers.getWriteCount(r.getId());
}

return RetrospectGetResponse.of(r.getId(), r.getTitle(), r.getIntroduction(),
answers.getWriteStatus(memberId, r.getId()), r.getRetrospectStatus(), r.getAnalysisStatus(),
answers.getWriteCount(r.getId()), writeCount, r.getCreatedAt(), r.getDeadline());
})
.toList();

return RetrospectListGetServiceResponse.of(retrospects.size(), retrospectDtos);
return RetrospectListGetResponse.of(retrospects.size(), retrospectDtos);
}

private List<Question> getQuestions(List<QuestionCreateRequest> questions, Long savedRetrospectId, Long formId) {
Expand Down Expand Up @@ -168,13 +176,13 @@ public void closeRetrospect(Long spaceId, Long retrospectId, Long memberId) {
space.isLeaderSpace(memberId);

Retrospect retrospect = retrospectRepository.findByIdOrThrow(retrospectId);
retrospect.validateDeadline(time.now());

Answers answers = new Answers(answerRepository.findAllByRetrospectId(retrospectId));

retrospect.updateRetrospectStatus(RetrospectStatus.DONE);
retrospect.updateRetrospectStatus(RetrospectStatus.DONE, time.now());
retrospect.updateAnalysisStatus(AnalysisStatus.PROCEEDING);
retrospectRepository.saveAndFlush(retrospect);

Answers answers = new Answers(answerRepository.findAllByRetrospectId(retrospectId));

// 회고 ai 분석 시작
aiAnalyzeService.createAnalyze(spaceId, retrospectId, answers.getWriteMemberIds());
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion layer-api/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
config:
import: application-secret.properties
import: optional:file:/config/application-secret.properties
datasource:
url: ${DEV_DB_URL}
username: ${DEV_DB_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ public class RetrospectScheduler {
public void updateRetrospectStatusToDone() {
log.info("Batch Start : updateRetrospectStatusToDone");


LocalDateTime now = time.now();

List<Retrospect> retrospects = retrospectRepository.findAllByDeadlineBeforeAndRetrospectStatus(
now, RetrospectStatus.PROCEEDING);
Map<Long, Retrospect> retrospectMap = retrospects.stream()
.collect(Collectors.toMap(Retrospect::getId, retrospect -> retrospect));

retrospects.forEach(retrospect -> retrospect.updateRetrospectStatus(RetrospectStatus.DONE));
retrospects.forEach(retrospect -> retrospect.updateRetrospectStatus(RetrospectStatus.DONE, now));
retrospectRepository.saveAllAndFlush(retrospects);

List<Long> retrospectIds = retrospects.stream().map(Retrospect::getId).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.layer.domain.answer.enums.AnswerStatus;
import org.layer.domain.answer.exception.AnswerException;
import org.layer.domain.retrospect.entity.WriteStatus;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -42,17 +43,38 @@ public boolean hasRetrospectAnswer(Long memberId, Long retrospectId) {
.anyMatch(answer -> answer.getMemberId().equals(memberId));
}

public long getWriteCount() {
Set<Long> set = new HashSet<>();
public WriteStatus getWriteStatus(Long memberId, Long retrospectId) {
boolean isDoneWrite = answers.stream()
.filter(answer -> answer.getRetrospectId().equals(retrospectId))
.filter(answer -> answer.getMemberId().equals(memberId))
.anyMatch(answer -> answer.getAnswerStatus().equals(AnswerStatus.DONE));
if(isDoneWrite){
return WriteStatus.DONE;
}

answers.forEach(answer -> {
// 임시저장된 회고일 경우 제외
if (answer.getAnswerStatus() != AnswerStatus.TEMPORARY) {
set.add(answer.getMemberId());
}
});
boolean isTemporaryWrite = answers.stream()
.filter(answer -> answer.getRetrospectId().equals(retrospectId))
.filter(answer -> answer.getMemberId().equals(memberId))
.anyMatch(answer -> answer.getAnswerStatus().equals(AnswerStatus.TEMPORARY));
if(isTemporaryWrite){
return WriteStatus.PROCEEDING;
}

return WriteStatus.NOT_STARTED;
}

public long getWriteCount(Long retrospectId) {

Map<Long, List<Answer>> answersByRetrospectId = answers.stream()
.collect(Collectors.groupingBy(Answer::getRetrospectId));

Set<Long> answerMembers = new HashSet<>();

answersByRetrospectId.get(retrospectId).stream()
.filter(answer -> answer.getAnswerStatus().equals(AnswerStatus.DONE))
.forEach(answer -> answerMembers.add(answer.getMemberId()));

return set.size();
return answerMembers.size();
}

public List<Long> getWriteMemberIds() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.layer.domain.retrospect.entity;

public enum AnalysisStatus {
NOT_STARTED, PROCEEDING, DONE
}
Loading

0 comments on commit acc2184

Please sign in to comment.