Skip to content

Commit 60bfd73

Browse files
committed
refactor(volunteer-apply): 특정 모집글에 대한 봉사자의 지원 조회 필드 추가
- 리뷰 작성 여부 추가
1 parent a7cea1a commit 60bfd73

File tree

6 files changed

+48
-61
lines changed

6 files changed

+48
-61
lines changed

src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
66
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
77
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
8+
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto;
89
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase;
910
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
1011
import com.somemore.global.auth.annotation.CurrentUser;
@@ -34,19 +35,18 @@ public class VolunteerApplyQueryApiController {
3435

3536
@Operation(summary = "특정 모집글 봉사자 지원 단건 조회", description = "특정 모집글에 대한 봉사자 지원을 조회합니다.")
3637
@GetMapping("/volunteer-apply/recruit-board/{recruitBoardId}/volunteer/{volunteerId}")
37-
public ApiResponse<?> getVolunteerApplyByRecruitIdAndVolunteerId(
38+
public ApiResponse<VolunteerApplyWithReviewStatusResponseDto> getVolunteerApplyByRecruitIdAndVolunteerId(
3839
@PathVariable Long recruitBoardId,
3940
@PathVariable UUID volunteerId
4041
) {
4142
try {
4243
return ApiResponse.ok(
4344
200,
44-
volunteerApplyQueryUseCase.getVolunteerApplyByRecruitIdAndVolunteerId(
45-
recruitBoardId, volunteerId),
45+
volunteerApplyQueryFacadeUseCase.getVolunteerApplyByRecruitIdAndVolunteerId(recruitBoardId, volunteerId),
4646
"특정 모집글에 대한 봉사자 지원 단건 조회 성공"
4747
);
4848
} catch (NoSuchElementException e) {
49-
return ApiResponse.ok(210, "지원 내역이 없습니다.");
49+
return ApiResponse.ok(210, null, "지원 내역이 없습니다.");
5050
}
5151
}
5252

src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyResponseDto.java renamed to src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyWithReviewStatusResponseDto.java

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

3-
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
44
import com.fasterxml.jackson.databind.annotation.JsonNaming;
55
import com.somemore.domains.volunteerapply.domain.ApplyStatus;
66
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
@@ -9,33 +9,35 @@
99
import java.util.UUID;
1010
import lombok.Builder;
1111

12-
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
12+
@JsonNaming(SnakeCaseStrategy.class)
1313
@Builder
14-
public record VolunteerApplyResponseDto(
14+
public record VolunteerApplyWithReviewStatusResponseDto(
1515
@Schema(description = "봉사 지원 ID", example = "1")
1616
Long id,
1717
@Schema(description = "봉사자 UUID", example = "f5a8779a-bcc9-4fc5-b8a1-7b2a383054a9")
1818
UUID volunteerId,
1919
@Schema(description = "모집글 ID", example = "101")
2020
Long recruitBoardId,
21-
@Schema(description = "지원 상태", example = "WAITING", allowableValues = {"WAITING",
22-
"APPROVED", "REJECTED"})
21+
@Schema(description = "지원 상태", example = "WAITING", allowableValues = {"WAITING", "APPROVED", "REJECTED"})
2322
ApplyStatus status,
2423
@Schema(description = "봉사 참여 여부", example = "false")
2524
Boolean attended,
25+
@Schema(description = "리뷰 작성 여부", example = "false")
26+
Boolean isReviewed,
2627
@Schema(description = "지원서 생성 일시", example = "2024-11-01T12:00:00")
2728
LocalDateTime createdAt,
2829
@Schema(description = "지원서 수정 일시", example = "2024-11-01T12:30:00")
2930
LocalDateTime updatedAt
3031
) {
3132

32-
public static VolunteerApplyResponseDto from(VolunteerApply volunteerApply) {
33-
return VolunteerApplyResponseDto.builder()
33+
public static VolunteerApplyWithReviewStatusResponseDto of(VolunteerApply volunteerApply, boolean isReviewed) {
34+
return VolunteerApplyWithReviewStatusResponseDto.builder()
3435
.id(volunteerApply.getId())
3536
.volunteerId(volunteerApply.getVolunteerId())
3637
.recruitBoardId(volunteerApply.getRecruitBoardId())
3738
.status(volunteerApply.getStatus())
3839
.attended(volunteerApply.getAttended())
40+
.isReviewed(isReviewed)
3941
.createdAt(volunteerApply.getCreatedAt())
4042
.updatedAt(volunteerApply.getUpdatedAt())
4143
.build();
Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package com.somemore.domains.volunteerapply.service;
22

33
import com.somemore.domains.recruitboard.domain.RecruitBoard;
4+
import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator;
45
import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase;
6+
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
57
import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo;
68
import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase;
79
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
810
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
911
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
12+
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto;
1013
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
1114
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase;
1215
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
13-
import com.somemore.global.exception.BadRequestException;
1416
import lombok.RequiredArgsConstructor;
1517
import org.springframework.data.domain.Page;
1618
import org.springframework.stereotype.Service;
@@ -21,8 +23,6 @@
2123
import java.util.UUID;
2224
import java.util.stream.Collectors;
2325

24-
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
25-
2626
@RequiredArgsConstructor
2727
@Transactional(readOnly = true)
2828
@Service
@@ -31,52 +31,49 @@ public class VolunteerApplyQueryFacadeService implements VolunteerApplyQueryFaca
3131
private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase;
3232
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
3333
private final VolunteerQueryUseCase volunteerQueryUseCase;
34+
private final ReviewQueryUseCase reviewQueryUseCase;
35+
private final RecruitBoardValidator recruitBoardValidator;
36+
37+
@Override
38+
public VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId) {
39+
VolunteerApply apply = volunteerApplyQueryUseCase.getByRecruitIdAndVolunteerId(recruitId, volunteerId);
40+
boolean isReviewed = checkIfReviewed(apply);
41+
42+
return VolunteerApplyWithReviewStatusResponseDto.of(apply, isReviewed);
43+
}
3444

3545
@Override
3646
public Page<VolunteerApplyVolunteerInfoResponseDto> getVolunteerAppliesByRecruitIdAndCenterId(
3747
Long recruitId, UUID centerId, VolunteerApplySearchCondition condition) {
38-
validateAuthorization(recruitId, centerId);
39-
40-
Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitId,
41-
condition);
48+
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId);
49+
recruitBoardValidator.validateWriter(recruitBoard, centerId);
4250

43-
Map<UUID, VolunteerSimpleInfo> volunteerMap = getVolunteerInfoMap(
44-
applies);
51+
Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitId, condition);
52+
Map<UUID, VolunteerSimpleInfo> volunteerMap = getVolunteerInfoMap(applies);
4553

4654
return applies.map(
47-
apply -> VolunteerApplyVolunteerInfoResponseDto.of(
48-
apply,
49-
volunteerMap.getOrDefault(apply.getVolunteerId(), null)
50-
));
55+
apply -> VolunteerApplyVolunteerInfoResponseDto.of(apply, volunteerMap.getOrDefault(apply.getVolunteerId(), null)));
5156
}
5257

5358
@Override
5459
public Page<VolunteerApplyRecruitInfoResponseDto> getVolunteerAppliesByVolunteerId(
5560
UUID volunteerId, VolunteerApplySearchCondition condition) {
5661

57-
Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByVolunteerId(volunteerId,
58-
condition);
59-
62+
Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByVolunteerId(volunteerId, condition);
6063
Map<Long, RecruitBoard> boardMap = getRecruitBoardMap(applies);
6164

6265
return applies.map(
63-
apply -> VolunteerApplyRecruitInfoResponseDto.of(
64-
apply,
65-
boardMap.getOrDefault(apply.getRecruitBoardId(), null)
66-
));
66+
apply -> VolunteerApplyRecruitInfoResponseDto.of(apply, boardMap.getOrDefault(apply.getRecruitBoardId(), null)));
6767
}
6868

