Skip to content

Commit

Permalink
v1.0.8
Browse files Browse the repository at this point in the history
v1.0.8
  • Loading branch information
mikekks authored Sep 13, 2024
2 parents e24a36a + e86408e commit c70ea22
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public SpaceActionItemGetResponse getSpaceRecentActionItems(Long memberId, Long
// 종료된 것 중 가장 최근에 만들어진 회고 찾기
Optional<Retrospect> recentOpt = retrospectList.stream()
.filter(r -> r.getRetrospectStatus().equals(DONE)) // 끝난 회고 찾기
.sorted((a, b) -> b.getDeadline().compareTo(a.getDeadline())) // deadline 내림차순으로 정렬
.sorted(Comparator.comparing(Retrospect::getDeadline,
Comparator.nullsLast(Comparator.naturalOrder())).reversed()) // deadline 내림차순, null은 아래로 정렬
.findFirst();

if (recentOpt.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.layer.domain.answer.controller.dto.response;

import java.util.List;

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

import java.util.List;

@Schema(name = "AnswerByPersonGetResponse", description = "개인별 답변 조회 응답 Dto")
public record AnswerByPersonGetResponse(
@Schema(description = "답변자", example = "홍길동")
String name,
@Schema(description = "탈퇴 여부. 탈퇴시 true", example = "false")
Boolean deleted,
@Schema(description = "질문-답변 객체", example = "")
List<QuestionAndAnswerGetResponse> answers
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.layer.domain.answer.controller.dto.response;

import java.util.List;

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

import java.util.List;

@Schema(name = "AnswerByQuestionGetResponse", description = "임시 회고 조회 응답 Dto")
public record AnswerByQuestionGetResponse(
@Schema(description = "질문 내용", example = "질문 내용입니당")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public record PersonAndAnswerGetResponse(
@Schema(description = "답변자", example = "홍길동")
String name,
@Schema(description = "탈퇴 여부. 탈퇴시 true", example = "false")
Boolean deleted,
@Schema(description = "답변 내용", example = "답변 내용입니당")
String answerContent
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.layer.domain.answer.service;

import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.layer.domain.analyze.entity.Analyze;
import org.layer.domain.analyze.enums.AnalyzeType;
import org.layer.domain.analyze.repository.AnalyzeRepository;
Expand Down Expand Up @@ -40,6 +40,7 @@
import static org.layer.common.exception.AnswerExceptionType.NOT_ANSWERED;
import static org.layer.common.exception.MemberSpaceRelationExceptionType.NOT_FOUND_MEMBER_SPACE_RELATION;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -99,11 +100,14 @@ public void create(AnswerListCreateRequest request, Long spaceId, Long retrospec

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

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

if(!retrospect.hasDeadLine()){
retrospect.updateRetrospectStatus(RetrospectStatus.DONE);
}
retrospectRepository.saveAndFlush(retrospect);

aiAnalyzeService.createAnalyze(spaceId, retrospectId, answers.getWriteMemberIds());
}
Expand Down Expand Up @@ -180,11 +184,10 @@ public AnswerListGetResponse getAnalyzeAnswer(Long spaceId, Long retrospectId, L
Team team = new Team(memberSpaceRelationRepository.findAllBySpaceId(spaceId));
team.validateTeamMembership(memberId);

Retrospect retrospect = retrospectRepository.findByIdOrThrow(retrospectId);
retrospect.validateRetrospectStatusDone();

// answer 뽑기
Answers answers = new Answers(answerRepository.findAllByRetrospectId(retrospectId));
answers.validateIsWriteDone(memberId, retrospectId);

List<Long> questionIds = answers.getAnswers().stream().map(Answer::getQuestionId).toList();
List<Long> memberIds = answers.getAnswers().stream().map(Answer::getMemberId).toList();

Expand Down Expand Up @@ -248,19 +251,19 @@ private List<AnswerByPersonGetResponse> getAnswerByPersonGetResponses(Answers an
question.getId(), member.getId())))
.toList();

return new AnswerByPersonGetResponse(member.getName(), questionAndAnswer);
return new AnswerByPersonGetResponse(member.getName(), member.getDeletedAt() != null, questionAndAnswer);
})
.toList();
}

private List<AnswerByQuestionGetResponse> getAnswerByQuestionGetResponses(Answers answers, Members members,
List<Question> questions) {

return questions.stream()
.map(question -> {
List<PersonAndAnswerGetResponse> personAndAnswer = answers.getAnswers().stream()
.filter(answer -> answer.getQuestionId().equals(question.getId()))
.map(answer -> new PersonAndAnswerGetResponse(members.getName(answer.getMemberId()),
answer.getContent()))
.map(answer -> new PersonAndAnswerGetResponse(members.getName(answer.getMemberId()), members.getDeleted(answer.getMemberId()), answer.getContent()))
.toList();

return new AnswerByQuestionGetResponse(question.getContent(), question.getQuestionType().getStyle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void withdraw(final Long memberId, WithdrawMemberRequest withdrawMemberRe
}


// hard delete
// soft delete
memberService.withdrawMember(memberId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
import org.layer.domain.external.google.enums.SheetType;
import org.layer.domain.external.google.service.GoogleApiService;
import org.layer.domain.jwt.SecurityUtil;
import org.layer.domain.member.controller.dto.CreateFeedbackRequest;
import org.layer.domain.member.controller.dto.GetMemberAnalyzesResponse;
import org.layer.domain.member.controller.dto.GetMemberRecentAnalyzeResponse;
import org.layer.domain.member.controller.dto.GetMemberRecentBadAnalyzeResponse;
import org.layer.domain.member.controller.dto.GetMemberRecentGoodAnalyzeResponse;
import org.layer.domain.member.controller.dto.GetMemberRecentImprovementAnalyzeResponse;
import org.layer.domain.member.controller.dto.UpdateMemberInfoRequest;
import org.layer.domain.member.controller.dto.UpdateMemberInfoResponse;
import org.layer.domain.member.controller.dto.*;
import org.layer.domain.member.entity.Member;
import org.layer.domain.member.entity.MemberFeedback;
import org.layer.domain.member.entity.SocialType;
Expand All @@ -28,14 +21,12 @@
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.Space;
import org.layer.domain.space.repository.MemberSpaceRelationRepository;
import org.layer.oauth.dto.service.MemberInfoServiceResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -48,7 +39,7 @@
@RequiredArgsConstructor
@Service
public class MemberService {
private static final int TWO_MONTHS = 2;
private static final int TWO_MONTHS = 2;

private final MemberRepository memberRepository;
private final MemberSpaceRelationRepository memberSpaceRelationRepository;
Expand Down Expand Up @@ -122,7 +113,7 @@ public Member getMemberByMemberId(Long memberId) {
@Transactional
public void withdrawMember(Long memberId) {
Member currentMember = getCurrentMember();
memberRepository.delete(currentMember);
currentMember.deleteMember();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,18 @@ public void closeRetrospect(Long spaceId, Long retrospectId, Long memberId) {

Retrospect retrospect = retrospectRepository.findByIdOrThrow(retrospectId);

retrospect.updateRetrospectStatus(RetrospectStatus.DONE, time.now());
retrospect.updateRetrospectStatus(RetrospectStatus.DONE);
if (retrospect.getAnalysisStatus().equals(AnalysisStatus.DONE)) { // 이미 분석은 완료했지만, 마감되지 않은 경우
return;
}

retrospect.updateAnalysisStatus(AnalysisStatus.PROCEEDING);
retrospectRepository.saveAndFlush(retrospect);

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

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public List<SpaceResponse.SpaceMemberResponse> getSpaceMembers(Long memberId, Lo
log.info("?");
var SpaceMembers = spaceRepository.findAllSpaceMemberBySpaceIdWithIsLeader(spaceId);
return SpaceMembers.stream()
.filter(a -> a.getDeletedAt() == null)
.map(SpaceResponse.SpaceMemberResponse::toResponse)
.sorted(
Comparator.comparing(SpaceResponse.SpaceMemberResponse::isLeader).reversed())
Expand Down
4 changes: 2 additions & 2 deletions layer-api/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ spring:
import: optional:file:/config/application-secret.properties
datasource:
url: ${PROD_DB_URL}
username: ${DEV_DB_NAME}
password: ${DEV_DB_PASSWORD}
username: ${PROD_DB_NAME}
password: ${PROD_DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void updateRetrospectStatusToDone() {
Map<Long, Retrospect> retrospectMap = retrospects.stream()
.collect(Collectors.toMap(Retrospect::getId, retrospect -> retrospect));

retrospects.forEach(retrospect -> retrospect.updateRetrospectStatus(RetrospectStatus.DONE, now));
retrospects.forEach(retrospect -> retrospect.updateRetrospectStatus(RetrospectStatus.DONE));
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 @@ -28,7 +28,6 @@ public class Answers {

private final List<Answer> answers;


public String getAnswerToQuestion(Long questionId, Long memberId) {
return answers.stream()
.filter(answer -> answer.getQuestionId().equals(questionId) && answer.getMemberId().equals(memberId))
Expand All @@ -43,20 +42,28 @@ public boolean hasRetrospectAnswer(Long memberId, Long retrospectId) {
.anyMatch(answer -> answer.getMemberId().equals(memberId));
}

public void validateIsWriteDone(Long memberId, Long retrospectId) {
WriteStatus writeStatus = getWriteStatus(memberId, retrospectId);

if (!writeStatus.equals(WriteStatus.DONE)) {
throw new AnswerException(NOT_ANSWERED);
}
}

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){
if (isDoneWrite) {
return WriteStatus.DONE;
}

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){
if (isTemporaryWrite) {
return WriteStatus.PROCEEDING;
}

Expand All @@ -70,7 +77,7 @@ public long getWriteCount(Long retrospectId) {

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

if(!answersByRetrospectId.containsKey(retrospectId)){
if (!answersByRetrospectId.containsKey(retrospectId)) {
return 0L;
}

Expand Down Expand Up @@ -111,9 +118,10 @@ public void validateAlreadyAnswer(Long memberId, Long retrospectId) {
}
}

public String getTotalAnswer(Long rangeQuestionId, Long numberQuestionId){
public String getTotalAnswer(Long rangeQuestionId, Long numberQuestionId) {
Map<Long, String> answerConcatMap = answers.stream()
.filter(answer -> !answer.getQuestionId().equals(rangeQuestionId) && !answer.getQuestionId().equals(numberQuestionId))
.filter(answer -> !answer.getQuestionId().equals(rangeQuestionId) && !answer.getQuestionId()
.equals(numberQuestionId))
.collect(Collectors.groupingBy(
Answer::getMemberId, Collectors.mapping(Answer::getContent, Collectors.joining(" "))));

Expand All @@ -125,10 +133,11 @@ public String getTotalAnswer(Long rangeQuestionId, Long numberQuestionId){
return String.join("\n&&\n", answerMap.values());
}

public String getIndividualAnswer(Long rangeQuestionId, Long numberQuestionId, Long memberId){
public String getIndividualAnswer(Long rangeQuestionId, Long numberQuestionId, Long memberId) {
Map<Long, String> answerConcatMap = answers.stream()
.filter(answer -> answer.getMemberId().equals(memberId))
.filter(answer -> !answer.getQuestionId().equals(rangeQuestionId) && !answer.getQuestionId().equals(numberQuestionId))
.filter(answer -> !answer.getQuestionId().equals(rangeQuestionId) && !answer.getQuestionId()
.equals(numberQuestionId))
.collect(Collectors.groupingBy(
Answer::getMemberId, Collectors.mapping(Answer::getContent, Collectors.joining(" "))));

Expand All @@ -140,7 +149,6 @@ public String getIndividualAnswer(Long rangeQuestionId, Long numberQuestionId, L
return String.join("\n&&\n", answerMap.values());
}


public int getGoalCompletionRate(Long questionId) {

int sum = 0;
Expand All @@ -152,7 +160,7 @@ public int getGoalCompletionRate(Long questionId) {
}
}

if(count == ZERO){
if (count == ZERO) {
throw new AnswerException(NOT_CONTAIN_ANSWERS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.NoArgsConstructor;
import org.layer.domain.common.BaseTimeEntity;

import java.time.LocalDateTime;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -36,6 +38,9 @@ public class Member extends BaseTimeEntity {
private String profileImageUrl;


private LocalDateTime deletedAt;


@Builder(access = AccessLevel.PUBLIC)
private Member(String name, String email, MemberRole memberRole,
SocialType socialType, String socialId) {
Expand All @@ -53,4 +58,8 @@ public void updateName(String name) {
public void updateProfileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
}

public void deleteMember() {
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.layer.domain.member.entity;

import java.util.List;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

@RequiredArgsConstructor
@Getter
public class Members {
Expand All @@ -17,4 +17,12 @@ public String getName(Long memberId) {
.findAny()
.orElse(null);
}

public Boolean getDeleted(Long memberId) {
return members.stream()
.filter(member -> member.getId().equals(memberId))
.map(m -> m.getDeletedAt() != null) // 지워졌으면 true, 아니면 false
.findAny()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ public void updateRetrospect(String title, String introduction, LocalDateTime de
this.deadline = deadline;
}

public void updateRetrospectStatus(RetrospectStatus retrospectStatus, LocalDateTime now) {
public void updateRetrospectStatus(RetrospectStatus retrospectStatus) {
isProceedingRetrospect();

if(this.deadline != null && now.isBefore(this.deadline)){
return;
}

this.retrospectStatus = retrospectStatus;
}

public void updateAnalysisStatus(AnalysisStatus analysisStatus) {
this.analysisStatus = analysisStatus;
}

public boolean hasDeadLine() {
if (this.deadline == null) {
return false;
}

return true;
}
}
Loading

0 comments on commit c70ea22

Please sign in to comment.