11package com .somemore .domains .volunteerapply .service ;
22
33import com .somemore .domains .recruitboard .domain .RecruitBoard ;
4+ import com .somemore .domains .recruitboard .service .validator .RecruitBoardValidator ;
45import com .somemore .domains .recruitboard .usecase .RecruitBoardQueryUseCase ;
6+ import com .somemore .domains .review .usecase .ReviewQueryUseCase ;
57import com .somemore .domains .volunteer .repository .mapper .VolunteerSimpleInfo ;
68import com .somemore .domains .volunteer .usecase .VolunteerQueryUseCase ;
79import com .somemore .domains .volunteerapply .domain .VolunteerApply ;
810import com .somemore .domains .volunteerapply .dto .condition .VolunteerApplySearchCondition ;
911import com .somemore .domains .volunteerapply .dto .response .VolunteerApplyRecruitInfoResponseDto ;
12+ import com .somemore .domains .volunteerapply .dto .response .VolunteerApplyWithReviewStatusResponseDto ;
1013import com .somemore .domains .volunteerapply .dto .response .VolunteerApplyVolunteerInfoResponseDto ;
1114import com .somemore .domains .volunteerapply .usecase .VolunteerApplyQueryFacadeUseCase ;
1215import com .somemore .domains .volunteerapply .usecase .VolunteerApplyQueryUseCase ;
13- import com .somemore .global .exception .BadRequestException ;
1416import lombok .RequiredArgsConstructor ;
1517import org .springframework .data .domain .Page ;
1618import org .springframework .stereotype .Service ;
2123import java .util .UUID ;
2224import 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}
0 commit comments