Skip to content

Commit 5284816

Browse files
committed
refactor(volunteer-apply): VolunteerInfo 객체만 가져오도록 수정
- 객체를 가져오고 현 서비스에서 응답 DTO로 감싸주도록 변경
1 parent 26eb1c3 commit 5284816

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.somemore.volunteer.domain.VolunteerDetail;
99
import com.somemore.volunteer.dto.response.VolunteerProfileResponseDto;
1010
import com.somemore.volunteer.dto.response.VolunteerRankingResponseDto;
11-
import com.somemore.volunteer.dto.response.VolunteerSimpleInfoResponseDto;
1211
import com.somemore.volunteer.repository.VolunteerDetailRepository;
1312
import com.somemore.volunteer.repository.VolunteerRepository;
1413
import com.somemore.volunteer.repository.mapper.VolunteerOverviewForRankingByHours;
@@ -89,15 +88,8 @@ public List<Volunteer> getAllByIds(List<UUID> volunteerIds) {
8988
}
9089

9190
@Override
92-
public List<VolunteerSimpleInfoResponseDto> getVolunteerSimpleInfosByIds(
93-
List<UUID> volunteerIds) {
94-
95-
List<VolunteerSimpleInfo> volunteerSimpleInfos = volunteerRepository.findSimpleInfoByIds(
96-
volunteerIds);
97-
98-
return volunteerSimpleInfos.stream()
99-
.map(VolunteerSimpleInfoResponseDto::from)
100-
.toList();
91+
public List<VolunteerSimpleInfo> getVolunteerSimpleInfosByIds(List<UUID> ids) {
92+
return volunteerRepository.findSimpleInfoByIds(ids);
10193
}
10294

10395
private Volunteer findVolunteer(UUID volunteerId) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.somemore.volunteer.dto.response.VolunteerProfileResponseDto;
55
import com.somemore.volunteer.dto.response.VolunteerRankingResponseDto;
66
import com.somemore.volunteer.dto.response.VolunteerSimpleInfoResponseDto;
7+
import com.somemore.volunteer.repository.mapper.VolunteerSimpleInfo;
78
import java.util.List;
89
import java.util.UUID;
910

@@ -23,5 +24,5 @@ public interface VolunteerQueryUseCase {
2324

2425
List<Volunteer> getAllByIds(List<UUID> volunteerIds);
2526

26-
List<VolunteerSimpleInfoResponseDto> getVolunteerSimpleInfosByIds(List<UUID> volunteerIds);
27+
List<VolunteerSimpleInfo> getVolunteerSimpleInfosByIds(List<UUID> ids);
2728
}

src/main/java/com/somemore/volunteerapply/dto/response/VolunteerApplyVolunteerInfoResponseDto.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
44
import com.fasterxml.jackson.databind.annotation.JsonNaming;
55
import com.somemore.volunteer.dto.response.VolunteerSimpleInfoResponseDto;
6+
import com.somemore.volunteer.repository.mapper.VolunteerSimpleInfo;
67
import com.somemore.volunteerapply.domain.ApplyStatus;
78
import com.somemore.volunteerapply.domain.VolunteerApply;
89
import io.swagger.v3.oas.annotations.media.Schema;
@@ -32,8 +33,10 @@ public record VolunteerApplyVolunteerInfoResponseDto(
3233

3334
public static VolunteerApplyVolunteerInfoResponseDto of(
3435
VolunteerApply volunteerApply,
35-
VolunteerSimpleInfoResponseDto volunteer
36+
VolunteerSimpleInfo volunteerSimpleInfo
3637
) {
38+
VolunteerSimpleInfoResponseDto volunteer = VolunteerSimpleInfoResponseDto.from(
39+
volunteerSimpleInfo);
3740
return VolunteerApplyVolunteerInfoResponseDto.builder()
3841
.id(volunteerApply.getId())
3942
.recruitBoardId(volunteerApply.getRecruitBoardId())

src/main/java/com/somemore/volunteerapply/service/VolunteerApplyQueryFacadeService.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.somemore.global.exception.BadRequestException;
66
import com.somemore.recruitboard.domain.RecruitBoard;
77
import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase;
8-
import com.somemore.volunteer.dto.response.VolunteerSimpleInfoResponseDto;
8+
import com.somemore.volunteer.repository.mapper.VolunteerSimpleInfo;
99
import com.somemore.volunteer.usecase.VolunteerQueryUseCase;
1010
import com.somemore.volunteerapply.domain.VolunteerApply;
1111
import com.somemore.volunteerapply.dto.condition.VolunteerApplySearchCondition;
@@ -39,14 +39,14 @@ public Page<VolunteerApplyVolunteerInfoResponseDto> getVolunteerAppliesByRecruit
3939
Page<VolunteerApply> applies = volunteerApplyRepository.findAllByRecruitId(recruitId,
4040
condition);
4141

42-
Map<UUID, VolunteerSimpleInfoResponseDto> volunteerMap = getVolunteerInfoMap(
42+
Map<UUID, VolunteerSimpleInfo> volunteerMap = getVolunteerInfoMap(
4343
applies);
4444

45-
return applies.map(apply -> {
46-
VolunteerSimpleInfoResponseDto volunteerInfo = volunteerMap.getOrDefault(
47-
apply.getVolunteerId(), null);
48-
return VolunteerApplyVolunteerInfoResponseDto.of(apply, volunteerInfo);
49-
});
45+
return applies.map(
46+
apply -> VolunteerApplyVolunteerInfoResponseDto.of(
47+
apply,
48+
volunteerMap.getOrDefault(apply.getVolunteerId(), null)
49+
));
5050
}
5151

5252
@Override
@@ -79,24 +79,20 @@ private Map<Long, RecruitBoard> getRecruitBoardMap(Page<VolunteerApply> applies)
7979
.toList();
8080
List<RecruitBoard> boards = recruitBoardQueryUseCase.getAllByIds(boardIds);
8181

82-
Map<Long, RecruitBoard> boardMap = boards.stream()
82+
return boards.stream()
8383
.collect(Collectors.toMap(RecruitBoard::getId,
8484
board -> board));
85-
return boardMap;
8685
}
8786

88-
private Map<UUID, VolunteerSimpleInfoResponseDto> getVolunteerInfoMap(
89-
Page<VolunteerApply> applies) {
90-
91-
List<UUID> volunteerIds = applies.getContent().stream()
92-
.map(VolunteerApply::getVolunteerId)
93-
.collect(Collectors.toList());
87+
private Map<UUID, VolunteerSimpleInfo> getVolunteerInfoMap(Page<VolunteerApply> applies) {
88+
List<UUID> volunteerIds = applies.getContent().stream().map(VolunteerApply::getVolunteerId)
89+
.toList();
9490

95-
List<VolunteerSimpleInfoResponseDto> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(
91+
List<VolunteerSimpleInfo> volunteers = volunteerQueryUseCase.getVolunteerSimpleInfosByIds(
9692
volunteerIds);
9793

9894
return volunteers.stream()
99-
.collect(Collectors.toMap(VolunteerSimpleInfoResponseDto::id,
95+
.collect(Collectors.toMap(VolunteerSimpleInfo::id,
10096
volunteer -> volunteer));
10197
}
10298

0 commit comments

Comments
 (0)