diff --git a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java deleted file mode 100644 index 07b12ca14..000000000 --- a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerSimpleInfoResponseDto.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.somemore.domains.volunteer.dto.response; - -import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.util.UUID; - -@Schema(description = "봉사자 간단 정보 응답 DTO") -@JsonNaming(SnakeCaseStrategy.class) -@Builder -public record VolunteerSimpleInfoResponseDto( - @Schema(description = "봉사자 ID", example = "f5a8779a-bcc9-4fc5-b8a1-7b2a383054a9") - UUID id, - @Schema(description = "봉사자 이름", example = "홍길동") - String name, - @Schema(description = "봉사자 닉네임", example = "gil-dong") - String nickname, - @Schema(description = "봉사자 이메일", example = "hong@example.com") - String email, - @Schema(description = "봉사자 이미지 URL", example = "https://example.com/images/hong.jpg") - String imgUrl -) { - - public static VolunteerSimpleInfoResponseDto from(VolunteerSimpleInfo volunteerSimpleInfo) { - return VolunteerSimpleInfoResponseDto.builder() - .id(volunteerSimpleInfo.id()) - .name(volunteerSimpleInfo.name()) - .nickname(volunteerSimpleInfo.nickname()) - .email(volunteerSimpleInfo.email()) - .imgUrl(volunteerSimpleInfo.imgUrl()) - .build(); - } -} diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java index 35b7e24b4..8bba19a62 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java @@ -2,7 +2,6 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import java.util.List; import java.util.Optional; @@ -24,8 +23,6 @@ public interface VolunteerRepository { List findAllByIds(List volunteerIds); - List findSimpleInfoByIds(List ids); - boolean existsByVolunteerId(UUID volunteerId); default boolean doesNotExistsByVolunteerId(UUID volunteerId) { diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java index 8ebc433d8..dce1d751a 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java @@ -5,10 +5,8 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.domains.volunteer.domain.QVolunteer; -import com.somemore.domains.volunteer.domain.QVolunteerDetail; import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -24,7 +22,6 @@ public class VolunteerRepositoryImpl implements VolunteerRepository { private final JPAQueryFactory queryFactory; private static final QVolunteer volunteer = QVolunteer.volunteer; - private static final QVolunteerDetail volunteerDetail = QVolunteerDetail.volunteerDetail; @Override public Volunteer save(Volunteer volunteer) { @@ -75,25 +72,6 @@ public List findAllByIds(List volunteerIds) { return volunteerJpaRepository.findAllByIdInAndDeletedFalse(volunteerIds); } - @Override - public List findSimpleInfoByIds(List ids) { - BooleanExpression exp = volunteer.id.in(ids) - .and(isNotDeleted()); - - return queryFactory - .select(Projections.constructor(VolunteerSimpleInfo.class, - volunteer.id, - volunteerDetail.name, - volunteer.nickname, - volunteerDetail.email, - volunteer.imgUrl, - volunteer.tier)) - .from(volunteer) - .join(volunteerDetail).on(volunteer.id.eq(volunteerDetail.volunteerId)) - .where(exp) - .fetch(); - } - private Optional findOne(BooleanExpression condition) { return Optional.ofNullable( diff --git a/src/main/java/com/somemore/domains/volunteer/repository/mapper/VolunteerSimpleInfo.java b/src/main/java/com/somemore/domains/volunteer/repository/mapper/VolunteerSimpleInfo.java deleted file mode 100644 index 3a0228bb2..000000000 --- a/src/main/java/com/somemore/domains/volunteer/repository/mapper/VolunteerSimpleInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.somemore.domains.volunteer.repository.mapper; - -import com.somemore.domains.volunteer.domain.Tier; - -import java.util.UUID; - -public record VolunteerSimpleInfo( - UUID id, - String name, - String nickname, - String email, - String imgUrl, - Tier tier -) { - -} diff --git a/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java b/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java index 607d2c753..d629e1443 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java @@ -2,12 +2,9 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; -import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; -import com.somemore.domains.volunteer.validator.VolunteerDetailAccessValidator; import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,8 +23,6 @@ public class VolunteerQueryService implements VolunteerQueryUseCase { private final VolunteerRepository volunteerRepository; - private final VolunteerDetailRepository volunteerDetailRepository; - private final VolunteerDetailAccessValidator volunteerDetailAccessValidator; @Override public UUID getVolunteerIdByOAuthId(String oAuthId) { @@ -58,11 +53,6 @@ public List getAllByIds(List volunteerIds) { return volunteerRepository.findAllByIds(volunteerIds); } - @Override - public List getVolunteerSimpleInfosByIds(List ids) { - return volunteerRepository.findSimpleInfoByIds(ids); - } - @Override public void validateVolunteerExists(UUID volunteerId) { if (volunteerRepository.doesNotExistsByVolunteerId(volunteerId)) { diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java b/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java index 587339328..a8f0613a3 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java +++ b/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java @@ -2,7 +2,6 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import java.util.List; import java.util.UUID; @@ -17,7 +16,5 @@ public interface VolunteerQueryUseCase { List getAllByIds(List volunteerIds); - List getVolunteerSimpleInfosByIds(List ids); - void validateVolunteerExists(UUID volunteerId); } diff --git a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java index fb2f82a94..87def61bf 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java +++ b/src/main/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiController.java @@ -8,7 +8,6 @@ import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; -import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.auth.annotation.RoleId; import com.somemore.global.common.response.ApiResponse; import com.somemore.global.exception.NoSuchElementException; @@ -90,7 +89,7 @@ public ApiResponse> getVolunteerAppli @Operation(summary = "지원자 리스트 조회", description = "특정 모집글에 대한 지원자 리스트를 조회합니다.") @GetMapping("/volunteer-applies/recruit-board/{recruitBoardId}") public ApiResponse> getVolunteerApplies( - @CurrentUser UUID centerId, + @RoleId UUID centerId, @PathVariable Long recruitBoardId, @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable, @RequestParam(required = false) Boolean attended, diff --git a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java index 7275b70cd..42b70e0a9 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java +++ b/src/main/java/com/somemore/domains/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java @@ -2,10 +2,9 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.somemore.domains.volunteer.dto.response.VolunteerSimpleInfoResponseDto; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; +import com.somemore.volunteer.dto.VolunteerInfoResponseDto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; @@ -19,8 +18,7 @@ public record VolunteerApplyVolunteerInfoResponseDto( Long id, @Schema(description = "모집글 ID", example = "2") Long recruitBoardId, - @Schema(description = "지원 상태", example = "WAITING", allowableValues = {"WAITING", - "APPROVED", "REJECTED"}) + @Schema(description = "지원 상태", example = "WAITING", allowableValues = {"WAITING", "APPROVED", "REJECTED"}) ApplyStatus status, @Schema(description = "참석 여부", example = "true") Boolean attend, @@ -28,16 +26,15 @@ public record VolunteerApplyVolunteerInfoResponseDto( LocalDateTime createdAt, @Schema(description = "지원 수정일", example = "2024-11-05T12:00:00") LocalDateTime updatedAt, - @Schema(description = "봉사자 정보", implementation = VolunteerSimpleInfoResponseDto.class) - VolunteerSimpleInfoResponseDto volunteer + @Schema(description = "봉사자 정보", implementation = VolunteerInfoResponseDto.class) + VolunteerInfoResponseDto volunteer ) { public static VolunteerApplyVolunteerInfoResponseDto of( VolunteerApply volunteerApply, - VolunteerSimpleInfo volunteerSimpleInfo + VolunteerInfoResponseDto volunteer ) { - VolunteerSimpleInfoResponseDto volunteer = VolunteerSimpleInfoResponseDto.from( - volunteerSimpleInfo); + return VolunteerApplyVolunteerInfoResponseDto.builder() .id(volunteerApply.getId()) .recruitBoardId(volunteerApply.getRecruitBoardId()) diff --git a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java index 2761b6229..9ce29cc54 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java +++ b/src/main/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepository.java @@ -27,11 +27,9 @@ public interface VolunteerApplyRepository { List findAllByRecruitId(Long recruitId); - Page findAllByRecruitId(Long recruitId, - VolunteerApplySearchCondition condition); + Page findAllByRecruitId(Long recruitId, VolunteerApplySearchCondition condition); - Page findAllByVolunteerId(UUID volunteerId, - VolunteerApplySearchCondition condition); + Page findAllByVolunteerId(UUID volunteerId, VolunteerApplySearchCondition condition); List findAllByIds(List ids); } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 6647b231a..5cde2c351 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -4,8 +4,6 @@ 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; @@ -13,6 +11,11 @@ import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.usecase.UserQueryUseCase; +import com.somemore.volunteer.dto.VolunteerInfoResponseDto; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; +import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; @@ -21,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.function.Function; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -30,13 +34,17 @@ public class VolunteerApplyQueryFacadeService implements VolunteerApplyQueryFaca private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; - private final VolunteerQueryUseCase volunteerQueryUseCase; + private final NEWVolunteerQueryUseCase volunteerQueryUseCase; + private final UserQueryUseCase userQueryUseCase; private final ReviewQueryUseCase reviewQueryUseCase; private final RecruitBoardValidator recruitBoardValidator; @Override - public VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAndVolunteerId(Long recruitId, UUID volunteerId) { - VolunteerApply apply = volunteerApplyQueryUseCase.getByRecruitIdAndVolunteerId(recruitId, volunteerId); + public VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAndVolunteerId( + Long recruitBoardId, + UUID volunteerId + ) { + VolunteerApply apply = volunteerApplyQueryUseCase.getByRecruitIdAndVolunteerId(recruitBoardId, volunteerId); boolean isReviewed = checkIfReviewed(apply); return VolunteerApplyWithReviewStatusResponseDto.of(apply, isReviewed); @@ -44,26 +52,34 @@ public VolunteerApplyWithReviewStatusResponseDto getVolunteerApplyByRecruitIdAnd @Override public Page getVolunteerAppliesByRecruitIdAndCenterId( - Long recruitId, UUID centerId, VolunteerApplySearchCondition condition) { - RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId); + Long recruitBoardId, + UUID centerId, + VolunteerApplySearchCondition condition + ) { + RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitBoardId); recruitBoardValidator.validateWriter(recruitBoard, centerId); - Page applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitId, condition); - Map volunteerMap = getVolunteerInfoMap(applies); + Page applies = volunteerApplyQueryUseCase.getAllByRecruitId(recruitBoardId, condition); + Map volunteerMapToVolunteerId = getVolunteerInfoMap(applies); - return applies.map( - apply -> VolunteerApplyVolunteerInfoResponseDto.of(apply, volunteerMap.getOrDefault(apply.getVolunteerId(), null))); + return applies.map(apply -> VolunteerApplyVolunteerInfoResponseDto.of( + apply, + volunteerMapToVolunteerId.get(apply.getVolunteerId()) + )); } @Override public Page getVolunteerAppliesByVolunteerId( - UUID volunteerId, VolunteerApplySearchCondition condition) { - + UUID volunteerId, + VolunteerApplySearchCondition condition + ) { Page applies = volunteerApplyQueryUseCase.getAllByVolunteerId(volunteerId, condition); - Map boardMap = getRecruitBoardMap(applies); + Map boardMapToId = getRecruitBoardMap(applies); - return applies.map( - apply -> VolunteerApplyRecruitInfoResponseDto.of(apply, boardMap.getOrDefault(apply.getRecruitBoardId(), null))); + return applies.map(apply -> VolunteerApplyRecruitInfoResponseDto.of( + apply, + boardMapToId.get(apply.getRecruitBoardId())) + ); } private boolean checkIfReviewed(VolunteerApply apply) { @@ -72,25 +88,49 @@ private boolean checkIfReviewed(VolunteerApply apply) { } private Map getRecruitBoardMap(Page applies) { + // 1. 모집글 ID 추출 List boardIds = applies.getContent().stream() .map(VolunteerApply::getRecruitBoardId) .toList(); + + // 2. 모집글 ID가 비어 있는 경우 빈 맵 반환 + if (boardIds.isEmpty()) { + return Map.of(); + } + + // 3. ID로 모집글 조회 List boards = recruitBoardQueryUseCase.getAllByIds(boardIds); + // 4. 조회된 모집글을 Map 변환 return boards.stream() - .collect(Collectors.toMap(RecruitBoard::getId, - board -> board)); + .collect(Collectors.toMap(RecruitBoard::getId, Function.identity())); } - private Map getVolunteerInfoMap(Page applies) { + private Map getVolunteerInfoMap(Page applies) { + // 1. Volunteer IDs 추출 List volunteerIds = applies.getContent().stream() .map(VolunteerApply::getVolunteerId) .toList(); - List volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(volunteerIds); - - return volunteers.stream() - .collect(Collectors.toMap(VolunteerSimpleInfo::id, volunteer -> volunteer)); + // 2. Volunteer 정보 조회 + List volunteerNicknameAndIds = + volunteerQueryUseCase.getVolunteerNicknameAndIdsByIds(volunteerIds); + + // 3. User 정보 조회 + Map userAttributesMap = + userQueryUseCase.getAllByUserIds( + volunteerNicknameAndIds.stream() + .map(VolunteerNicknameAndId::userId) + .toList() + ).stream() + .collect(Collectors.toMap(UserCommonAttribute::getUserId, user -> user)); + + // 4. VolunteerInfoResponseDto 생성 및 Map 변환 + return volunteerNicknameAndIds.stream() + .map(volunteer -> VolunteerInfoResponseDto.of( + volunteer, + userAttributesMap.get(volunteer.userId()) + )) + .collect(Collectors.toMap(VolunteerInfoResponseDto::id, Function.identity())); } - } diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java index 6511ff36d..bd44b0d36 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java @@ -3,6 +3,7 @@ import com.somemore.user.domain.UserCommonAttribute; import com.somemore.user.repository.usercommonattribute.record.UserProfileDto; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -15,4 +16,5 @@ public interface UserCommonAttributeRepository { Optional findIsCustomizedByUserId(UUID userId); Optional findUserProfileByUserId(UUID userId); + List findAllByUserIds(List userIds); } diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java index e34c8d1c6..43c454dc5 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java @@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -68,6 +69,15 @@ public Optional findUserProfileByUserId(UUID userId) { ); } + public List findAllByUserIds(List userIds) { + return queryFactory + .selectFrom(userCommonAttribute) + .where( + inUserIds(userIds), + isNotDeleted()) + .fetch(); + } + private static BooleanExpression eqUserId(UUID userId) { return userCommonAttribute.userId.eq(userId); } @@ -76,4 +86,8 @@ private static BooleanExpression isNotDeleted() { return userCommonAttribute.deleted.eq(false); } + private static BooleanExpression inUserIds(List userIds) { + return userCommonAttribute.userId.in(userIds); + } + } diff --git a/src/main/java/com/somemore/user/service/UserQueryService.java b/src/main/java/com/somemore/user/service/UserQueryService.java index af4391d39..ca0f0676b 100644 --- a/src/main/java/com/somemore/user/service/UserQueryService.java +++ b/src/main/java/com/somemore/user/service/UserQueryService.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.UUID; import static com.somemore.global.exception.ExceptionMessage.NOT_EXIST_USER; @@ -50,6 +51,11 @@ public UserCommonAttribute getCommonAttributeByUserId(UUID userId) { .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); } + @Override + public List getAllByUserIds(List userIds) { + return userCommonAttributeRepository.findAllByUserIds(userIds); + } + @Override public boolean getIsCustomizedByUserId(UUID userId) { return userCommonAttributeRepository.findIsCustomizedByUserId(userId) diff --git a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java index 0f69da41f..6f73c08b0 100644 --- a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java +++ b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java @@ -5,6 +5,7 @@ import com.somemore.user.domain.UserRole; import com.somemore.user.repository.usercommonattribute.record.UserProfileDto; +import java.util.List; import java.util.UUID; public interface UserQueryUseCase { @@ -17,6 +18,8 @@ public interface UserQueryUseCase { UserCommonAttribute getCommonAttributeByUserId(UUID userId); + List getAllByUserIds(List userIds); + boolean getIsCustomizedByUserId(UUID userId); boolean isDuplicateAccountId(String accountId); diff --git a/src/main/java/com/somemore/volunteer/dto/VolunteerInfoResponseDto.java b/src/main/java/com/somemore/volunteer/dto/VolunteerInfoResponseDto.java new file mode 100644 index 000000000..995a95c0f --- /dev/null +++ b/src/main/java/com/somemore/volunteer/dto/VolunteerInfoResponseDto.java @@ -0,0 +1,37 @@ +package com.somemore.volunteer.dto; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + +import java.util.UUID; + +@Schema(description = "봉사자 간단 정보 응답 DTO") +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@Builder +public record VolunteerInfoResponseDto( + @Schema(description = "봉사자 ID", example = "f5a8779a-bcc9-4fc5-b8a1-7b2a383054a9") + UUID id, + @Schema(description = "봉사자 이름", example = "홍길동") + String name, + @Schema(description = "봉사자 닉네임", example = "gil-dong") + String nickname, + @Schema(description = "봉사자 연락처", example = "010-1234-5678") + String contactNumber, + @Schema(description = "봉사자 이미지 URL", example = "https://example.com/images/hong.jpg") + String imgUrl +) { + + public static VolunteerInfoResponseDto of(VolunteerNicknameAndId volunteer, UserCommonAttribute userCommonAttribute) { + return VolunteerInfoResponseDto.builder() + .id(volunteer.id()) + .name(userCommonAttribute.getName()) + .nickname(volunteer.nickname()) + .contactNumber(userCommonAttribute.getContactNumber()) + .imgUrl(userCommonAttribute.getImgUrl()) + .build(); + } +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java index 82855ca1a..8d8c6174e 100644 --- a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java @@ -2,6 +2,7 @@ import com.somemore.volunteer.domain.NEWVolunteer; import com.somemore.volunteer.repository.record.VolunteerNickname; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; import java.util.List; import java.util.Optional; @@ -16,4 +17,6 @@ public interface NEWVolunteerRepository { Optional findByUserId(UUID userId); List findNicknamesByIds(List ids); + + List findVolunteerNicknameAndIdsByIds(List ids); } diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java index 50606e4cb..ca484c472 100644 --- a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java @@ -6,6 +6,7 @@ import com.somemore.volunteer.domain.NEWVolunteer; import com.somemore.volunteer.domain.QNEWVolunteer; import com.somemore.volunteer.repository.record.VolunteerNickname; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -60,7 +61,22 @@ public List findNicknamesByIds(List ids) { volunteer.nickname)) .from(volunteer) .where( - volunteer.id.in(ids), + inIds(ids), + isNotDeleted() + ) + .fetch(); + } + + @Override + public List findVolunteerNicknameAndIdsByIds(List ids) { + return queryFactory + .select(Projections.constructor(VolunteerNicknameAndId.class, + volunteer.id, + volunteer.userId, + volunteer.nickname)) + .from(volunteer) + .where( + inIds(ids), isNotDeleted() ) .fetch(); @@ -69,4 +85,8 @@ public List findNicknamesByIds(List ids) { private static BooleanExpression isNotDeleted() { return volunteer.deleted.eq(false); } + + private static BooleanExpression inIds(List ids) { + return volunteer.id.in(ids); + } } diff --git a/src/main/java/com/somemore/volunteer/repository/record/VolunteerNicknameAndId.java b/src/main/java/com/somemore/volunteer/repository/record/VolunteerNicknameAndId.java new file mode 100644 index 000000000..e5fe837c1 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/record/VolunteerNicknameAndId.java @@ -0,0 +1,10 @@ +package com.somemore.volunteer.repository.record; + +import java.util.UUID; + +public record VolunteerNicknameAndId( + UUID id, + UUID userId, + String nickname +) { +} diff --git a/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java b/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java index 18bf34bed..3b8f94bc5 100644 --- a/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java +++ b/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java @@ -4,11 +4,13 @@ import com.somemore.global.exception.NoSuchElementException; import com.somemore.volunteer.domain.NEWVolunteer; import com.somemore.volunteer.repository.NEWVolunteerRepository; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.UUID; @Service @@ -39,4 +41,9 @@ public UUID getUserIdById(UUID id) { public UUID getIdByUserId(UUID userId) { return getByUserId(userId).getId(); } + + @Override + public List getVolunteerNicknameAndIdsByIds(List ids) { + return volunteerRepository.findVolunteerNicknameAndIdsByIds(ids); + } } diff --git a/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java b/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java index b2070ab73..b5ea545b4 100644 --- a/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java +++ b/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java @@ -1,7 +1,9 @@ package com.somemore.volunteer.usecase; import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; +import java.util.List; import java.util.UUID; public interface NEWVolunteerQueryUseCase { @@ -13,4 +15,6 @@ public interface NEWVolunteerQueryUseCase { UUID getUserIdById(UUID id); UUID getIdByUserId(UUID userId); + + List getVolunteerNicknameAndIdsByIds(List ids); } diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java index cab4a1701..37579f2c5 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java @@ -1,10 +1,7 @@ package com.somemore.domains.volunteer.repository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.support.IntegrationTestSupport; import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.DisplayName; @@ -12,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -26,9 +22,6 @@ class VolunteerRepositoryImplTest extends IntegrationTestSupport { @Autowired private VolunteerRepository volunteerRepository; - @Autowired - private VolunteerDetailRepository volunteerDetailRepository; - @DisplayName("봉사자의 id로 닉네임을 조회한다.") @Test void findNicknameById() { @@ -160,27 +153,6 @@ void findAllByIds() { assertThat(volunteers).hasSize(3); } - @DisplayName("아이디 리스트로 봉사자 간단 정보를 조회할 수 있다.") - @Test - void findSimpleInfoByIds() { - // given - List ids = new ArrayList<>(); - - for (int i = 0; i < 4; i++) { - Volunteer volunteerTest = volunteerRepository.save(Volunteer.createDefault(NAVER, "naver")); - String name = "name" + i; - VolunteerRegisterRequestDto dto = createVolunteerRegisterRequestDto(name); - volunteerDetailRepository.save(VolunteerDetail.of(dto, volunteerTest.getId())); - ids.add(volunteerTest.getId()); - } - - // when - List simpleInfo = volunteerRepository.findSimpleInfoByIds(ids); - - // then - assertThat(simpleInfo).hasSize(4); - } - @DisplayName("봉사자 ID로 봉사자가 존재하는지 확인할 수 있다.") @Test void existsVolunteerById() { @@ -214,10 +186,4 @@ private void createVolunteerAndUpdateVolunteerStats(int i) { volunteerRepository.save(volunteer); } - private static VolunteerRegisterRequestDto createVolunteerRegisterRequestDto(String name) { - return new VolunteerRegisterRequestDto( - NAVER, "naver", name, "email", "M", "1111", "1111", - "010-0000-0000"); - } - } diff --git a/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java index 591a0b0b8..e1febfb46 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java @@ -1,12 +1,8 @@ package com.somemore.domains.volunteer.service; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; -import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.exception.BadRequestException; import com.somemore.support.IntegrationTestSupport; @@ -22,9 +18,7 @@ import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; @Transactional class VolunteerQueryServiceTest extends IntegrationTestSupport { @@ -35,9 +29,6 @@ class VolunteerQueryServiceTest extends IntegrationTestSupport { @Autowired private VolunteerRepository volunteerRepository; - @Autowired - private VolunteerDetailRepository volunteerDetailRepository; - final String oAuthId = "example-oauth-id"; final OAuthProvider oAuthProvider = OAuthProvider.NAVER; @@ -158,30 +149,6 @@ void findAllByIds() { assertThat(volunteers).hasSize(2); } - @DisplayName("아이디 리스트로 봉사자 간단 정보를 조회할 수 있다") - @Test - void getVolunteerSimpleInfosByIds() { - // given - Volunteer volunteer1 = Volunteer.createDefault(OAuthProvider.NAVER, "1234"); - Volunteer volunteer2 = Volunteer.createDefault(OAuthProvider.NAVER, "1234"); - - volunteerRepository.save(volunteer1); - volunteerRepository.save(volunteer2); - - VolunteerDetail detail1 = createVolunteerDetail(volunteer1.getId()); - VolunteerDetail detail2 = createVolunteerDetail(volunteer1.getId()); - - volunteerDetailRepository.save(detail1); - volunteerDetailRepository.save(detail2); - - // when - List volunteers = volunteerQueryService.getVolunteerSimpleInfosByIds( - List.of(volunteer1.getId(), volunteer2.getId(), UUID.randomUUID())); - - // then - assertThat(volunteers).hasSize(2); - } - @DisplayName("봉사자 ID로 봉사자가 존재하는지 확인할 수 있다 (service)") @Test void validateVolunteerExists() { @@ -209,21 +176,4 @@ void validateNonExistentVolunteer() { assertEquals(NOT_EXISTS_VOLUNTEER.getMessage(), exception.getMessage()); } - private static VolunteerDetail createVolunteerDetail(UUID volunteerId) { - - VolunteerRegisterRequestDto volunteerRegisterRequestDto = - new VolunteerRegisterRequestDto( - OAuthProvider.NAVER, - "example-oauth-id", - "making", - "making@example.com", - "male", - "06-08", - "1998", - "010-1234-5678" - ); - - return VolunteerDetail.of(volunteerRegisterRequestDto, volunteerId); - } - } diff --git a/src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiControllerTest.java b/src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiControllerTest.java index b812aea5e..f21b29af8 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiControllerTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/controller/VolunteerApplyQueryApiControllerTest.java @@ -119,7 +119,7 @@ void getSummaryByRecruitBoardId() throws Exception { @Test @DisplayName("지원자 리스트를 조회 성공 테스트") - @WithMockCustomUser(role = "CENTER") + @MockUser(role = "ROLE_CENTER") void getVolunteerApplies() throws Exception { // given Long recruitBoardId = 1L; diff --git a/src/test/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImplTest.java b/src/test/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImplTest.java index f2c9acdab..2d3ffbbaa 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImplTest.java @@ -18,8 +18,7 @@ import java.util.Optional; import java.util.UUID; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED; +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.*; import static org.assertj.core.api.Assertions.assertThat; @Transactional @@ -30,12 +29,11 @@ class VolunteerApplyRepositoryImplTest extends IntegrationTestSupport { @BeforeEach void setUp() { - // Given for (int i = 1; i <= 15; i++) { VolunteerApply apply = VolunteerApply.builder() .volunteerId(UUID.randomUUID()) .recruitBoardId(1L) - .status(ApplyStatus.WAITING) + .status(WAITING) .attended(false) .build(); volunteerApplyRepository.save(apply); @@ -55,44 +53,41 @@ void setUp() { @DisplayName("봉사 신청 저장 및 조회") @Test void saveAndFindById() { - // Given + // given VolunteerApply newApply = createApply(UUID.randomUUID(), 1L); - VolunteerApply savedApply = volunteerApplyRepository.save(newApply); + volunteerApplyRepository.save(newApply); - // When - Optional foundApply = volunteerApplyRepository.findById(savedApply.getId()); + // when + Optional foundApply = volunteerApplyRepository.findById(newApply.getId()); - // Then + // then assertThat(foundApply).isPresent(); - assertThat(foundApply.get().getId()).isEqualTo(savedApply.getId()); + assertThat(foundApply.get().getId()).isEqualTo(newApply.getId()); assertThat(foundApply.get().getStatus()).isEqualTo(APPROVED); } @DisplayName("모집글 ID 리스트로 봉사자 ID 리스트 조회") @Test void findVolunteerIdsByRecruitIds() { - // When - List volunteerIds = volunteerApplyRepository.findVolunteerIdsByRecruitIds( - List.of(1L, 2L)); + // when + List volunteerIds = volunteerApplyRepository.findVolunteerIdsByRecruitIds(List.of(1L, 2L)); - // Then + // then assertThat(volunteerIds).hasSize(20); } @DisplayName("모집글 ID로 페이징된 봉사 신청 조회") @Test void findAllByRecruitId() { - // Given + // given PageRequest firstPage = PageRequest.of(0, 10, Sort.by(Sort.Order.asc("created_at"))); PageRequest secondPage = PageRequest.of(1, 10, Sort.by(Sort.Order.asc("created_at"))); - // When - Page firstPageResult = volunteerApplyRepository.findAllByRecruitId(1L, - firstPage); - Page secondPageResult = volunteerApplyRepository.findAllByRecruitId(1L, - secondPage); + // when + Page firstPageResult = volunteerApplyRepository.findAllByRecruitId(1L, firstPage); + Page secondPageResult = volunteerApplyRepository.findAllByRecruitId(1L, secondPage); - // Then + // then assertThat(firstPageResult.getContent()).hasSize(10); assertThat(firstPageResult.getTotalElements()).isEqualTo(15); assertThat(firstPageResult.getTotalPages()).isEqualTo(2); @@ -115,8 +110,7 @@ void findByRecruitIdAndVolunteerId() { volunteerApplyRepository.save(newApply); // when - Optional findApply = volunteerApplyRepository.findByRecruitIdAndVolunteerId( - recruitId, volunteerId); + Optional findApply = volunteerApplyRepository.findByRecruitIdAndVolunteerId(recruitId, volunteerId); // then assertThat(findApply).isPresent(); @@ -133,8 +127,7 @@ void existsByRecruitIdAndVolunteerId() { volunteerApplyRepository.save(newApply); // when - boolean result = volunteerApplyRepository.existsByRecruitIdAndVolunteerId(recruitId, - volunteerId); + boolean result = volunteerApplyRepository.existsByRecruitIdAndVolunteerId(recruitId, volunteerId); // then assertThat(result).isTrue(); @@ -173,13 +166,12 @@ void findAllByRecruitIdWithCondition() { .build(); // when - Page applies = volunteerApplyRepository.findAllByRecruitId(recruitBoardId, - condition); + Page applies = volunteerApplyRepository.findAllByRecruitId(recruitBoardId, condition); // then assertThat(applies.getTotalElements()).isEqualTo(3); assertThat(applies.getContent()) - .allMatch(apply -> apply.getStatus() == APPROVED && !apply.getAttended()); + .allMatch(apply -> apply.getStatus() == status && apply.getAttended() == attended); } @@ -187,14 +179,14 @@ void findAllByRecruitIdWithCondition() { @Test void findAllByVolunteerId() { // given - UUID centerId = UUID.randomUUID(); + UUID volunteerId = UUID.randomUUID(); ApplyStatus status = APPROVED; Boolean attended = false; - volunteerApplyRepository.save(createApply(centerId, status, attended)); - volunteerApplyRepository.save(createApply(centerId, status, attended)); - volunteerApplyRepository.save(createApply(centerId, status, attended)); - volunteerApplyRepository.save(createApply(centerId, REJECTED, !attended)); + volunteerApplyRepository.save(createApply(volunteerId, status, attended)); + volunteerApplyRepository.save(createApply(volunteerId, status, attended)); + volunteerApplyRepository.save(createApply(volunteerId, status, attended)); + volunteerApplyRepository.save(createApply(volunteerId, REJECTED, !attended)); VolunteerApplySearchCondition condition = VolunteerApplySearchCondition.builder() .status(status) @@ -203,13 +195,12 @@ void findAllByVolunteerId() { .build(); // when - Page applies = volunteerApplyRepository.findAllByVolunteerId(centerId, - condition); + Page applies = volunteerApplyRepository.findAllByVolunteerId(volunteerId, condition); // then assertThat(applies.getTotalElements()).isEqualTo(3); assertThat(applies.getContent()) - .allMatch(apply -> apply.getStatus() == APPROVED && !apply.getAttended()); + .allMatch(apply -> apply.getStatus() == status && apply.getAttended() == attended); } @@ -250,8 +241,7 @@ private static VolunteerApply createApply(UUID volunteerId, Long recruitId) { .build(); } - private static VolunteerApply createApply(Long recruitId, ApplyStatus status, - Boolean attended) { + private static VolunteerApply createApply(Long recruitId, ApplyStatus status, Boolean attended) { return VolunteerApply.builder() .volunteerId(UUID.randomUUID()) .recruitBoardId(recruitId) @@ -260,10 +250,9 @@ private static VolunteerApply createApply(Long recruitId, ApplyStatus status, .build(); } - private static VolunteerApply createApply(UUID centerId, ApplyStatus status, - Boolean attended) { + private static VolunteerApply createApply(UUID volunteerId, ApplyStatus status, Boolean attended) { return VolunteerApply.builder() - .volunteerId(centerId) + .volunteerId(volunteerId) .recruitBoardId(101L) .status(status) .attended(attended) diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyStatusChangeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyStatusChangeServiceTest.java index 1a686f7c9..230430ac7 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyStatusChangeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyStatusChangeServiceTest.java @@ -91,12 +91,7 @@ void applyWhenDuplicate() { recruitBoardRepository.save(board); UUID volunteerId = UUID.randomUUID(); - VolunteerApply apply = VolunteerApply.builder() - .volunteerId(volunteerId) - .recruitBoardId(board.getId()) - .status(WAITING) - .attended(false) - .build(); + VolunteerApply apply = createVolunteerApply(volunteerId, board.getId()); volunteerApplyRepository.save(apply); VolunteerApplyCreateRequestDto dto = VolunteerApplyCreateRequestDto.builder() @@ -111,7 +106,16 @@ void applyWhenDuplicate() { .hasMessage(DUPLICATE_APPLICATION.getMessage()); } - private static RecruitBoard createRecruitBoard(RecruitStatus status) { + private VolunteerApply createVolunteerApply(UUID volunteerId, Long recruitBoardId) { + return VolunteerApply.builder() + .volunteerId(volunteerId) + .recruitBoardId(recruitBoardId) + .status(WAITING) + .attended(false) + .build(); + } + + private RecruitBoard createRecruitBoard(RecruitStatus status) { LocalDateTime startDateTime = createStartDateTime(); LocalDateTime endDateTime = startDateTime.plusHours(2); diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java index b45349475..cabb91317 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java @@ -1,19 +1,9 @@ package com.somemore.domains.volunteerapply.service; -import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; -import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; -import static org.assertj.core.api.Assertions.assertThat; - import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.repository.ReviewRepository; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; -import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; -import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto; @@ -21,8 +11,11 @@ import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyWithReviewStatusResponseDto; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.support.IntegrationTestSupport; -import java.util.List; -import java.util.UUID; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.NEWVolunteerRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -31,6 +24,13 @@ import org.springframework.data.domain.Pageable; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.UUID; + +import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; +import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; +import static org.assertj.core.api.Assertions.assertThat; + @Transactional class VolunteerApplyQueryFacadeServiceTest extends IntegrationTestSupport { @@ -39,9 +39,9 @@ class VolunteerApplyQueryFacadeServiceTest extends IntegrationTestSupport { @Autowired private RecruitBoardRepository recruitBoardRepository; @Autowired - private VolunteerRepository volunteerRepository; + private NEWVolunteerRepository volunteerRepository; @Autowired - private VolunteerDetailRepository volunteerDetailRepository; + private UserCommonAttributeRepository userCommonAttributeRepository; @Autowired private VolunteerApplyRepository volunteerApplyRepository; @Autowired @@ -60,8 +60,8 @@ void getVolunteerApplyByRecruitIdAndVolunteerId() { reviewRepository.save(review); // when - VolunteerApplyWithReviewStatusResponseDto dto = volunteerApplyQueryFacadeService.getVolunteerApplyByRecruitIdAndVolunteerId( - recruitBoardId, volunteerId); + VolunteerApplyWithReviewStatusResponseDto dto = + volunteerApplyQueryFacadeService.getVolunteerApplyByRecruitIdAndVolunteerId(recruitBoardId, volunteerId); // then assertThat(dto.recruitBoardId()).isEqualTo(recruitBoardId); @@ -77,18 +77,21 @@ void getVolunteerAppliesByRecruitIdAndCenterId() { RecruitBoard board = createRecruitBoard(centerId); recruitBoardRepository.save(board); - Volunteer volunteer1 = Volunteer.createDefault(NAVER, "naver"); - Volunteer volunteer2 = Volunteer.createDefault(NAVER, "naver"); - volunteerRepository.save(volunteer1); - volunteerRepository.save(volunteer2); + UUID userIdOne = UUID.randomUUID(); + UUID userIdTwo = UUID.randomUUID(); - VolunteerDetail volunteerDetail1 = createVolunteerDetail(volunteer1.getId()); - VolunteerDetail volunteerDetail2 = createVolunteerDetail(volunteer2.getId()); - volunteerDetailRepository.save(volunteerDetail1); - volunteerDetailRepository.save(volunteerDetail2); + UserCommonAttribute userOne = createUserCommonAttribute(userIdOne); + UserCommonAttribute userTwo = createUserCommonAttribute(userIdTwo); + userCommonAttributeRepository.save(userOne); + userCommonAttributeRepository.save(userTwo); - VolunteerApply apply1 = createApply(volunteer1.getId(), board.getId()); - VolunteerApply apply2 = createApply(volunteer2.getId(), board.getId()); + NEWVolunteer volunteerOne = createVolunteer(userIdOne); + NEWVolunteer volunteerTwo = createVolunteer(userIdTwo); + volunteerRepository.save(volunteerOne); + volunteerRepository.save(volunteerTwo); + + VolunteerApply apply1 = createApply(volunteerOne.getId(), board.getId()); + VolunteerApply apply2 = createApply(volunteerTwo.getId(), board.getId()); volunteerApplyRepository.saveAll(List.of(apply1, apply2)); VolunteerApplySearchCondition condition = VolunteerApplySearchCondition.builder() @@ -96,9 +99,8 @@ void getVolunteerAppliesByRecruitIdAndCenterId() { .build(); // when - Page result = volunteerApplyQueryFacadeService.getVolunteerAppliesByRecruitIdAndCenterId( - board.getId(), - centerId, condition); + Page result = + volunteerApplyQueryFacadeService.getVolunteerAppliesByRecruitIdAndCenterId(board.getId(), centerId, condition); // then assertThat(result).hasSize(2); @@ -142,23 +144,6 @@ private static Review createReview(Long volunteerApplyId, UUID volunteerId) { .build(); } - private static VolunteerDetail createVolunteerDetail(UUID volunteerId) { - - VolunteerRegisterRequestDto volunteerRegisterRequestDto = - new VolunteerRegisterRequestDto( - NAVER, - "example-oauth-id", - "making", - "making@example.com", - "male", - "06-08", - "1998", - "010-1234-5678" - ); - - return VolunteerDetail.of(volunteerRegisterRequestDto, volunteerId); - } - private static VolunteerApply createApply(UUID volunteerId, Long recruitId) { return VolunteerApply.builder() .volunteerId(volunteerId) @@ -168,6 +153,14 @@ private static VolunteerApply createApply(UUID volunteerId, Long recruitId) { .build(); } + private static NEWVolunteer createVolunteer(UUID userIdOne) { + return NEWVolunteer.createDefault(userIdOne); + } + + private static UserCommonAttribute createUserCommonAttribute(UUID userIdOne) { + return UserCommonAttribute.createDefault(userIdOne, UserRole.VOLUNTEER); + } + private Pageable getPageable() { return PageRequest.of(0, 4); } diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java index fda71de8c..5b2057e77 100644 --- a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -11,8 +11,10 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Optional; +import java.util.List; import java.util.UUID; +import static com.somemore.user.domain.UserRole.VOLUNTEER; import static org.assertj.core.api.Assertions.assertThat; @Transactional @@ -26,7 +28,7 @@ class UserCommonAttributeRepositoryImplTest extends IntegrationTestSupport { void saveUserCommonAttribute() { // given UUID userId = UUID.randomUUID(); - UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.VOLUNTEER); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, VOLUNTEER); // when UserCommonAttribute savedUserCommonAttribute = userCommonAttributeRepository.save(userCommonAttribute); @@ -64,4 +66,33 @@ void findUserProfileByUserId() { assertThat(userProfile.imgUrl()).isEqualTo(userCommonAttribute.getImgUrl()); assertThat(userProfile.introduce()).isEqualTo(userCommonAttribute.getIntroduce()); } + + @DisplayName("유저 아이디(userId) 리스트로 유저 공통 속성 리스트를 조회할 수 있다.") + @Test + void findAllByUserIds() { + // given + UserCommonAttribute one = createUserCommonAttribute(); + UserCommonAttribute two = createUserCommonAttribute(); + UserCommonAttribute three = createUserCommonAttribute(); + + userCommonAttributeRepository.save(one); + userCommonAttributeRepository.save(two); + userCommonAttributeRepository.save(three); + + List userIds = List.of(one.getUserId(), two.getUserId(), three.getUserId()); + + // when + List result = userCommonAttributeRepository.findAllByUserIds(userIds); + + // then + assertThat(result).hasSize(3); + assertThat(result) + .extracting(UserCommonAttribute::getUserId) + .containsExactlyInAnyOrder(one.getUserId(), two.getUserId(), three.getUserId()); + + } + + private UserCommonAttribute createUserCommonAttribute() { + return UserCommonAttribute.createDefault(UUID.randomUUID(), VOLUNTEER); + } } diff --git a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java index d7522570f..d68759c97 100644 --- a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java +++ b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java @@ -17,6 +17,9 @@ import java.util.UUID; +import java.util.List; + +import static com.somemore.user.domain.UserRole.VOLUNTEER; import static org.assertj.core.api.Assertions.assertThat; @Transactional @@ -39,7 +42,7 @@ void setup() { UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); user = userRepository.save(User.of(userAuthInfo, UserRole.VOLUNTEER)); - userCommonAttribute = userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId(),UserRole.VOLUNTEER)); + userCommonAttribute = userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId(), UserRole.VOLUNTEER)); } @@ -120,7 +123,7 @@ void getUserProfileByUserId() { UUID userId = UUID.randomUUID(); UserRole role = UserRole.VOLUNTEER; - UserCommonAttribute userCommonAttribute1 = UserCommonAttribute.createDefault(userId,role); + UserCommonAttribute userCommonAttribute1 = UserCommonAttribute.createDefault(userId, role); userCommonAttributeRepository.save(userCommonAttribute1); //when @@ -135,4 +138,33 @@ void getUserProfileByUserId() { assertThat(result.imgUrl()).isEqualTo(userCommonAttribute1.getImgUrl()); assertThat(result.introduce()).isEqualTo(userCommonAttribute1.getIntroduce()); } + + @DisplayName("유저 아이디(userId) 리스트로 유저 공통 속성 리스트를 조회할 수 있다.") + @Test + void findAllByUserIds() { + // given + UserCommonAttribute one = createUserCommonAttribute(); + UserCommonAttribute two = createUserCommonAttribute(); + UserCommonAttribute three = createUserCommonAttribute(); + + userCommonAttributeRepository.save(one); + userCommonAttributeRepository.save(two); + userCommonAttributeRepository.save(three); + + List userIds = List.of(one.getUserId(), two.getUserId(), three.getUserId()); + + // when + List result = userQueryService.getAllByUserIds(userIds); + + // then + assertThat(result).hasSize(3); + assertThat(result) + .extracting(UserCommonAttribute::getUserId) + .containsExactlyInAnyOrder(one.getUserId(), two.getUserId(), three.getUserId()); + + } + + private UserCommonAttribute createUserCommonAttribute() { + return UserCommonAttribute.createDefault(UUID.randomUUID(), VOLUNTEER); + } } diff --git a/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java index 16205a5be..873bb1466 100644 --- a/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java +++ b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java @@ -3,6 +3,7 @@ import com.somemore.support.IntegrationTestSupport; import com.somemore.volunteer.domain.NEWVolunteer; import com.somemore.volunteer.repository.record.VolunteerNickname; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -68,4 +69,33 @@ void findNicknamesByIds() { volunteer2.getNickname(), volunteer3.getNickname()); } + + @DisplayName("아이디 리스트로 VolunteerNicknameAndId 리스트를 조회할 수 있다.") + @Test + void findVolunteerNicknameAndIdsByIds() { + // given + UUID userId1 = UUID.randomUUID(); + UUID userId2 = UUID.randomUUID(); + UUID userId3 = UUID.randomUUID(); + + NEWVolunteer volunteer1 = NEWVolunteer.createDefault(userId1); + NEWVolunteer volunteer2 = NEWVolunteer.createDefault(userId2); + NEWVolunteer volunteer3 = NEWVolunteer.createDefault(userId3); + + volunteerRepository.save(volunteer1); + volunteerRepository.save(volunteer2); + volunteerRepository.save(volunteer3); + + List ids = List.of(volunteer1.getId(), volunteer2.getId(), volunteer3.getId()); + + // when + List nicknames = volunteerRepository.findVolunteerNicknameAndIdsByIds(ids); + + // then + assertThat(nicknames).extracting(VolunteerNicknameAndId::userId) + .containsExactlyInAnyOrder( + volunteer1.getUserId(), + volunteer2.getUserId(), + volunteer3.getUserId()); + } } diff --git a/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java b/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java index 2793d9040..109e3296f 100644 --- a/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java +++ b/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java @@ -3,12 +3,14 @@ import com.somemore.support.IntegrationTestSupport; import com.somemore.volunteer.domain.NEWVolunteer; import com.somemore.volunteer.repository.NEWVolunteerRepository; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -63,4 +65,33 @@ void getUserIdById() { assertThat(foundUserId).isEqualTo(volunteer.getUserId()); } -} \ No newline at end of file + + @DisplayName("아이디 리스트로 VolunteerNicknameAndId 리스트를 조회할 수 있다.") + @Test + void findVolunteerNicknameAndIdsByIds() { + // given + UUID userId1 = UUID.randomUUID(); + UUID userId2 = UUID.randomUUID(); + UUID userId3 = UUID.randomUUID(); + + NEWVolunteer volunteer1 = NEWVolunteer.createDefault(userId1); + NEWVolunteer volunteer2 = NEWVolunteer.createDefault(userId2); + NEWVolunteer volunteer3 = NEWVolunteer.createDefault(userId3); + + volunteerRepository.save(volunteer1); + volunteerRepository.save(volunteer2); + volunteerRepository.save(volunteer3); + + List ids = List.of(volunteer1.getId(), volunteer2.getId(), volunteer3.getId()); + + // when + List nicknames = volunteerQueryService.getVolunteerNicknameAndIdsByIds(ids); + + // then + assertThat(nicknames).extracting(VolunteerNicknameAndId::userId) + .containsExactlyInAnyOrder( + volunteer1.getUserId(), + volunteer2.getUserId(), + volunteer3.getUserId()); + } +}