69-
private void validateAuthorization(Long recruitId, UUID centerId) {
70-
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId);
71-
if (recruitBoard.isWriter(centerId)) {
72-
return;
73-
}
74-
75-
throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD);
69+
private boolean checkIfReviewed(VolunteerApply apply) {
70+
return apply.isVolunteerActivityCompleted()
71+
&& reviewQueryUseCase.existsByVolunteerApplyId(apply.getId());
7672
}
7773

7874
private Map<Long, RecruitBoard> getRecruitBoardMap(Page<VolunteerApply> applies) {
79-
List<Long> boardIds = applies.getContent().stream().map(VolunteerApply::getRecruitBoardId)
75+
List<Long> boardIds = applies.getContent().stream()
76+
.map(VolunteerApply::getRecruitBoardId)
8077
.toList();
8178
List<RecruitBoard> boards = recruitBoardQueryUseCase.getAllByIds(boardIds);
8279

@@ -86,15 +83,14 @@ private Map<Long, RecruitBoard> getRecruitBoardMap(Page<VolunteerApply> applies)
8683
}
8784

8885
private Map<UUID, VolunteerSimpleInfo> getVolunteerInfoMap(Page<VolunteerApply> applies) {
89-
List<UUID> volunteerIds = applies.getContent().stream().map(VolunteerApply::getVolunteerId)
86+
List<UUID> volunteerIds = applies.getContent().stream()
87+
.map(VolunteerApply::getVolunteerId)
9088
.toList();
9189

92-
List<VolunteerSimpleInfo> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(
93-
volunteerIds);
90+
List<VolunteerSimpleInfo> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(volunteerIds);
9491

9592
return volunteers.stream()
96-
.collect(Collectors.toMap(VolunteerSimpleInfo::id,
97-
volunteer -> volunteer));
93+
.collect(Collectors.toMap(VolunteerSimpleInfo::id, volunteer -> volunteer));
9894
}
9995

