diff --git a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerProfileResponseDto.java b/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerProfileResponseDto.java deleted file mode 100644 index c87ec9f28..000000000 --- a/src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerProfileResponseDto.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.somemore.domains.volunteer.dto.response; - -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.domain.VolunteerDetail; -import io.swagger.v3.oas.annotations.media.Schema; - -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -@Schema(description = "봉사자 프로필 응답 DTO") -public record VolunteerProfileResponseDto( - @Schema(description = "봉사자 ID", example = "123e4567-e89b-12d3-a456-426614174000") - String volunteerId, - - @Schema(description = "봉사자 닉네임", example = "길동이") - String nickname, - - @Schema(description = "봉사자 이미지 URL", example = "http://example.com/image.jpg") - String imgUrl, - - @Schema(description = "봉사자 소개", example = "안녕하세요! 봉사 활동을 좋아합니다.") - String introduce, - - @Schema(description = "봉사자 등급", example = "RED") - String tier, - - @Schema(description = "총 봉사 시간", example = "120") - Integer totalVolunteerHours, - - @Schema(description = "총 봉사 횟수", example = "20") - Integer totalVolunteerCount, - - @Schema(description = "봉사자 상세 정보", implementation = Detail.class) - Detail detail -) { - - public static VolunteerProfileResponseDto from( - Volunteer volunteer, - VolunteerDetail volunteerDetail - ) { - return new VolunteerProfileResponseDto( - volunteer.getId().toString(), - volunteer.getNickname(), - volunteer.getImgUrl(), - volunteer.getIntroduce(), - volunteer.getTier().name(), - volunteer.getTotalVolunteerHours(), - volunteer.getTotalVolunteerCount(), - Detail.from(volunteerDetail) - ); - } - - public static VolunteerProfileResponseDto from( - Volunteer volunteer - ) { - return new VolunteerProfileResponseDto( - volunteer.getId().toString(), - volunteer.getNickname(), - volunteer.getImgUrl(), - volunteer.getIntroduce(), - volunteer.getTier().name(), - volunteer.getTotalVolunteerHours(), - volunteer.getTotalVolunteerCount(), - null - ); - } - - @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) - @Schema(description = "봉사자 상세 프로필") - private record Detail( - @Schema(description = "이름", example = "홍길동") - String name, - - @Schema(description = "이메일", example = "honggildong@example.com") - String email, - - @Schema(description = "성별", example = "MALE") - String gender, - - @Schema(description = "생년월일", example = "1990-01-01") - String birthDate, - - @Schema(description = "연락처", example = "010-1234-5678") - String contactNumber - ) { - public static Detail from( - VolunteerDetail volunteerDetail - ) { - return new Detail( - volunteerDetail.getName(), - volunteerDetail.getEmail(), - volunteerDetail.getGender().name(), - volunteerDetail.getBirthDate(), - volunteerDetail.getContactNumber() - ); - } - } -} 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 36ef44f17..607d2c753 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java @@ -1,8 +1,6 @@ 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.response.VolunteerProfileResponseDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; @@ -31,34 +29,6 @@ public class VolunteerQueryService implements VolunteerQueryUseCase { private final VolunteerDetailRepository volunteerDetailRepository; private final VolunteerDetailAccessValidator volunteerDetailAccessValidator; - @Override - public VolunteerProfileResponseDto getMyProfile(UUID volunteerId) { - - return VolunteerProfileResponseDto.from( - findVolunteer(volunteerId), - findVolunteerDetail(volunteerId) - ); - } - - @Override - public VolunteerProfileResponseDto getVolunteerProfile(UUID volunteerId) { - - return VolunteerProfileResponseDto.from( - findVolunteer(volunteerId) - ); - } - - @Override - public VolunteerProfileResponseDto getVolunteerDetailedProfile(UUID volunteerId, - UUID centerId) { - volunteerDetailAccessValidator.validateByCenterId(centerId, volunteerId); - - return VolunteerProfileResponseDto.from( - findVolunteer(volunteerId), - findVolunteerDetail(volunteerId) - ); - } - @Override public UUID getVolunteerIdByOAuthId(String oAuthId) { return volunteerRepository.findByOauthId(oAuthId) @@ -99,15 +69,4 @@ public void validateVolunteerExists(UUID volunteerId) { throw new BadRequestException(NOT_EXISTS_VOLUNTEER.getMessage()); } } - - private Volunteer findVolunteer(UUID volunteerId) { - return volunteerRepository.findById(volunteerId) - .orElseThrow(() -> new BadRequestException(NOT_EXISTS_VOLUNTEER)); - } - - private VolunteerDetail findVolunteerDetail(UUID volunteerId) { - return volunteerDetailRepository.findByVolunteerId(volunteerId) - .orElseThrow(() -> new BadRequestException(NOT_EXISTS_VOLUNTEER)); - } - } 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 d23ad6ffb..587339328 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java +++ b/src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java @@ -1,7 +1,6 @@ package com.somemore.domains.volunteer.usecase; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; @@ -10,12 +9,6 @@ public interface VolunteerQueryUseCase { - VolunteerProfileResponseDto getMyProfile(UUID volunteerId); - - VolunteerProfileResponseDto getVolunteerProfile(UUID volunteerId); - - VolunteerProfileResponseDto getVolunteerDetailedProfile(UUID volunteerId, UUID centerId); - UUID getVolunteerIdByOAuthId(String oAuthId); String getNicknameById(UUID id); diff --git a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java b/src/main/java/com/somemore/volunteer/controller/VolunteerProfileQueryController.java similarity index 53% rename from src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java rename to src/main/java/com/somemore/volunteer/controller/VolunteerProfileQueryController.java index 1fdad7ed5..ec9d1573d 100644 --- a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerProfileQueryController.java +++ b/src/main/java/com/somemore/volunteer/controller/VolunteerProfileQueryController.java @@ -1,9 +1,9 @@ -package com.somemore.domains.volunteer.controller; +package com.somemore.volunteer.controller; -import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto; -import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; -import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.auth.annotation.UserId; import com.somemore.global.common.response.ApiResponse; +import com.somemore.volunteer.dto.VolunteerProfileResponseDto; +import com.somemore.volunteer.usecase.GetVolunteerProfileUseCase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -23,43 +23,38 @@ @Tag(name = "GET Volunteer Profile", description = "봉사자 조회") public class VolunteerProfileQueryController { - private final VolunteerQueryUseCase volunteerQueryUseCase; + private final GetVolunteerProfileUseCase getVolunteerProfileUseCase; @Operation(summary = "본인 상세 프로필 조회", description = "현재 로그인된 사용자의 상세 프로필을 조회합니다.") @Secured("ROLE_VOLUNTEER") @GetMapping("/me") public ApiResponse getMyProfile( - @CurrentUser UUID volunteerId) { - + @UserId UUID userId) { return ApiResponse.ok( 200, - volunteerQueryUseCase.getMyProfile(volunteerId), - "본인 상세 프로필 조회 성공"); + getVolunteerProfileUseCase.getProfileByUserId(userId), + "본인 프로필 조회 성공"); } - @GetMapping("/{volunteerId}") - @Operation(summary = "타인 프로필 조회", description = "특정 봉사자의 프로필을 조회합니다. 상세 정보는 포함되지 않습니다.") - public ApiResponse getVolunteerProfile( - @PathVariable UUID volunteerId) { - + @GetMapping("/user-id/{userId}") + @Operation(summary = "타인 프로필 조회 (유저 아이디)", description = "유저 아이디로 특정 봉사자의 상세 프로필을 조회합니다.") + public ApiResponse getVolunteerProfileByUserId( + @PathVariable UUID userId) { return ApiResponse.ok( 200, - volunteerQueryUseCase.getVolunteerProfile(volunteerId), + getVolunteerProfileUseCase.getProfileByUserId(userId), "타인 프로필 조회 성공" ); } - @GetMapping("/{volunteerId}/detailed") - @Secured("ROLE_CENTER") - @Operation(summary = "지원자 상세 프로필 조회", description = "기관이 작성한 모집 글에 지원한 봉사자의 상세 프로필을 조회합니다.") - public ApiResponse getVolunteerDetailedProfile( - @PathVariable UUID volunteerId, - @CurrentUser UUID centerId) { - + @GetMapping("/volunteer-id/{volunteerId}") + @Operation(summary = "타인 프로필 조회 (봉사자 아아디)", description = "봉사자 아이디특정 봉사자의 상세 프로필을 조회합니다.") + public ApiResponse getVolunteerProfileByVolunteerId( + @PathVariable UUID volunteerId) { return ApiResponse.ok( 200, - volunteerQueryUseCase.getVolunteerDetailedProfile(volunteerId, centerId), - "지원자 상세 프로필 조회 성공" + getVolunteerProfileUseCase.getProfileByVolunteerId(volunteerId), + "타인 프로필 조회 성공" ); } } diff --git a/src/main/java/com/somemore/volunteer/dto/VolunteerProfileResponseDto.java b/src/main/java/com/somemore/volunteer/dto/VolunteerProfileResponseDto.java new file mode 100644 index 000000000..003606ab6 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/dto/VolunteerProfileResponseDto.java @@ -0,0 +1,76 @@ +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.domain.NEWVolunteer; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@Schema(description = "봉사자 프로필 응답 DTO") +@Builder +public record VolunteerProfileResponseDto( + + @Schema(description = "봉사자 닉네임", example = "길동이") + String nickname, + + @Schema(description = "봉사자 등급", example = "RED") + String tier, + + @Schema(description = "봉사자 이미지 URL", example = "http://example.com/image.jpg") + String imgUrl, + + @Schema(description = "봉사자 소개", example = "안녕하세요! 봉사 활동을 좋아합니다.") + String introduce, + + @Schema(description = "총 봉사 시간", example = "120") + Integer totalVolunteerHours, + + @Schema(description = "총 봉사 횟수", example = "20") + Integer totalVolunteerCount, + + @Schema(description = "봉사자 상세 정보", implementation = Detail.class) + Detail detail +) { + + public static VolunteerProfileResponseDto of( + NEWVolunteer volunteer, + UserCommonAttribute commonAttribute + ) { + return VolunteerProfileResponseDto.builder() + .nickname(volunteer.getNickname()) + .tier(volunteer.getTier().name()) + .imgUrl(commonAttribute.getImgUrl()) + .introduce(commonAttribute.getIntroduce()) + .totalVolunteerHours(volunteer.getTotalVolunteerHours()) + .totalVolunteerCount(volunteer.getTotalVolunteerCount()) + .detail(Detail.of(volunteer, commonAttribute)) + .build(); + } + + @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) + @Schema(description = "봉사자 상세 프로필") + @Builder + public record Detail( + @Schema(description = "이름", example = "홍길동") + String name, + + @Schema(description = "성별", example = "MALE") + String gender, + + @Schema(description = "연락처", example = "010-1234-5678") + String contactNumber + ) { + public static Detail of( + NEWVolunteer volunteer, + UserCommonAttribute commonAttribute + ) { + return Detail.builder() + .name(commonAttribute.getName()) + .gender(volunteer.getGender().name()) + .contactNumber(commonAttribute.getContactNumber()) + .build(); + } + } +} diff --git a/src/main/java/com/somemore/volunteer/service/GetVolunteerProfileService.java b/src/main/java/com/somemore/volunteer/service/GetVolunteerProfileService.java new file mode 100644 index 000000000..dbb32d047 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/service/GetVolunteerProfileService.java @@ -0,0 +1,36 @@ +package com.somemore.volunteer.service; + +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.usecase.UserQueryUseCase; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.dto.VolunteerProfileResponseDto; +import com.somemore.volunteer.usecase.GetVolunteerProfileUseCase; +import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class GetVolunteerProfileService implements GetVolunteerProfileUseCase { + + private final NEWVolunteerQueryUseCase volunteerQueryUseCase; + private final UserQueryUseCase userQueryUseCase; + + @Override + public VolunteerProfileResponseDto getProfileByUserId(UUID userId) { + NEWVolunteer volunteer = volunteerQueryUseCase.getByUserId(userId); + UserCommonAttribute commonAttribute = userQueryUseCase.getCommonAttributeByUserId(userId); + + return VolunteerProfileResponseDto.of(volunteer, commonAttribute); + } + + @Override + public VolunteerProfileResponseDto getProfileByVolunteerId(UUID volunteerId) { + UUID userId = volunteerQueryUseCase.getUserIdById(volunteerId); + return getProfileByUserId(userId); + } +} diff --git a/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java b/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java index ad4a10218..18bf34bed 100644 --- a/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java +++ b/src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java @@ -18,12 +18,23 @@ public class NEWVolunteerQueryService implements NEWVolunteerQueryUseCase { private final NEWVolunteerRepository volunteerRepository; + @Override + public NEWVolunteer getById(UUID id) { + return volunteerRepository.findById(id) + .orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_VOLUNTEER)); + } + @Override public NEWVolunteer getByUserId(UUID userId) { return volunteerRepository.findByUserId(userId) .orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_VOLUNTEER)); } + @Override + public UUID getUserIdById(UUID id) { + return getById(id).getUserId(); + } + @Override public UUID getIdByUserId(UUID userId) { return getByUserId(userId).getId(); diff --git a/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java b/src/main/java/com/somemore/volunteer/service/RegisterNEWVolunteerService.java similarity index 77% rename from src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java rename to src/main/java/com/somemore/volunteer/service/RegisterNEWVolunteerService.java index b6cfd061e..abbefc83d 100644 --- a/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java +++ b/src/main/java/com/somemore/volunteer/service/RegisterNEWVolunteerService.java @@ -12,14 +12,14 @@ @Service @RequiredArgsConstructor @Transactional -public class NEWRegisterVolunteerService implements NEWRegisterVolunteerUseCase { +public class RegisterNEWVolunteerService implements NEWRegisterVolunteerUseCase { - private final NEWVolunteerRepository NEWVolunteerRepository; + private final NEWVolunteerRepository volunteerRepository; @Override public void register(UUID userId) { NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); - NEWVolunteerRepository.save(volunteer); + volunteerRepository.save(volunteer); } } diff --git a/src/main/java/com/somemore/volunteer/usecase/GetVolunteerProfileUseCase.java b/src/main/java/com/somemore/volunteer/usecase/GetVolunteerProfileUseCase.java new file mode 100644 index 000000000..c91441137 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/usecase/GetVolunteerProfileUseCase.java @@ -0,0 +1,12 @@ +package com.somemore.volunteer.usecase; + +import com.somemore.volunteer.dto.VolunteerProfileResponseDto; + +import java.util.UUID; + +public interface GetVolunteerProfileUseCase { + + VolunteerProfileResponseDto getProfileByUserId(UUID userId); + + VolunteerProfileResponseDto getProfileByVolunteerId(UUID volunteerId); +} diff --git a/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java b/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java index 1a3730b04..b2070ab73 100644 --- a/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java +++ b/src/main/java/com/somemore/volunteer/usecase/NEWVolunteerQueryUseCase.java @@ -6,7 +6,11 @@ public interface NEWVolunteerQueryUseCase { + NEWVolunteer getById(UUID id); + NEWVolunteer getByUserId(UUID userId); + UUID getUserIdById(UUID id); + UUID getIdByUserId(UUID userId); } 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 d34db6a9b..591a0b0b8 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java @@ -3,7 +3,6 @@ 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.VolunteerProfileResponseDto; import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; @@ -21,10 +20,11 @@ import static com.somemore.domains.volunteer.domain.Volunteer.createDefault; import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_DETAIL; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @Transactional class VolunteerQueryServiceTest extends IntegrationTestSupport { @@ -95,69 +95,6 @@ void throwExceptionWhenNicknameNotFound() { .hasMessage(NOT_EXISTS_VOLUNTEER.getMessage()); } - @DisplayName("내 프로필 조회 성공") - @Test - void getMyProfile() { - // given - Volunteer volunteer = createDefault(oAuthProvider, oAuthId); - volunteerRepository.save(volunteer); - UUID volunteerId = volunteer.getId(); - - VolunteerDetail volunteerDetail = createVolunteerDetail(volunteerId); - volunteerDetailRepository.save(volunteerDetail); - - // when - VolunteerProfileResponseDto response = volunteerQueryService.getMyProfile(volunteerId); - - // then - assertThat(response).isNotNull(); - assertThat(response.volunteerId()).isEqualTo(volunteerId.toString()); - assertThat(response.nickname()).isEqualTo(volunteer.getNickname()); - } - - @DisplayName("봉사자 프로필 조회 성공") - @Test - void getVolunteerProfile() { - // given - Volunteer volunteer = createDefault(oAuthProvider, oAuthId); - volunteerRepository.save(volunteer); - UUID volunteerId = volunteer.getId(); - - VolunteerDetail volunteerDetail = createVolunteerDetail(volunteerId); - volunteerDetailRepository.save(volunteerDetail); - - // when - VolunteerProfileResponseDto response = volunteerQueryService.getVolunteerProfile( - volunteerId); - - // then - assertThat(response).isNotNull(); - assertThat(response.volunteerId()).isEqualTo(volunteerId.toString()); - assertThat(response.nickname()).isEqualTo(volunteer.getNickname()); - assertThat(response.detail()).isNull(); - } - - @DisplayName("권한이 없는 기관의 봉사자 상세 프로필 조회 실패") - @Test - void getVolunteerDetailedProfile() { - // given - UUID centerId = UUID.randomUUID(); - - Volunteer volunteer = createDefault(oAuthProvider, oAuthId); - volunteerRepository.save(volunteer); - UUID volunteerId = volunteer.getId(); - - VolunteerDetail volunteerDetail = createVolunteerDetail(volunteerId); - volunteerDetailRepository.save(volunteerDetail); - - // when - // then - assertThatThrownBy( - () -> volunteerQueryService.getVolunteerDetailedProfile(volunteerId, centerId)) - .isInstanceOf(BadRequestException.class) - .hasMessage(UNAUTHORIZED_VOLUNTEER_DETAIL.getMessage()); - } - @DisplayName("봉사 시간 기준 상위 4명의 랭킹을 조회한다.") @Test void getRankingByHours() { diff --git a/src/test/java/com/somemore/volunteer/service/GetVolunteerProfileServiceTest.java b/src/test/java/com/somemore/volunteer/service/GetVolunteerProfileServiceTest.java new file mode 100644 index 000000000..ba3c712fa --- /dev/null +++ b/src/test/java/com/somemore/volunteer/service/GetVolunteerProfileServiceTest.java @@ -0,0 +1,92 @@ +package com.somemore.volunteer.service; + +import com.somemore.global.exception.NoSuchElementException; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import com.somemore.user.usecase.UserQueryUseCase; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.dto.VolunteerProfileResponseDto; +import com.somemore.volunteer.repository.NEWVolunteerRepository; +import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; +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.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@Transactional +class GetVolunteerProfileServiceTest extends IntegrationTestSupport { + + @Autowired + private GetVolunteerProfileService getVolunteerProfileService; + + @Autowired + private NEWVolunteerQueryUseCase volunteerQueryUseCase; + + @Autowired + private UserQueryUseCase userQueryUseCase; + + @Autowired + private NEWVolunteerRepository volunteerRepository; + + @Autowired + private UserCommonAttributeRepository userCommonAttributeRepository; + + @Test + @DisplayName("성공적으로 봉사자 프로필을 조회할 수 있다") + void testGetVolunteerProfileSuccess() { + // given + UUID userId = UUID.randomUUID(); + NEWVolunteer expectedVolunteer = NEWVolunteer.createDefault(userId); + UserCommonAttribute expectedCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.VOLUNTEER); + volunteerRepository.save(expectedVolunteer); + userCommonAttributeRepository.save(expectedCommonAttribute); + + // when + VolunteerProfileResponseDto volunteerProfileResponseDto = getVolunteerProfileService.getProfileByUserId(userId); + + // then + assertThat(volunteerProfileResponseDto) + .isNotNull(); + assertThat(volunteerProfileResponseDto.nickname()) + .isEqualTo(expectedVolunteer.getNickname()); + assertThat(volunteerProfileResponseDto.tier()) + .isEqualTo(expectedVolunteer.getTier().name()); + assertThat(volunteerProfileResponseDto.imgUrl()) + .isEqualTo(expectedCommonAttribute.getImgUrl()); + assertThat(volunteerProfileResponseDto.introduce()) + .isEqualTo(expectedCommonAttribute.getIntroduce()); + assertThat(volunteerProfileResponseDto.totalVolunteerHours()) + .isEqualTo(expectedVolunteer.getTotalVolunteerHours()); + assertThat(volunteerProfileResponseDto.totalVolunteerCount()) + .isEqualTo(expectedVolunteer.getTotalVolunteerCount()); + + VolunteerProfileResponseDto.Detail detail = volunteerProfileResponseDto.detail(); + + assertThat(detail.name()) + .isEqualTo(expectedCommonAttribute.getName()); + assertThat(detail.gender()) + .isEqualTo(expectedVolunteer.getGender().name()); + assertThat(detail.contactNumber()) + .isEqualTo(expectedCommonAttribute.getContactNumber()); + } + + @Test + @DisplayName("존재하지 않는 봉사자 프로필 조회 시 예외를 발생시킨다") + void testGetVolunteerProfileNotFound() { + // given + UUID nonExistUserId = UUID.randomUUID(); + + // when + // then + assertThatThrownBy(() -> volunteerQueryUseCase.getByUserId(nonExistUserId)) + .isInstanceOf(NoSuchElementException.class); + } + +} \ No newline at end of file diff --git a/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java b/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java index 5c12de054..2793d9040 100644 --- a/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java +++ b/src/test/java/com/somemore/volunteer/service/NEWVolunteerQueryServiceTest.java @@ -33,7 +33,15 @@ void setUp() { } @Test - @DisplayName("사용자 ID로 봉사자를 조회한다") + @DisplayName("봉사자 ID로 봉사자를 조회한다") + void getById() { + NEWVolunteer foundVolunteer = volunteerQueryService.getById(volunteer.getId()); + + assertThat(foundVolunteer).isEqualTo(volunteer); + } + + @Test + @DisplayName("유저 ID로 봉사자를 조회한다") void getByUserId() { NEWVolunteer foundVolunteer = volunteerQueryService.getByUserId(userId); @@ -41,10 +49,18 @@ void getByUserId() { } @Test - @DisplayName("사용자 ID로 봉사자 ID를 조회한다") + @DisplayName("유저 ID로 봉사자 ID를 조회한다") void getIdByUserId() { UUID foundVolunteerId = volunteerQueryService.getIdByUserId(userId); assertThat(foundVolunteerId).isEqualTo(volunteer.getId()); } + + @Test + @DisplayName("봉사자 ID로 유저 ID를 조회한다") + void getUserIdById() { + UUID foundUserId = volunteerQueryService.getUserIdById(volunteer.getId()); + + assertThat(foundUserId).isEqualTo(volunteer.getUserId()); + } } \ No newline at end of file diff --git a/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java b/src/test/java/com/somemore/volunteer/service/RegisterNEWVolunteerServiceTest.java similarity index 89% rename from src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java rename to src/test/java/com/somemore/volunteer/service/RegisterNEWVolunteerServiceTest.java index 49da8a8eb..1ffb343d8 100644 --- a/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java +++ b/src/test/java/com/somemore/volunteer/service/RegisterNEWVolunteerServiceTest.java @@ -14,10 +14,10 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class NEWRegisterVolunteerServiceTest extends IntegrationTestSupport { +class RegisterNEWVolunteerServiceTest extends IntegrationTestSupport { @Autowired - private NEWRegisterVolunteerService registerVolunteerService; + private RegisterNEWVolunteerService registerVolunteerService; @Autowired private NEWVolunteerRepository volunteerRepository;