Skip to content

Commit

Permalink
[BE] feat: 리뷰에 필요한 정보 조회 기능 추가 (#103)
Browse files Browse the repository at this point in the history
* test: QuestionTestFixture 생성

* feat: 모든 리뷰 문항을 조회하는 기능 구현

* feat: 모든 키워드를 조회하는 기능 구현

* test: ReviewerGroupFixture 생성

* feat: 리뷰 생성 시 필요한 리뷰어 그룹 정보를 조회하는 기능 구현

* feat: 리뷰 생성 시 필요한 정보를 조회하는 기능 구현

* refactor: @servicetest 적용

* refactor: swagger 적용

* refactor: 필드명 변경

* style: 개행 추가

* refactor: 날짜 형식 변경

* test: import문 제거

* refactor: ReviewCreationResponse 패키지 변경

* refactor: readOnly 트랜잭션 적용

* fix: 리뷰어 중복 검증 임시 제거

---------

Co-authored-by: donghoony <[email protected]>
  • Loading branch information
skylar1220 and donghoony authored Jul 25, 2024
1 parent 8706a80 commit 9be248e
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public record KeywordResponse(
long id,

@Schema(description = "키워드명")
String detail
String content
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.keyword.dto.response.KeywordResponse;
import reviewme.keyword.dto.response.KeywordsResponse;
import reviewme.keyword.repository.KeywordRepository;

@Service
Expand All @@ -13,11 +13,11 @@ public class KeywordService {

private final KeywordRepository keywordRepository;

public KeywordsResponse findAllKeywords() {
List<KeywordResponse> responses = keywordRepository.findAll()
@Transactional(readOnly = true)
public List<KeywordResponse> findAllKeywords() {
return keywordRepository.findAll()
.stream()
.map(keyword -> new KeywordResponse(keyword.getId(), keyword.getContent()))
.toList();
return new KeywordsResponse(responses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import reviewme.member.domain.exception.InvalidDescriptionLengthException;
Expand All @@ -29,6 +30,7 @@
@Entity
@Table(name = "reviewer_group")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(of = "id")
@Getter
public class ReviewerGroup {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public ReviewerGroupGithubIds(ReviewerGroup reviewerGroup, List<GithubId> github
Set<GithubIdReviewerGroup> reviewers = githubIds.stream()
.map(githubId -> new GithubIdReviewerGroup(githubId, reviewerGroup))
.collect(Collectors.toSet());
if (reviewers.size() != githubIds.size()) {
throw new DuplicateReviewerException();
}
// if (reviewers.size() != githubIds.size()) {
// throw new DuplicateReviewerException();
// }
this.reviewerGithubIds = reviewers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package reviewme.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

@Schema(description = "리뷰 생성 시 필요한 리뷰어 그룹 응답")
public record ReviewCreationReviewerGroupResponse(

@Schema(description = "리뷰어 그룹 아이디")
long id,

@Schema(description = "리뷰 그룹 이름 (레포지토리명)")
String name,

@Schema(description = "그룹 소개")
String description,

@Schema(description = "리뷰 작성 기한")
LocalDateTime deadline,

@Schema(description = "썸네일 URL")
String thumbnailUrl,

@Schema(description = "리뷰이")
MemberResponse reviewee
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.member.domain.Member;
import reviewme.member.domain.ReviewerGroup;
import reviewme.member.dto.response.MemberResponse;
import reviewme.member.dto.response.ReviewerGroupResponse;
import reviewme.member.repository.ReviewerGroupRepository;
import reviewme.member.dto.response.ReviewCreationReviewerGroupResponse;

@Service
@RequiredArgsConstructor
Expand All @@ -24,4 +26,18 @@ public ReviewerGroupResponse findReviewerGroup(long reviewerGroupId) {
new MemberResponse(reviewee.getId(), reviewee.getName())
);
}

@Transactional(readOnly = true)
public ReviewCreationReviewerGroupResponse findReviewCreationReviewerGroup(long reviewerGroupId) {
ReviewerGroup reviewerGroup = reviewerGroupRepository.getReviewerGroupById(reviewerGroupId);
Member reviewee = reviewerGroup.getReviewee();
return new ReviewCreationReviewerGroupResponse(
reviewerGroup.getId(),
reviewerGroup.getGroupName(),
reviewerGroup.getDescription(),
reviewerGroup.getDeadline(),
reviewerGroup.getThumbnailUrl(),
new MemberResponse(reviewee.getId(), reviewee.getName())
);
}
}
10 changes: 9 additions & 1 deletion backend/src/main/java/reviewme/review/controller/ReviewApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import reviewme.review.dto.response.ReviewCreationResponse;
import reviewme.review.dto.request.CreateReviewRequest;
import reviewme.review.dto.response.ReviewDetailResponse;

Expand All @@ -23,5 +25,11 @@ public interface ReviewApi {
summary = "리뷰 조회",
description = "단일 리뷰를 조회한다."
)
ResponseEntity<ReviewDetailResponse> findReview(@PathVariable long id);
ResponseEntity<ReviewDetailResponse> findReview(@PathVariable long id, @RequestParam long memberId);

@Operation(
summary = "리뷰 생성 시 필요한 정보 조회",
description = "리뷰 생성 시 필요한 정보를 조회한다."
)
ResponseEntity<ReviewCreationResponse> findReviewCreationSetup(@RequestParam long reviewerGroupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reviewme.review.dto.response.ReviewCreationResponse;
import reviewme.review.dto.request.CreateReviewRequest;
import reviewme.review.dto.response.ReviewDetailResponse;
import reviewme.review.service.ReviewService;

@RestController
@RequiredArgsConstructor
public class ReviewController {
public class ReviewController implements ReviewApi{

private final ReviewService reviewService;

Expand All @@ -32,4 +33,10 @@ public ResponseEntity<ReviewDetailResponse> findReview(@PathVariable long id,
ReviewDetailResponse response = reviewService.findReview(id, memberId);
return ResponseEntity.ok(response);
}

@GetMapping("/reviews/write")
public ResponseEntity<ReviewCreationResponse> findReviewCreationSetup(@RequestParam long reviewerGroupId) {
ReviewCreationResponse response = reviewService.findReviewCreationSetup(reviewerGroupId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package reviewme.review.dto.response;

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

@Schema(description = "리뷰 문항 응답")
public record QuestionResponse(

@Schema(description = "리뷰 문항 ID")
long id,

@Schema(description = "리뷰 문항")
String content
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package reviewme.review.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import reviewme.keyword.dto.response.KeywordResponse;
import reviewme.member.dto.response.ReviewCreationReviewerGroupResponse;

@Schema(description = "리뷰 생성 시 필요한 정보 응답")
public record ReviewCreationResponse(

@Schema(description = "리뷰어 그룹")
ReviewCreationReviewerGroupResponse reviewerGroup,

@Schema(description = "리뷰 문항 목록")
List<QuestionResponse> questions,

@Schema(description = "키워드 목록")
List<KeywordResponse> keywords
) {
}
23 changes: 23 additions & 0 deletions backend/src/main/java/reviewme/review/service/QuestionService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package reviewme.review.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.review.dto.response.QuestionResponse;
import reviewme.review.repository.QuestionRepository;

@Service
@RequiredArgsConstructor
public class QuestionService {

private final QuestionRepository questionRepository;

@Transactional(readOnly = true)
public List<QuestionResponse> findAllQuestions() {
return questionRepository.findAll()
.stream()
.map(question -> new QuestionResponse(question.getId(), question.getContent()))
.toList();
}
}
17 changes: 17 additions & 0 deletions backend/src/main/java/reviewme/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
import org.springframework.transaction.annotation.Transactional;
import reviewme.keyword.domain.Keyword;
import reviewme.keyword.domain.Keywords;
import reviewme.keyword.dto.response.KeywordResponse;
import reviewme.keyword.repository.KeywordRepository;
import reviewme.keyword.service.KeywordService;
import reviewme.member.domain.Member;
import reviewme.member.domain.ReviewerGroup;
import reviewme.member.repository.MemberRepository;
import reviewme.member.repository.ReviewerGroupRepository;
import reviewme.member.service.ReviewerGroupService;
import reviewme.review.domain.Question;
import reviewme.review.domain.Review;
import reviewme.review.domain.ReviewContent;
import reviewme.review.dto.response.ReviewCreationResponse;
import reviewme.review.dto.response.QuestionResponse;
import reviewme.member.dto.response.ReviewCreationReviewerGroupResponse;
import reviewme.review.dto.request.CreateReviewRequest;
import reviewme.review.dto.response.ReviewDetailResponse;
import reviewme.review.dto.response.ReviewDetailReviewContentResponse;
Expand All @@ -28,6 +34,9 @@
@RequiredArgsConstructor
public class ReviewService {

private final ReviewerGroupService reviewerGroupService;
private final KeywordService keywordService;
private final QuestionService questionService;
private final ReviewRepository reviewRepository;
private final MemberRepository memberRepository;
private final ReviewerGroupRepository reviewerGroupRepository;
Expand Down Expand Up @@ -100,4 +109,12 @@ public ReviewDetailResponse findReview(long reviewId, long memberId) {
keywordContents
);
}

@Transactional(readOnly = true)
public ReviewCreationResponse findReviewCreationSetup(long reviewerGroupId) {
ReviewCreationReviewerGroupResponse reviewerGroup = reviewerGroupService.findReviewCreationReviewerGroup(reviewerGroupId);
List<QuestionResponse> questions = questionService.findAllQuestions();
List<KeywordResponse> keywords = keywordService.findAllKeywords();
return new ReviewCreationResponse(reviewerGroup, questions, keywords);
}
}
18 changes: 18 additions & 0 deletions backend/src/test/java/reviewme/fixture/QuestionFixure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package reviewme.fixture;

import reviewme.review.domain.Question;

public enum QuestionFixure {

소프트스킬이_어떤가요,
기술역량이_어떤가요,
;

public Question create() {
return new Question(replaceUnderscores());
}

private String replaceUnderscores() {
return name().replace("_", " ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Getter
public enum ReviewerGroupFixture {

리뷰_그룹("리뷰 그룹", "그룹 설명", LocalDateTime.of(2024, 1, 1, 12, 0)),
데드라인_남은_그룹("데드라인 이전 그룹", "설명", LocalDateTime.now().plusDays(1)),
데드라인_지난_그룹("데드라인 지난 그룹", "설명", LocalDateTime.now().minusDays(1)),
;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package reviewme.keyword.service;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import reviewme.fixture.KeywordFixture;
import reviewme.keyword.dto.response.KeywordResponse;
import reviewme.keyword.repository.KeywordRepository;
import reviewme.support.ServiceTest;

@ServiceTest
class KeywordServiceTest {

@Autowired
KeywordService keywordService;

@Autowired
KeywordRepository keywordRepository;

@Test
void 모든_키워드를_조회한다() {
// given
keywordRepository.save(KeywordFixture.회의를_이끌어요.create());

// when
List<KeywordResponse> keywords = keywordService.findAllKeywords();

// then
assertThat(keywords).hasSize(1);
}
}
Loading

0 comments on commit 9be248e

Please sign in to comment.