Skip to content

Commit 3cdb3b9

Browse files
authored
[FEATURE] 봉사자 프로필 조회 기능 추가 (#323)
* refactor(volunteer): 프로필 관련 미사용 코드 제거 - 사용되지 않는 기존의 VolunteerProfile 조회 메서드 및 테스트 제거 - VolunteerQueryUseCase와 VolunteerQueryServiceTest에서 불필요한 import 삭제 * feat(volunteer): 봉사자 프로필 조회 기능 추가 - VolunteerProfileResponseDto 생성 및 봉사자 DTO 정의 - GetVolunteerProfileUseCase 인터페이스 및 구현체 추가 - VolunteerProfileQueryController에서 프로필 조회 기능 수정 및 서비스 연동 - 관련 도메인, 유즈케이스 의존성 업데이트 * test(volunteer): 유저 아이디 기준 봉사자 프로필 조회 서비스 테스트 추가 - 성공적인 봉사자 프로필 조회 테스트 케이스 작성 - 존재하지 않는 봉사자 프로필 조회 시 예외 발생 테스트 포함 * refactor(service): 클래스명 리팩터링 - NEWRegisterVolunteerService를 RegisterNEWVolunteerService로 클래스명 변경 - 관련 테스트 클래스 및 필드명도 동일하게 수정 * feat(volunteer): 프로필 조회 로직 및 메서드 확장 구현 - 봉사자 ID를 기반으로 프로필 조회 기능 추가 - VolunteerQueryUseCase에 `getById` 및 `getUserIdById` 메서드 확장 - VolunteerProfileQueryController에 새로운 엔드포인트 추가: - `GET /user-id/{userId}`: 유저 ID 기반 프로필 조회 - `GET /volunteer-id/{volunteerId}`: 봉사자 ID 기반 프로필 조회 - 기존 `getProfile` 메서드를 `getProfileByUserId`로 변경 - `getProfileByVolunteerId` 메서드 추가하여 봉사자 ID 활용 로직 연결 * test(service): 봉사자 조회 관련 테스트 케이스 추가 - 봉사자 ID로 봉사자를 조회하는 테스트 추가 - 봉사자 ID로 유저 ID를 조회하는 테스트 추가 - 기존 테스트의 DisplayName 수정 및 표현 개선 * refactor(service): 불필요한 코드 제거 및 변수명 변경 - `findVolunteer`와 `findVolunteerDetail` 메서드 제거 - 사용되지 않는 메서드로 판단하여 삭제 - `NEWVolunteerRepository` 변수명을 `volunteerRepository`로 변경 - 가독성 및 네이밍 일관성 강화
1 parent e56b93c commit 3cdb3b9

14 files changed

+276
-243
lines changed

src/main/java/com/somemore/domains/volunteer/dto/response/VolunteerProfileResponseDto.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/main/java/com/somemore/domains/volunteer/service/VolunteerQueryService.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.somemore.domains.volunteer.service;
22

33
import com.somemore.domains.volunteer.domain.Volunteer;
4-
import com.somemore.domains.volunteer.domain.VolunteerDetail;
5-
import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto;
64
import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto;
75
import com.somemore.domains.volunteer.repository.VolunteerDetailRepository;
86
import com.somemore.domains.volunteer.repository.VolunteerRepository;
@@ -31,34 +29,6 @@ public class VolunteerQueryService implements VolunteerQueryUseCase {
3129
private final VolunteerDetailRepository volunteerDetailRepository;
3230
private final VolunteerDetailAccessValidator volunteerDetailAccessValidator;
3331

34-
@Override
35-
public VolunteerProfileResponseDto getMyProfile(UUID volunteerId) {
36-
37-
return VolunteerProfileResponseDto.from(
38-
findVolunteer(volunteerId),
39-
findVolunteerDetail(volunteerId)
40-
);
41-
}
42-
43-
@Override
44-
public VolunteerProfileResponseDto getVolunteerProfile(UUID volunteerId) {
45-
46-
return VolunteerProfileResponseDto.from(
47-
findVolunteer(volunteerId)
48-
);
49-
}
50-
51-
@Override
52-
public VolunteerProfileResponseDto getVolunteerDetailedProfile(UUID volunteerId,
53-
UUID centerId) {
54-
volunteerDetailAccessValidator.validateByCenterId(centerId, volunteerId);
55-
56-
return VolunteerProfileResponseDto.from(
57-
findVolunteer(volunteerId),
58-
findVolunteerDetail(volunteerId)
59-
);
60-
}
61-
6232
@Override
6333
public UUID getVolunteerIdByOAuthId(String oAuthId) {
6434
return volunteerRepository.findByOauthId(oAuthId)
@@ -99,15 +69,4 @@ public void validateVolunteerExists(UUID volunteerId) {
9969
throw new BadRequestException(NOT_EXISTS_VOLUNTEER.getMessage());
10070
}
10171
}
102-
103-
private Volunteer findVolunteer(UUID volunteerId) {
104-
return volunteerRepository.findById(volunteerId)
105-
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_VOLUNTEER));
106-
}
107-
108-
private VolunteerDetail findVolunteerDetail(UUID volunteerId) {
109-
return volunteerDetailRepository.findByVolunteerId(volunteerId)
110-
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_VOLUNTEER));
111-
}
112-
11372
}

