Skip to content

Commit

Permalink
feature: 리뷰 임시저장 구현
Browse files Browse the repository at this point in the history
related to: #18
  • Loading branch information
heejjinkim committed Oct 14, 2024
1 parent 2db7cfb commit 2746434
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/_119/wepro/review/domain/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ public class Option {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Option option = (Option) o;

if (id != null ? !id.equals(option.id) : option.id != null) return false;
if (id != null ? !id.equals(option.id) : option.id != null) {
return false;
}
return content != null ? content.equals(option.content) : option.content == null;
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/_119/wepro/review/dto/ChoiceAnswerDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com._119.wepro.review.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ChoiceAnswerDto {

private Long questionId;
private Long optionId;
}
12 changes: 12 additions & 0 deletions src/main/java/com/_119/wepro/review/dto/SubAnswerDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com._119.wepro.review.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class SubAnswerDto {

private Long questionId;
private String answerText;
}
15 changes: 15 additions & 0 deletions src/main/java/com/_119/wepro/review/dto/request/ReviewRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com._119.wepro.review.dto.request;

import com._119.wepro.review.dto.ChoiceAnswerDto;
import com._119.wepro.review.dto.SubAnswerDto;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -35,4 +37,17 @@ public static class ReviewAskRequest{
@NotNull
private List<Long> memberIdList;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ReviewDraftRequest{

@NotNull
private List<ChoiceAnswerDto> choiceAnswerList;

@NotNull
private List<SubAnswerDto> subAnswerList;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com._119.wepro.review.presentation;

import com._119.wepro.global.util.SecurityUtil;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewAskRequest;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewFormCreateRequest;
import com._119.wepro.review.dto.response.ReviewResponse.ProjectMemberGetResponse;
import com._119.wepro.review.dto.response.ReviewResponse.ReviewFormCreateResponse;
import com._119.wepro.review.dto.request.ReviewRequest.*;
import com._119.wepro.review.dto.response.ReviewResponse.*;
import com._119.wepro.review.service.ReviewService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -41,6 +40,15 @@ public ResponseEntity<Void> requestReview(@RequestBody @Valid ReviewAskRequest r
return ResponseEntity.ok().build();
}

@Operation(summary = "리뷰 임시저장 API")
@PostMapping("/draft/{reviewFormId}")
public ResponseEntity<Void> draftReview(@PathVariable(name = "reviewFormId") Long reviewFormId,
@RequestBody @Valid ReviewDraftRequest request) {
Long memberId = securityUtil.getCurrentMemberId();
reviewService.draft(memberId, reviewFormId, request);
return ResponseEntity.ok().build();
}

@Operation(summary = "프로젝트 멤버 조회(리뷰 요청 받은 멤버 제외) API")
@GetMapping("/project/members")
public ResponseEntity<ProjectMemberGetResponse> getProjectMembers(
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/_119/wepro/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
import com._119.wepro.project.domain.repository.ProjectMemberCustomRepository;
import com._119.wepro.project.domain.repository.ProjectRepository;
import com._119.wepro.review.domain.ReviewForm;
import com._119.wepro.review.domain.ReviewRecord;
import com._119.wepro.review.domain.repository.ChoiceQuestionRepository;
import com._119.wepro.review.domain.repository.ReviewFormRepository;
import com._119.wepro.review.domain.repository.ReviewRecordRepository;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewAskRequest;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewDraftRequest;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewFormCreateRequest;
import com._119.wepro.review.dto.response.ReviewResponse.ProjectMemberGetResponse;
import com._119.wepro.review.dto.response.ReviewResponse.ReviewFormCreateResponse;
import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -36,6 +40,7 @@ public class ReviewService {
private final ProjectRepository projectRepository;
private final ChoiceQuestionRepository choiceQuestionRepository;
private final ProjectMemberCustomRepository projectMemberCustomRepository;
private final ReviewRecordRepository reviewRecordRepository;

@Transactional
public ReviewFormCreateResponse createReviewForm(ReviewFormCreateRequest request,
Expand Down Expand Up @@ -82,4 +87,23 @@ public ProjectMemberGetResponse getProjectMembers(Long reviewFormId) {

return ProjectMemberGetResponse.of(filteredMembers);
}

@Transactional
public void draft(Long memberId, Long reviewFormId, ReviewDraftRequest request) {
Member writer = memberRepository.findById(memberId)
.orElseThrow(() -> new RestApiException(UserErrorCode.USER_NOT_FOUND));

ReviewForm reviewForm = reviewFormRepository.findById(reviewFormId)
.orElseThrow(() -> new RestApiException(ReviewErrorCode.REVIEW_FORM_NOT_FOUND));

Optional<ReviewRecord> savedReviewRecord = reviewRecordRepository.findByReviewForm(reviewForm);

if (savedReviewRecord.isPresent()) { // 첫 번째 이후의 임시저장
ReviewRecord reviewRecord = savedReviewRecord.get();
reviewRecord.update(request);
} else { // 첫 번재 임시저장
ReviewRecord reviewRecord = ReviewRecord.of(writer, reviewForm, request);
reviewRecordRepository.save(reviewRecord);
}
}
}

0 comments on commit 2746434

Please sign in to comment.