77import MathCaptain .weakness .Group .dto .response .GroupResponseDto ;
88import MathCaptain .weakness .Group .dto .response .RelationResponseDto ;
99import MathCaptain .weakness .Group .repository .GroupRepository ;
10+ import MathCaptain .weakness .Record .repository .RecordRepository ;
1011import MathCaptain .weakness .User .dto .response .UserResponseDto ;
1112import MathCaptain .weakness .Group .enums .GroupRole ;
1213import MathCaptain .weakness .Group .repository .RelationRepository ;
1920import org .springframework .stereotype .Service ;
2021import org .springframework .transaction .annotation .Transactional ;
2122
23+ import java .time .DayOfWeek ;
24+ import java .time .LocalDateTime ;
25+ import java .time .temporal .TemporalAdjusters ;
2226import java .util .List ;
2327import java .util .stream .Collectors ;
2428
@@ -29,6 +33,7 @@ public class RelationService {
2933
3034 private final RelationRepository relationRepository ;
3135 private final GroupRepository groupRepository ;
36+ private final RecordRepository recordRepository ;
3237
3338 // 그룹 탈퇴
3439 public ApiResponse <?> leaveGroup (Users user , Long groupId ) {
@@ -70,20 +75,17 @@ public void saveRelation(Users member, Group group, GroupJoinRequestDto groupJoi
7075
7176 // 그룹 멤버 리스트 (그룹 상세 페이지)
7277 public List <GroupMemberListResponseDto > getGroupMemberList (Long groupId ) {
73-
78+ // 그룹 멤버 관계 조회
7479 List <RelationBetweenUserAndGroup > relations = relationRepository .findAllByJoinGroup_id (groupId )
7580 .orElseThrow (() -> new ResourceNotFoundException ("해당 그룹에 멤버가 없습니다." ));
7681
82+ // 이번 주의 시작과 끝 시간 계산
83+ LocalDateTime startOfWeek = LocalDateTime .now ().with (TemporalAdjusters .previousOrSame (DayOfWeek .MONDAY ));
84+ LocalDateTime endOfWeek = startOfWeek .plusWeeks (1 );
85+
86+ // 멤버 리스트 생성
7787 return relations .stream ()
78- .map (relation -> GroupMemberListResponseDto .builder ()
79- .userId (relation .getMember ().getUserId ())
80- .userName (relation .getMember ().getName ())
81- // .userImage(relation.getMember().getImage())
82- .userRole (relation .getGroupRole ())
83- .userPoint (relation .getMember ().getUserPoint ())
84- .userWeeklyGoal (relation .getPersonalWeeklyGoal ())
85- .isAchieveWeeklyGoal (relation .getIsWeeklyGoalAchieved ())
86- .build ())
88+ .map (relation -> mapToGroupMemberListResponseDto (relation , startOfWeek , endOfWeek ))
8789 .collect (Collectors .toList ());
8890 }
8991
@@ -131,6 +133,30 @@ public RelationResponseDto getRelationInfo(Long relationId) {
131133
132134 /// 빌드
133135
136+ private GroupMemberListResponseDto mapToGroupMemberListResponseDto (RelationBetweenUserAndGroup relation , LocalDateTime startOfWeek , LocalDateTime endOfWeek ) {
137+ // 기록 리포지토리에서 현재 진행 상황 가져오기 (null 방지)
138+ Integer currentProgress = recordRepository .countDailyGoalAchieved (
139+ relation .getJoinGroup ().getId (),
140+ relation .getMember ().getUserId (),
141+ startOfWeek ,
142+ endOfWeek
143+ ).orElse (0 );
144+
145+ // DTO 빌드 및 반환
146+ return GroupMemberListResponseDto .builder ()
147+ .userId (relation .getMember ().getUserId ())
148+ .userName (relation .getMember ().getName ())
149+ //.userImage(relation.getMember().getImage()) // 주석 유지 또는 복원 필요 시 활성화
150+ .userRole (relation .getGroupRole ())
151+ .userPoint (relation .getMember ().getUserPoint ())
152+ .userWeeklyGoal (relation .getPersonalWeeklyGoal ())
153+ .userDailyGoal (relation .getPersonalDailyGoal ())
154+ .isAchieveWeeklyGoal (relation .getIsWeeklyGoalAchieved ())
155+ .currentProgress (currentProgress )
156+ .build ();
157+ }
158+
159+
134160 private RelationBetweenUserAndGroup buildLeaderRelation (Users leader , Group group , int dailyGoal , int weeklyGoal ) {
135161 return RelationBetweenUserAndGroup .builder ()
136162 .member (leader )
0 commit comments