src/main/java/com/somemore/domains/volunteer/usecase/VolunteerQueryUseCase.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.somemore.domains.volunteer.usecase;
22

33
import com.somemore.domains.volunteer.domain.Volunteer;
4-
import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto;
54
import com.somemore.domains.volunteer.dto.response.VolunteerRankingResponseDto;
65
import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo;
76

@@ -10,12 +9,6 @@
109

1110
public interface VolunteerQueryUseCase {
1211

13-
VolunteerProfileResponseDto getMyProfile(UUID volunteerId);
14-
15-
VolunteerProfileResponseDto getVolunteerProfile(UUID volunteerId);
16-
17-
VolunteerProfileResponseDto getVolunteerDetailedProfile(UUID volunteerId, UUID centerId);
18-
1912
UUID getVolunteerIdByOAuthId(String oAuthId);
2013

2114
String getNicknameById(UUID id);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.somemore.domains.volunteer.controller;
1+
package com.somemore.volunteer.controller;
22

3-
import com.somemore.domains.volunteer.dto.response.VolunteerProfileResponseDto;
4-
import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase;
5-
import com.somemore.global.auth.annotation.CurrentUser;
3+
import com.somemore.global.auth.annotation.UserId;
64
import com.somemore.global.common.response.ApiResponse;
5+
import com.somemore.volunteer.dto.VolunteerProfileResponseDto;
6+
import com.somemore.volunteer.usecase.GetVolunteerProfileUseCase;
77
import io.swagger.v3.oas.annotations.Operation;
88
import io.swagger.v3.oas.annotations.tags.Tag;
99
import lombok.RequiredArgsConstructor;
@@ -23,43 +23,38 @@
2323
@Tag(name = "GET Volunteer Profile", description = "봉사자 조회")
2424
public class VolunteerProfileQueryController {
2525

26-
private final VolunteerQueryUseCase volunteerQueryUseCase;
26+
private final GetVolunteerProfileUseCase getVolunteerProfileUseCase;
2727

2828
@Operation(summary = "본인 상세 프로필 조회", description = "현재 로그인된 사용자의 상세 프로필을 조회합니다.")
2929
@Secured("ROLE_VOLUNTEER")
3030
@GetMapping("/me")
3131
public ApiResponse<VolunteerProfileResponseDto> getMyProfile(
32-
@CurrentUser UUID volunteerId) {
33-
32+
@UserId UUID userId) {
3433
return ApiResponse.ok(
3534
200,
36-
volunteerQueryUseCase.getMyProfile(volunteerId),
37-
"본인 상세 프로필 조회 성공");
35+
getVolunteerProfileUseCase.getProfileByUserId(userId),
36+
"본인 프로필 조회 성공");
3837
}
3938

40-
@GetMapping("/{volunteerId}")
41-
@Operation(summary = "타인 프로필 조회", description = "특정 봉사자의 프로필을 조회합니다. 상세 정보는 포함되지 않습니다.")
42-
public ApiResponse<VolunteerProfileResponseDto> getVolunteerProfile(
43-
@PathVariable UUID volunteerId) {
44-
39+
@GetMapping("/user-id/{userId}")
40+
@Operation(summary = "타인 프로필 조회 (유저 아이디)", description = "유저 아이디로 특정 봉사자의 상세 프로필을 조회합니다.")
41+
public ApiResponse<VolunteerProfileResponseDto> getVolunteerProfileByUserId(
42+
@PathVariable UUID userId) {
4543
return ApiResponse.ok(
4644
200,
47-
volunteerQueryUseCase.getVolunteerProfile(volunteerId),
45+
getVolunteerProfileUseCase.getProfileByUserId(userId),
4846
"타인 프로필 조회 성공"
4947
);
5048
}
5149

52-
@GetMapping("/{volunteerId}/detailed")
53-
@Secured("ROLE_CENTER")
54-
@Operation(summary = "지원자 상세 프로필 조회", description = "기관이 작성한 모집 글에 지원한 봉사자의 상세 프로필을 조회합니다.")
55-
public ApiResponse<VolunteerProfileResponseDto> getVolunteerDetailedProfile(
56-
@PathVariable UUID volunteerId,
57-
@CurrentUser UUID centerId) {
58-
50+
@GetMapping("/volunteer-id/{volunteerId}")
51+
@Operation(summary = "타인 프로필 조회 (봉사자 아아디)", description = "봉사자 아이디특정 봉사자의 상세 프로필을 조회합니다.")
52+
public ApiResponse<VolunteerProfileResponseDto> getVolunteerProfileByVolunteerId(
53+
@PathVariable UUID volunteerId) {
5954
return ApiResponse.ok(
6055
200,
61-
volunteerQueryUseCase.getVolunteerDetailedProfile(volunteerId, centerId),
62-
"지원자 상세 프로필 조회 성공"
56+
getVolunteerProfileUseCase.getProfileByVolunteerId(volunteerId),
57+
"타인 프로필 조회 성공"
6358
);
6459
}
6560
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.somemore.volunteer.dto;
2+
3+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
4+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
5+
import com.somemore.user.domain.UserCommonAttribute;
6+
import com.somemore.volunteer.domain.NEWVolunteer;
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
import lombok.Builder;
9+
10+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
11+
@Schema(description = "봉사자 프로필 응답 DTO")
12+
@Builder
13+
public record VolunteerProfileResponseDto(
14+
15+
@Schema(description = "봉사자 닉네임", example = "길동이")
16+
String nickname,
17+
18+
@Schema(description = "봉사자 등급", example = "RED")
19+
String tier,
20+
21+
@Schema(description = "봉사자 이미지 URL", example = "http://example.com/image.jpg")
22+
String imgUrl,
23+
24+
@Schema(description = "봉사자 소개", example = "안녕하세요! 봉사 활동을 좋아합니다.")
25+
String introduce,
26+
27+
@Schema(description = "총 봉사 시간", example = "120")
28+
Integer totalVolunteerHours,
29+
30+
@Schema(description = "총 봉사 횟수", example = "20")
31+
Integer totalVolunteerCount,
32+
33+
@Schema(description = "봉사자 상세 정보", implementation = Detail.class)
34+
Detail detail
35+
) {
36+
37+
public static VolunteerProfileResponseDto of(
38+
NEWVolunteer volunteer,
39+
UserCommonAttribute commonAttribute
40+
) {
41+
return VolunteerProfileResponseDto.builder()
42+
.nickname(volunteer.getNickname())
43+
.tier(volunteer.getTier().name())
44+
.imgUrl(commonAttribute.getImgUrl())
45+
.introduce(commonAttribute.getIntroduce())
46+
.totalVolunteerHours(volunteer.getTotalVolunteerHours())
47+
.totalVolunteerCount(volunteer.getTotalVolunteerCount())
48+
.detail(Detail.of(volunteer, commonAttribute))
49+
.build();
50+
}
51+
52+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
53+
@Schema(description = "봉사자 상세 프로필")
54+
@Builder
55+
public record Detail(
56+
@Schema(description = "이름", example = "홍길동")
57+
String name,
58+
59+
@Schema(description = "성별", example = "MALE")
60+
String gender,
61+
62+
@Schema(description = "연락처", example = "010-1234-5678")
63+
String contactNumber
64+
) {
65+
public static Detail of(
66+
NEWVolunteer volunteer,
67+
UserCommonAttribute commonAttribute
68+
) {
69+
return Detail.builder()
70+
.name(commonAttribute.getName())
71+
.gender(volunteer.getGender().name())
72+
.contactNumber(commonAttribute.getContactNumber())
73+
.build();
74+
}
75+
}
76+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.somemore.volunteer.service;
2+
3+
import com.somemore.user.domain.UserCommonAttribute;
4+
import com.somemore.user.usecase.UserQueryUseCase;
5+
import com.somemore.volunteer.domain.NEWVolunteer;
6+
import com.somemore.volunteer.dto.VolunteerProfileResponseDto;
7+
import com.somemore.volunteer.usecase.GetVolunteerProfileUseCase;
8+
import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase;
9+
import lombok.RequiredArgsConstructor;
10+
import org.springframework.stereotype.Service;
11+
import org.springframework.transaction.annotation.Transactional;
12+
13+
import java.util.UUID;
14+
15+
@Service
16+
@RequiredArgsConstructor
17+
@Transactional(readOnly = true)
18+
public class GetVolunteerProfileService implements GetVolunteerProfileUseCase {
19+
20+
private final NEWVolunteerQueryUseCase volunteerQueryUseCase;
21+
private final UserQueryUseCase userQueryUseCase;
22+
23+
@Override
24+
public VolunteerProfileResponseDto getProfileByUserId(UUID userId) {
25+
NEWVolunteer volunteer = volunteerQueryUseCase.getByUserId(userId);
26+
UserCommonAttribute commonAttribute = userQueryUseCase.getCommonAttributeByUserId(userId);
27+
28+
return VolunteerProfileResponseDto.of(volunteer, commonAttribute);
29+
}
30+
31+
@Override
32+
public VolunteerProfileResponseDto getProfileByVolunteerId(UUID volunteerId) {
33+
UUID userId = volunteerQueryUseCase.getUserIdById(volunteerId);
34+
return getProfileByUserId(userId);
35+
}
36+
}

src/main/java/com/somemore/volunteer/service/NEWVolunteerQueryService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,23 @@ public class NEWVolunteerQueryService implements NEWVolunteerQueryUseCase {
1818

1919
private final NEWVolunteerRepository volunteerRepository;
2020

21+
@Override
22+
public NEWVolunteer getById(UUID id) {
23+
return volunteerRepository.findById(id)
24+
.orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_VOLUNTEER));
25+
}
26+
2127
@Override
2228
public NEWVolunteer getByUserId(UUID userId) {
2329
return volunteerRepository.findByUserId(userId)
2430
.orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_VOLUNTEER));
2531
}
2632

33+
@Override
34+
public UUID getUserIdById(UUID id) {
35+
return getById(id).getUserId();
36+
}
37+
2738
@Override
2839
public UUID getIdByUserId(UUID userId) {
2940
return getByUserId(userId).getId();

0 commit comments

Comments
 (0)