10096
}

src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryService.java

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

33
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
44
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
5-
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyResponseDto;
65
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
76
import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository;
87
import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
@@ -46,13 +45,6 @@ public VolunteerApplySummaryResponseDto getSummaryByRecruitId(Long recruitId) {
4645
return VolunteerApplySummaryResponseDto.from(applies);
4746
}
4847

49-
@Override
50-
public VolunteerApplyResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId) {
51-
VolunteerApply apply = getByRecruitIdAndVolunteerId(recruitId, volunteerId);
52-
53-
return VolunteerApplyResponseDto.from(apply);
54-
}
55-
5648
@Override
5749
public Page<VolunteerApply> getAllByRecruitId(Long recruitId, VolunteerApplySearchCondition condition) {
5850
return volunteerApplyRepository.findAllByRecruitId(recruitId, condition);

src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryFacadeUseCase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
44
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto;
5+
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto;
56
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto;
7+
import org.springframework.data.domain.Page;
68

79
import java.util.UUID;
8-
import org.springframework.data.domain.Page;
910

1011
public interface VolunteerApplyQueryFacadeUseCase {
1112

12-
Page<VolunteerApplyVolunteerInfoResponseDto> getVolunteerAppliesByRecruitIdAndCenterId(
13-
Long recruitId,
14-
UUID centerId, VolunteerApplySearchCondition condition);
13+
VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId);
14+
15+
Page<VolunteerApplyVolunteerInfoResponseDto> getVolunteerAppliesByRecruitIdAndCenterId(Long recruitId, UUID centerId, VolunteerApplySearchCondition condition);
1516

16-
Page<VolunteerApplyRecruitInfoResponseDto> getVolunteerAppliesByVolunteerId(UUID volunteerId,
17-
VolunteerApplySearchCondition condition);
17+
Page<VolunteerApplyRecruitInfoResponseDto> getVolunteerAppliesByVolunteerId(UUID volunteerId, VolunteerApplySearchCondition condition);
1818

1919
}

src/main/java/com/somemore/domains/volunteerapply/usecase/VolunteerApplyQueryUseCase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.somemore.domains.volunteerapply.domain.VolunteerApply;
44
import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition;
5-
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyResponseDto;
65
import com.somemore.domains.volunteerapply.dto.response.VolunteerApplySummaryResponseDto;
76
import org.springframework.data.domain.Page;
87

@@ -17,8 +16,6 @@ public interface VolunteerApplyQueryUseCase {
1716

1817
VolunteerApplySummaryResponseDto getSummaryByRecruitId(Long recruitId);
1918

20-
VolunteerApplyResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId);
21-
2219
List<UUID> getVolunteerIdsByRecruitIds(List<Long> recruitIds);
2320

2421
List<VolunteerApply> getAllByIds(List<Long> ids);

0 commit comments

Comments
 (0)