-
Notifications
You must be signed in to change notification settings - Fork 1
[FEATURE] 특정 모집글 봉사자 지원 조회 필드 추가 #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| package com.somemore.domains.volunteerapply.service; | ||
|
|
||
| import com.somemore.domains.recruitboard.domain.RecruitBoard; | ||
| import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; | ||
| import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; | ||
| import com.somemore.domains.review.usecase.ReviewQueryUseCase; | ||
| import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; | ||
| import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; | ||
| import com.somemore.domains.volunteerapply.domain.VolunteerApply; | ||
| import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; | ||
| import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto; | ||
| import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; | ||
| import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto; | ||
| import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase; | ||
| import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; | ||
| import com.somemore.global.exception.BadRequestException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.stereotype.Service; | ||
|
|
@@ -21,8 +23,6 @@ | |
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| @Service | ||
|
|
@@ -31,52 +31,49 @@ public class VolunteerApplyQueryFacadeService implements VolunteerApplyQueryFaca | |
| private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; | ||
| private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; | ||
| private final VolunteerQueryUseCase volunteerQueryUseCase; | ||
| private final ReviewQueryUseCase reviewQueryUseCase; | ||
| private final RecruitBoardValidator recruitBoardValidator; | ||
|
|
||
| @Override | ||
| public VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId) { | ||
| VolunteerApply apply = volunteerApplyQueryUseCase.getByRecruitIdAndVolunteerId(recruitId, volunteerId); | ||
| boolean isReviewed = checkIfReviewed(apply); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰가 작성되어있을 때, 체크한다 이런 느낌인가요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음.. 봉사 지원과 리뷰의 관계를 생각해봤을때, 봉사지원(상태가 APPROVED이고 참석여부가 TRUE일때)일때, 리뷰가 있을수도(작성했을 수도)없을 수도 있어서 위 메서드로 빼놨습니다. 즉, 리뷰 작성 가능성이 있을때, ReviewQueryUseCase로 조회하도록 했습니다. |
||
|
|
||
| return VolunteerApplyWithReviewStatusResponseDto.of(apply, isReviewed); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<VolunteerApplyVolunteerInfoResponseDto> getVolunteerAppliesByRecruitIdAndCenterId( | ||
| Long recruitId, UUID centerId, VolunteerApplySearchCondition condition) { | ||
| validateAuthorization(recruitId, centerId); | ||
|
|
||
| Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitId, | ||
| condition); | ||
| RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId); | ||
| recruitBoardValidator.validateWriter(recruitBoard, centerId); | ||
|
|
||
| Map<UUID, VolunteerSimpleInfo> volunteerMap = getVolunteerInfoMap( | ||
| applies); | ||
| Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitId, condition); | ||
| Map<UUID, VolunteerSimpleInfo> volunteerMap = getVolunteerInfoMap(applies); | ||
|
|
||
| return applies.map( | ||
| apply -> VolunteerApplyVolunteerInfoResponseDto.of( | ||
| apply, | ||
| volunteerMap.getOrDefault(apply.getVolunteerId(), null) | ||
| )); | ||
| apply -> VolunteerApplyVolunteerInfoResponseDto.of(apply, volunteerMap.getOrDefault(apply.getVolunteerId(), null))); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<VolunteerApplyRecruitInfoResponseDto> getVolunteerAppliesByVolunteerId( | ||
| UUID volunteerId, VolunteerApplySearchCondition condition) { | ||
|
|
||
| Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByVolunteerId(volunteerId, | ||
| condition); | ||
|
|
||
| Page<VolunteerApply> applies = volunteerApplyQueryUseCase.getAllByVolunteerId(volunteerId, condition); | ||
| Map<Long, RecruitBoard> boardMap = getRecruitBoardMap(applies); | ||
|
|
||
| return applies.map( | ||
| apply -> VolunteerApplyRecruitInfoResponseDto.of( | ||
| apply, | ||
| boardMap.getOrDefault(apply.getRecruitBoardId(), null) | ||
| )); | ||
| apply -> VolunteerApplyRecruitInfoResponseDto.of(apply, boardMap.getOrDefault(apply.getRecruitBoardId(), null))); | ||
| } | ||
|
|
||
| private void validateAuthorization(Long recruitId, UUID centerId) { | ||
| RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId); | ||
| if (recruitBoard.isWriter(centerId)) { | ||
| return; | ||
| } | ||
|
|
||
| throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); | ||
| private boolean checkIfReviewed(VolunteerApply apply) { | ||
| return apply.isVolunteerActivityCompleted() | ||
| && reviewQueryUseCase.existsByVolunteerApplyId(apply.getId()); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @m-a-king 반대로 전자가 false면 후자는 실행을 안하니까 조회 한번을 아낄수 있어요
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다. 이해했습니다~ |
||
| } | ||
|
|
||
| private Map<Long, RecruitBoard> getRecruitBoardMap(Page<VolunteerApply> applies) { | ||
| List<Long> boardIds = applies.getContent().stream().map(VolunteerApply::getRecruitBoardId) | ||
| List<Long> boardIds = applies.getContent().stream() | ||
| .map(VolunteerApply::getRecruitBoardId) | ||
| .toList(); | ||
| List<RecruitBoard> boards = recruitBoardQueryUseCase.getAllByIds(boardIds); | ||
|
|
||
|
|
@@ -86,15 +83,14 @@ private Map<Long, RecruitBoard> getRecruitBoardMap(Page<VolunteerApply> applies) | |
| } | ||
|
|
||
| private Map<UUID, VolunteerSimpleInfo> getVolunteerInfoMap(Page<VolunteerApply> applies) { | ||
| List<UUID> volunteerIds = applies.getContent().stream().map(VolunteerApply::getVolunteerId) | ||
| List<UUID> volunteerIds = applies.getContent().stream() | ||
| .map(VolunteerApply::getVolunteerId) | ||
| .toList(); | ||
|
|
||
| List<VolunteerSimpleInfo> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds( | ||
| volunteerIds); | ||
| List<VolunteerSimpleInfo> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(volunteerIds); | ||
|
|
||
| return volunteers.stream() | ||
| .collect(Collectors.toMap(VolunteerSimpleInfo::id, | ||
| volunteer -> volunteer)); | ||
| .collect(Collectors.toMap(VolunteerSimpleInfo::id, volunteer -> volunteer)); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 이겼군요...