|
1 | 1 | package flipnote.group.application.service; |
2 | 2 |
|
3 | 3 | import java.util.List; |
| 4 | +import java.util.Map; |
| 5 | +import java.util.stream.Collectors; |
4 | 6 |
|
5 | 7 | import org.springframework.stereotype.Service; |
6 | 8 |
|
| 9 | +import flipnote.group.adapter.out.entity.GroupEntity; |
7 | 10 | import flipnote.group.adapter.out.entity.JoinEntity; |
8 | 11 | import flipnote.group.application.port.in.FindMyJoinListUseCase; |
9 | 12 | import flipnote.group.application.port.in.result.FindMyJoinListResult; |
| 13 | +import flipnote.group.application.port.out.GroupRepositoryPort; |
10 | 14 | import flipnote.group.application.port.out.JoinRepositoryPort; |
| 15 | +import flipnote.group.domain.model.join.JoinMyInfo; |
11 | 16 | import lombok.RequiredArgsConstructor; |
12 | 17 |
|
13 | 18 | @Service |
14 | 19 | @RequiredArgsConstructor |
15 | 20 | public class FindMyJoinListService implements FindMyJoinListUseCase { |
16 | 21 |
|
17 | 22 | private final JoinRepositoryPort joinRepository; |
| 23 | + private final GroupRepositoryPort groupRepository; |
18 | 24 |
|
19 | 25 | @Override |
20 | 26 | public FindMyJoinListResult findMyJoinList(Long userId) { |
21 | 27 |
|
22 | 28 | List<JoinEntity> joinList = joinRepository.findMyJoinList(userId); |
23 | 29 |
|
24 | | - return FindMyJoinListResult.of(joinList); |
| 30 | + List<Long> groupIds = joinList.stream() |
| 31 | + .map(JoinEntity::getGroupId) |
| 32 | + .toList(); |
| 33 | + |
| 34 | + List<GroupEntity> groupList = groupRepository.findAllById(groupIds); |
| 35 | + |
| 36 | + Map<Long, String> groupNameMap = groupList.stream() |
| 37 | + .collect(Collectors.toMap(GroupEntity::getId, GroupEntity::getName)); |
| 38 | + |
| 39 | + List<JoinMyInfo> result = joinList.stream() |
| 40 | + .map(join -> JoinMyInfo.of(join, groupNameMap.get(join.getGroupId()))) |
| 41 | + .toList(); |
| 42 | + |
| 43 | + |
| 44 | + return FindMyJoinListResult.of(result); |
25 | 45 | } |
26 | 46 | } |
0 commit comments