From b2a279736d6cb0ce7628622e1adc57d2b826752b Mon Sep 17 00:00:00 2001 From: Seoyoung2222 Date: Sun, 8 Dec 2024 04:10:41 +0900 Subject: [PATCH] =?UTF-8?q?BE:=20[feat]=20=ED=81=AC=EB=A3=A8=EC=9B=90=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A1=B0=ED=9A=8C=20#83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CrewController.java | 13 ++++++ .../common/dto/CrewMemberResponseDto.java | 4 ++ .../crew/common/service/CrewQueryService.java | 45 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/controller/CrewController.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/controller/CrewController.java index 44b1d967..03b13c48 100644 --- a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/controller/CrewController.java +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/controller/CrewController.java @@ -6,6 +6,7 @@ import RunningMachines.R2R.domain.crew.common.dto.CrewResponseDto; import RunningMachines.R2R.domain.crew.common.service.CrewCommandService; import RunningMachines.R2R.domain.crew.common.service.CrewQueryService; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -49,4 +50,16 @@ public ResponseEntity getCrewMember(@PathVariable Long cr CrewMemberResponseDto responseDto = crewQueryService.getCrewMember(crewId); return ResponseEntity.ok(responseDto); } + + @Operation(summary = "크루 멤버 프로필 조회") + @GetMapping("/{crewId}/member/{memberId}/{year}/{month}") + public ResponseEntity getCrewMember( + @PathVariable Long crewId, + @PathVariable Long memberId, + @PathVariable int year, + @PathVariable int month) { + + CrewMemberResponseDto responseDto = crewQueryService.getCrewMemberProfile(crewId, memberId, year, month); + return ResponseEntity.ok(responseDto); + } } diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/dto/CrewMemberResponseDto.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/dto/CrewMemberResponseDto.java index 96ec8f71..48107833 100644 --- a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/dto/CrewMemberResponseDto.java +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/dto/CrewMemberResponseDto.java @@ -1,5 +1,7 @@ package RunningMachines.R2R.domain.crew.common.dto; +import RunningMachines.R2R.domain.user.dto.UserDistanceResponseDto; +import RunningMachines.R2R.domain.user.dto.UserRecentResponseDto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,4 +18,6 @@ public class CrewMemberResponseDto { private int postCount; private int memberCount; private List members; + private List userDistance; + private List recentRuns; } diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/service/CrewQueryService.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/service/CrewQueryService.java index 84e41d27..9ff303d6 100644 --- a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/service/CrewQueryService.java +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/common/service/CrewQueryService.java @@ -1,5 +1,6 @@ package RunningMachines.R2R.domain.crew.common.service; +import RunningMachines.R2R.domain.course.repository.UserCourseRepository; import RunningMachines.R2R.domain.crew.common.dto.CrewMemberResponseDto; import RunningMachines.R2R.domain.crew.common.dto.CrewResponseDto; import RunningMachines.R2R.domain.crew.common.dto.MemberDetailsDto; @@ -7,6 +8,10 @@ import RunningMachines.R2R.domain.crew.common.entity.CrewUser; import RunningMachines.R2R.domain.crew.common.repository.CrewRepository; import RunningMachines.R2R.domain.crew.common.repository.CrewUserRepository; +import RunningMachines.R2R.domain.user.dto.UserDistanceResponseDto; +import RunningMachines.R2R.domain.user.dto.UserRecentResponseDto; +import RunningMachines.R2R.domain.user.entity.User; +import RunningMachines.R2R.domain.user.service.MyPageQueryService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +25,7 @@ public class CrewQueryService { private final CrewRepository crewRepository; private final CrewUserRepository crewUserRepository; + private final MyPageQueryService myPageQueryService; public List getAllCrews() { return crewRepository.findAll().stream() @@ -51,6 +57,45 @@ public CrewMemberResponseDto getCrewMember(Long crewId) { .build(); } + public CrewMemberResponseDto getCrewMemberProfile(Long crewId, Long memberId, int year, int month) { + Crew crew = crewRepository.findById(crewId) + .orElseThrow(() -> new IllegalArgumentException("해당 크루를 찾을 수 없습니다.")); + + List crewUsers = crewUserRepository.findByCrewId(crewId); + CrewUser member = crewUsers.stream() + .filter(crewUser -> crewUser.getUser().getId().equals(memberId)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); + + User user = member.getUser(); + + // 1. 멤버의 달리기 거리 달력 가져오기 (year, month를 기준으로) + List userDistanceResponseDtos = myPageQueryService.getUserDistance(user.getEmail(), year, month); + + // 2. 멤버의 최근 러닝 기록 가져오기 + List recentRuns = myPageQueryService.getUserRecentRunning(user.getEmail()); + + List members = crewUsers.stream() + .map(crewUser -> MemberDetailsDto.builder() + .userId(crewUser.getUser().getId()) + .name(crewUser.getUser().getNickname()) + .profileUrl(crewUser.getUser().getProfileImageUrl()) + .membershipDuration(calculationMembershipDuration(crewUser.getCreatedAt())) + .role(crewUser.getRole().toString()) + .build()) + .toList(); + + // 최종 응답 DTO 생성 + return CrewMemberResponseDto.builder() + .crewTitle(crew.getTitle()) + .postCount(crew.getCrewPosts().size()) + .memberCount(crewUsers.size()) + .members(members) + .userDistance(userDistanceResponseDtos) + .recentRuns(recentRuns) + .build(); + } + private String calculationMembershipDuration(LocalDateTime createdAt) { long months = ChronoUnit.MONTHS.between(createdAt, LocalDateTime.now()); if (months < 12) {