Skip to content

Commit e7b48ef

Browse files
committed
update making subgroup
1 parent 5e88ede commit e7b48ef

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/main/java/com/ccapp/ccgo/mission/dto/MissionHistoryDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.NoArgsConstructor;
77

88
import java.time.LocalDateTime;
9+
import java.util.List;
910

1011
@Getter
1112
@Builder
@@ -20,6 +21,7 @@ public class MissionHistoryDto {
2021
private String teamName; // 팀 이름
2122
private Long userId;
2223
private String userName; // 사용자 이름
24+
private List<String> matchedNames; // 매칭된 상대방들의 이름
2325
private Long missionTemplateId;
2426
private String missionTitle; // 미션 제목
2527
private String missionDescription; // 미션 설명

src/main/java/com/ccapp/ccgo/mission/service/SubGroupMissionService.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.ArrayList;
25+
import java.util.Optional;
2526
import java.util.stream.Collectors;
2627
import java.time.LocalDateTime;
2728

@@ -251,13 +252,18 @@ public List<MissionHistoryDto> getMissionHistoryByTeam(Long teamId) {
251252

252253
// MissionHistory를 DTO로 변환
253254
private MissionHistoryDto convertToDto(MissionHistory history) {
255+
// 미션을 완료한 사용자와 매칭된 상대방들의 이름 조회
256+
List<String> matchedNames = getMatchedUserNames(history.getUser().getId(), history.getTeam().getTeamId());
257+
254258
return MissionHistoryDto.builder()
255259
.id(history.getId())
256260
.subGroupId(history.getSubGroup().getId())
261+
.subGroupName(history.getSubGroup().getName())
257262
.teamId(history.getTeam().getTeamId())
258263
.teamName(history.getTeam().getTeamName())
259264
.userId(history.getUser().getId())
260265
.userName(history.getUser().getName())
266+
.matchedNames(matchedNames) // 매칭된 상대방들의 이름 추가
261267
.missionTemplateId(history.getMissionTemplate().getId())
262268
.missionTitle(history.getMissionTemplate().getTitle())
263269
.missionDescription(history.getMissionTemplate().getDescription())
@@ -266,4 +272,31 @@ private MissionHistoryDto convertToDto(MissionHistory history) {
266272
.createdAt(history.getCreatedAt())
267273
.build();
268274
}
275+
276+
// 사용자와 매칭된 상대방들의 이름 조회
277+
private List<String> getMatchedUserNames(Long userId, Long teamId) {
278+
try {
279+
// 사용자가 속한 서브그룹 조회
280+
Optional<Long> subGroupIdOpt = subGroupMemberRepository.findSubGroupIdByTeamIdAndUserId(teamId, userId);
281+
if (subGroupIdOpt.isEmpty()) {
282+
return new ArrayList<>();
283+
}
284+
285+
Long subGroupId = subGroupIdOpt.get();
286+
287+
// 같은 서브그룹의 다른 멤버들 조회 (본인 제외)
288+
List<SubGroupMember> members = subGroupMemberRepository.findBySubGroup_Id(subGroupId);
289+
return members.stream()
290+
.map(member -> member.getUser().getName())
291+
.filter(name -> !name.equals(subGroupMemberRepository.findBySubGroup_Id(subGroupId)
292+
.stream()
293+
.filter(m -> m.getUser().getId().equals(userId))
294+
.findFirst()
295+
.map(m -> m.getUser().getName())
296+
.orElse("")))
297+
.collect(Collectors.toList());
298+
} catch (Exception e) {
299+
return new ArrayList<>();
300+
}
301+
}
269302
}

0 commit comments

Comments
 (0)