Skip to content

Commit

Permalink
Merge pull request #45 from Team-Puzzling/feat/#37-review-my-start-en…
Browse files Browse the repository at this point in the history
…d-get-api

#37 [FEAT] 기간에 따른 회고 상세 조회 API
  • Loading branch information
yeseul106 authored Jul 17, 2023
2 parents 25c2c87 + a5dde45 commit 61c4da0
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ public ProjectJoinResponseDto joinProject(Long memberId, ProjectJoinRequestDto p
if ( projectJoinRequestDto.getProjectId() == null ) {
throw new BadRequestException("공백일 수 없습니다. (reviewTemplateId)");
}
if (userProjectRepository.existsByMemberIdAndProjectId(memberId, projectJoinRequestDto.getProjectId())){
throw new BadRequestException(("이미 프로젝트에 참여한 팀원입니다."));
}
if (userProjectRepository.existsByProjectIdAndNickname(projectJoinRequestDto.getProjectId(),projectJoinRequestDto.getMemberProjectNickname())){
throw new BadRequestException(("이미 프로젝트에 있는 닉네임입니다."));
}
if (userProjectRepository.existsByMemberIdAndProjectId(memberId, projectJoinRequestDto.getProjectId())){
throw new BadRequestException(("이미 프로젝트에 참여한 팀원입니다."));
}
Member member = findMemberById(memberId);
Project project = findProjectById(projectJoinRequestDto.getProjectId());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.puzzling.puzzlingServer.api.review.controller;

import com.puzzling.puzzlingServer.api.review.dto.request.Review5FRequestDto;
import com.puzzling.puzzlingServer.api.review.dto.response.MyReviewProjectResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewActionPlanResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.*;
import com.puzzling.puzzlingServer.api.review.dto.request.ReviewAARRequestDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewPreviousTemplateResponseDto;

import com.puzzling.puzzlingServer.api.review.dto.response.ReviewTeamStatusResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewTemplateGetResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.request.ReviewTILRequestDto;
import com.puzzling.puzzlingServer.api.review.service.ReviewService;
import com.puzzling.puzzlingServer.common.response.ApiResponse;
Expand Down Expand Up @@ -65,6 +61,12 @@ public ApiResponse<ReviewTeamStatusResponseDto> getTeamReviewStatus(@PathVariabl
return ApiResponse.success(SuccessStatus.GET_REVIEW_TEAM_STATUS_SUCCESS, reviewService.getTeamReviewStatus(projectId, startDate, endDate));
}

@GetMapping("member/{memberId}/project/{projectId}/team/review")
public ApiResponse<ReviewDetailResponseDto> getMyReviewDetail(@PathVariable Long memberId, @PathVariable Long projectId,
@RequestParam String startDate, @RequestParam String endDate) {
return ApiResponse.success(SuccessStatus.GET_MY_REVIEWS_DETAIL_SUCCESS, reviewService.getMyReviewDetail(memberId, projectId, startDate, endDate));
}

@GetMapping("member/{memberId}/project/{projectId}/review")
public ApiResponse<MyReviewProjectResponseDto> getMyReviewProjects(@PathVariable Long memberId, @PathVariable Long projectId) {
return ApiResponse.success(SuccessStatus.GET_PROJECT_MY_REVIEWS_SUCCESS, reviewService.getMyReviewProjects(memberId, projectId));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.puzzling.puzzlingServer.api.review.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static lombok.AccessLevel.PRIVATE;

@Getter
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
public class ReviewContentObjectDto {
private String title;
private String content;

public static ReviewContentObjectDto of (String title, String content) {
return new ReviewContentObjectDto(title, content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.puzzling.puzzlingServer.api.review.dto.response;

import com.puzzling.puzzlingServer.api.review.domain.Review;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Getter
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
public class ReviewDetailResponseDto {
private Long reviewId;
private String reviewDay;
private String reviewDate;
private Long reviewTemplateId;
private List<ReviewContentObjectDto> contents;

public static ReviewDetailResponseDto of (Long reviewId, String reviewDay, String reviewDate,
Long reviewTemplateId, List<ReviewContentObjectDto> contents) {
return new ReviewDetailResponseDto(reviewId, reviewDay, reviewDate, reviewTemplateId, contents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
import com.puzzling.puzzlingServer.api.template.domain.ReviewAAR;
import com.puzzling.puzzlingServer.api.template.domain.ReviewTIL;
import com.puzzling.puzzlingServer.api.template.domain.ReviewTemplate;
import com.puzzling.puzzlingServer.api.template.strategy.AARReviewTemplateStrategy;
import com.puzzling.puzzlingServer.api.template.strategy.FiveFReviewTemplateStrategy;
import com.puzzling.puzzlingServer.api.template.strategy.ReviewTemplateStrategy;
import com.puzzling.puzzlingServer.api.template.strategy.TILReviewTemplateStrategy;
import com.puzzling.puzzlingServer.common.exception.BadRequestException;
import com.puzzling.puzzlingServer.common.exception.NotFoundException;
import com.puzzling.puzzlingServer.common.util.DateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
Expand All @@ -42,8 +47,7 @@
import java.util.stream.Collectors;

import static com.puzzling.puzzlingServer.common.response.ErrorStatus.NOT_FOUND_PROJECT;
import static com.puzzling.puzzlingServer.common.util.DateUtil.checkTodayIsReviewDay;
import static com.puzzling.puzzlingServer.common.util.DateUtil.getDayOfWeek;
import static com.puzzling.puzzlingServer.common.util.DateUtil.*;


@Service
Expand Down Expand Up @@ -84,7 +88,7 @@ public void createReviewTIL(Long memberId, Long projectId, ReviewTILRequestDto r
Review review = Review.builder()
.userProject(userProject)
.reviewTemplate(reviewTemplate)
.reviewDate("123")
.reviewDate(convertLocalDatetoString(LocalDate.now()))
.memberId(memberId)
.projectId(projectId)
.build();
Expand Down Expand Up @@ -115,7 +119,7 @@ public void createReview5F(Long memberId, Long projectId, Review5FRequestDto rev
Review review = Review.builder()
.userProject(userProject)
.reviewTemplate(reviewTemplate)
.reviewDate("123")
.reviewDate(convertLocalDatetoString(LocalDate.now()))
.memberId(memberId)
.projectId(projectId)
.build();
Expand Down Expand Up @@ -148,7 +152,7 @@ public void createReviewAAR(Long memberId, Long projectId, ReviewAARRequestDto r
Review review = Review.builder()
.userProject(userProject)
.reviewTemplate(reviewTemplate)
.reviewDate("123")
.reviewDate(convertLocalDatetoString(LocalDate.now()))
.memberId(memberId)
.projectId(projectId)
.build();
Expand Down Expand Up @@ -177,10 +181,6 @@ public ReviewPreviousTemplateResponseDto getPreviousReviewTemplate(Long memberId
public List<ReviewActionPlanResponseDto> getReviewActionPlans(Long memberId, Long projectId) {
List<Review> findReviews = reviewRepository.findAllByMemberIdAndProjectIdOrderByReviewDateDesc(memberId, projectId);

if (findReviews.isEmpty()) {
throw new BadRequestException("유저가 해당 프로젝트 팀원이 아닙니다.");
}

return findReviews.stream()
.map(findReview -> {
String reviewTemplateName = findReview.getReviewTemplate().getName();
Expand Down Expand Up @@ -233,17 +233,58 @@ public List<ReviewTeamStatusResponseDto> getTeamReviewStatus(Long projectId, Str
return result;
}

private Project findProjectById (Long projectId) {
return projectRepository.findById(projectId).orElseThrow(() ->
new NotFoundException(NOT_FOUND_PROJECT.getMessage()));
@Override
@Transactional
public List<ReviewDetailResponseDto> getMyReviewDetail(Long memberId, Long projectId, String startDate, String endDate) {
List<ReviewDetailResponseDto> result = new ArrayList<>();
String reviewCycle = findProjectById(projectId).getReviewCycle();

List<String> reviewDates = generateReviewDates(startDate, endDate, reviewCycle);

for (String reviewDate : reviewDates) {
Optional<Review> findReview = reviewRepository.findByMemberIdAndProjectIdAndReviewDate(memberId, projectId, reviewDate);
List<ReviewContentObjectDto> reviewContent = new ArrayList<>();

if (findReview.isPresent()) {
Review reviewValue = findReview.get();
String reviewTemplateName = reviewValue.getReviewTemplate().getName();

switch (reviewTemplateName) {
case "TIL":
ReviewTIL reviewTIL = findReviewByReviewId(reviewValue.getId(), reviewTILRepository, "TIL");
TILReviewTemplateStrategy TILStrategy = new TILReviewTemplateStrategy();
TILStrategy.getReviewContents(reviewTIL, reviewContent);
break;
case "5F":
Review5F review5F = findReviewByReviewId(reviewValue.getId(), review5FRepository, "5F");
FiveFReviewTemplateStrategy FiveFStrategy = new FiveFReviewTemplateStrategy();
FiveFStrategy.getReviewContents(review5F, reviewContent);
break;
case "AAR":
ReviewAAR reviewAAR = findReviewByReviewId(reviewValue.getId(), reviewAARRepository, "AAR");
AARReviewTemplateStrategy AARStrategy = new AARReviewTemplateStrategy();
AARStrategy.getReviewContents(reviewAAR, reviewContent);
break;
default:
throw new BadRequestException("올바르지 않은 리뷰 템플릿 이름: " + reviewTemplateName);
}

result.add(ReviewDetailResponseDto.of(reviewValue.getId(), getDayOfWeek(reviewDate), reviewDate,
reviewValue.getReviewTemplate().getId(), reviewContent));
} else {
result.add(ReviewDetailResponseDto.of(null, getDayOfWeek(reviewDate), reviewDate,
null, null));
}
}
return result;
}



@Override
@Transactional
public List<MyReviewProjectResponseDto> getMyReviewProjects(Long memberId, Long projectId) {
List<Review> findReviews = reviewRepository.findAllByMemberIdAndProjectIdOrderByReviewDateDesc(memberId, projectId);

if (findReviews.isEmpty()) {
throw new BadRequestException("유저가 해당 프로젝트 팀원이 아닙니다.");
}
return findReviews.stream()
.map(findReview -> {
String reviewTemplateName = findReview.getReviewTemplate().getName();
Expand All @@ -265,6 +306,11 @@ public List<MyReviewProjectResponseDto> getMyReviewProjects(Long memberId, Long
.collect(Collectors.toList());
}

private Project findProjectById (Long projectId) {
return projectRepository.findById(projectId).orElseThrow(() ->
new NotFoundException(NOT_FOUND_PROJECT.getMessage()));
}

private ReviewTemplate findReviewTemplateById (Long reviewTemplateId) {
return reviewTemplateRepository.findById(reviewTemplateId)
.orElseThrow(() -> new NotFoundException("해당하는 회고 팀플릿이 없습니다."));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.puzzling.puzzlingServer.api.review.service;

import com.puzzling.puzzlingServer.api.review.dto.request.Review5FRequestDto;
import com.puzzling.puzzlingServer.api.review.dto.response.MyReviewProjectResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewActionPlanResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.*;
import com.puzzling.puzzlingServer.api.review.dto.request.ReviewAARRequestDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewPreviousTemplateResponseDto;

import com.puzzling.puzzlingServer.api.review.dto.response.ReviewTeamStatusResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewTemplateGetResponseDto;
import com.puzzling.puzzlingServer.api.review.dto.request.ReviewTILRequestDto;


Expand All @@ -30,4 +26,6 @@ public interface ReviewService {

List<MyReviewProjectResponseDto> getMyReviewProjects(Long memberId, Long projectId);

List<ReviewDetailResponseDto> getMyReviewDetail(Long memberId, Long projectId, String startDate, String endDate);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.puzzling.puzzlingServer.api.template.strategy;

import com.puzzling.puzzlingServer.api.review.dto.response.ReviewContentObjectDto;
import com.puzzling.puzzlingServer.api.template.domain.ReviewAAR;

import java.util.List;

public class AARReviewTemplateStrategy implements ReviewTemplateStrategy<ReviewAAR> {
@Override
public List<ReviewContentObjectDto> getReviewContents(ReviewAAR review, List<ReviewContentObjectDto> reviewContent) {
reviewContent.add(new ReviewContentObjectDto("초기의 목표", review.getInitialGoal()));
reviewContent.add(new ReviewContentObjectDto("결과", review.getResult()));
reviewContent.add(new ReviewContentObjectDto("차이가 발생한 이유", review.getDifference()));
reviewContent.add(new ReviewContentObjectDto("지속하고 싶은 점", review.getPersistence()));
reviewContent.add(new ReviewContentObjectDto("앞으로의 목적", review.getActionPlan()));
return reviewContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.puzzling.puzzlingServer.api.template.strategy;

import com.puzzling.puzzlingServer.api.review.dto.response.ReviewContentObjectDto;
import com.puzzling.puzzlingServer.api.template.domain.Review5F;

import java.util.List;

public class FiveFReviewTemplateStrategy implements ReviewTemplateStrategy<Review5F> {
@Override
public List<ReviewContentObjectDto> getReviewContents(Review5F review, List<ReviewContentObjectDto> reviewContent) {
reviewContent.add(new ReviewContentObjectDto("Fact", review.getFact()));
reviewContent.add(new ReviewContentObjectDto("Feeling", review.getFeeling()));
reviewContent.add(new ReviewContentObjectDto("Finding", review.getFinding()));
reviewContent.add(new ReviewContentObjectDto("Future action", review.getActionPlan()));
reviewContent.add(new ReviewContentObjectDto("Feedback", review.getFeedback()));
return reviewContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.puzzling.puzzlingServer.api.template.strategy;

import com.puzzling.puzzlingServer.api.review.domain.Review;
import com.puzzling.puzzlingServer.api.review.dto.response.ReviewContentObjectDto;

import java.util.List;

public interface ReviewTemplateStrategy<T> {
List<ReviewContentObjectDto> getReviewContents(T review, List<ReviewContentObjectDto> reviewContent);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.puzzling.puzzlingServer.api.template.strategy;

import com.puzzling.puzzlingServer.api.review.dto.response.ReviewContentObjectDto;
import com.puzzling.puzzlingServer.api.template.domain.ReviewTIL;

import java.util.List;

public class TILReviewTemplateStrategy implements ReviewTemplateStrategy<ReviewTIL> {
@Override
public List<ReviewContentObjectDto> getReviewContents(ReviewTIL review, List<ReviewContentObjectDto> reviewContent) {
reviewContent.add(new ReviewContentObjectDto("잘한 점", review.getLiked()));
reviewContent.add(new ReviewContentObjectDto("아쉬운 점", review.getLacked()));
reviewContent.add(new ReviewContentObjectDto("배운 점", review.getActionPlan()));
return reviewContent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public enum SuccessStatus {
GET_REVIEW_PREVIOUS_TEMPLATE_SUCCESS(HttpStatus.OK, "이전 회고 템플릿 조회 성공"),
GET_REVIEW_ACTION_PLAN_SUCCESS(HttpStatus.OK, "ACTIONPLAN 내용 조회 성공"),
GET_REVIEW_TEAM_STATUS_SUCCESS(HttpStatus.OK, "팀원 회고 상황 조회 성공"),
GET_PROJECT_MY_REVIEWS_SUCCESS(HttpStatus.OK, "해당 프로젝트 내 회고 리스트 조회 성공")
GET_PROJECT_MY_REVIEWS_SUCCESS(HttpStatus.OK, "해당 프로젝트 내 회고 리스트 조회 성공"),
GET_MY_REVIEWS_DETAIL_SUCCESS(HttpStatus.OK, "회고 상세 조회 성공")
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public static String getDayOfWeek(String dateStr) {

return dayOfWeekKorean;
}

public static String convertLocalDatetoString(LocalDate localDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return localDate.format(formatter);
}
}

0 comments on commit 61c4da0

Please sign in to comment.