Skip to content

Commit 3d43e09

Browse files
committed
refactor(review): 봉사 지원 생성 리팩토링
- ReviewQueryUseCase 의존하도록 변경
1 parent e5559f9 commit 3d43e09

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/main/java/com/somemore/domains/review/dto/request/ReviewCreateRequestDto.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.somemore.domains.review.dto.request;
22

33
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
45
import com.fasterxml.jackson.databind.annotation.JsonNaming;
56
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
67
import com.somemore.domains.review.domain.Review;
@@ -10,12 +11,12 @@
1011
import java.util.UUID;
1112
import lombok.Builder;
1213

13-
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
14+
@JsonNaming(SnakeCaseStrategy.class)
1415
@Builder
1516
public record ReviewCreateRequestDto(
16-
@Schema(description = "봉사 모집글 아이디", example = "1")
17-
@NotNull(message = "봉사 모집글 아이디는 필수 값입니다.")
18-
Long recruitBoardId,
17+
@Schema(description = "봉사 지원 아이디", example = "1")
18+
@NotNull(message = "봉사 지원 아이디는 필수 값입니다.")
19+
Long volunteerApplyId,
1920
@Schema(description = "리뷰 제목", example = "내 인생 최고의 봉사 활동")
2021
@NotBlank(message = "리뷰 제목은 필수 값입니다.")
2122
String title,
@@ -24,9 +25,9 @@ public record ReviewCreateRequestDto(
2425
String content
2526
) {
2627

27-
public Review toEntity(VolunteerApply apply, UUID volunteerId, String imgUrl) {
28+
public Review toEntity(UUID volunteerId, String imgUrl) {
2829
return Review.builder()
29-
.volunteerApplyId(apply.getId())
30+
.volunteerApplyId(volunteerApplyId)
3031
.volunteerId(volunteerId)
3132
.title(title)
3233
.content(content)

src/main/java/com/somemore/domains/review/service/CreateReviewService.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED;
55

66
import com.somemore.domains.review.repository.ReviewRepository;
7+
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
78
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
89
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
910
import com.somemore.global.exception.BadRequestException;
@@ -23,24 +24,24 @@
2324
public class CreateReviewService implements CreateReviewUseCase {
2425

2526
private final ReviewRepository reviewRepository;
27+
private final ReviewQueryUseCase reviewQueryUseCase;
2628
private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase;
2729

2830
@Override
2931
public Long createReview(ReviewCreateRequestDto requestDto, UUID volunteerId, String imgUrl) {
30-
VolunteerApply apply = getVolunteerApply(requestDto.recruitBoardId(), volunteerId);
31-
validateDuplicateReview(apply);
32+
validateDuplicateReview(requestDto.volunteerApplyId());
33+
34+
VolunteerApply apply = volunteerApplyQueryUseCase.getById(requestDto.volunteerApplyId());
3235
validateActivityCompletion(apply);
3336

34-
Review review = requestDto.toEntity(apply, volunteerId, imgUrl);
35-
return reviewRepository.save(review).getId();
36-
}
37+
Review review = requestDto.toEntity(volunteerId, imgUrl);
38+
reviewRepository.save(review);
3739

38-
private VolunteerApply getVolunteerApply(Long recruitBoardId, UUID volunteerId) {
39-
return volunteerApplyQueryUseCase.getByRecruitIdAndVolunteerId(recruitBoardId, volunteerId);
40+
return review.getId();
4041
}
4142

42-
private void validateDuplicateReview(VolunteerApply apply) {
43-
if (reviewRepository.existsByVolunteerApplyId(apply.getId())) {
43+
private void validateDuplicateReview(Long volunteerApplyId) {
44+
if (reviewQueryUseCase.existsByVolunteerApplyId(volunteerApplyId)) {
4445
throw new DuplicateException(REVIEW_ALREADY_EXISTS);
4546
}
4647
}

src/main/java/com/somemore/domains/review/service/ReviewQueryService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class ReviewQueryService implements ReviewQueryUseCase {
3131
private final VolunteerQueryUseCase volunteerQueryUseCase;
3232
private final CenterQueryUseCase centerQueryUseCase;
3333

34+
@Override
35+
public boolean existsByVolunteerApplyId(Long volunteerApplyId) {
36+
return reviewRepository.existsByVolunteerApplyId(volunteerApplyId);
37+
}
38+
3439
@Override
3540
public Review getById(Long id) {
3641
return reviewRepository.findById(id).orElseThrow(

src/main/java/com/somemore/domains/review/usecase/ReviewQueryUseCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
public interface ReviewQueryUseCase {
1212

13+
boolean existsByVolunteerApplyId(Long volunteerApplyId);
14+
1315
Review getById(Long id);
1416

1517
ReviewDetailResponseDto getDetailById(Long id);

0 commit comments

Comments
 (0)