From 8918b4e7d06b0e87474c4d151de148ff7562a71f Mon Sep 17 00:00:00 2001 From: huouvcti Date: Mon, 2 Jun 2025 16:09:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=ED=8C=94=EB=A1=9C=EC=9E=89,=20?= =?UTF-8?q?=ED=8C=94=EB=A1=9C=EC=9B=8C=20=EC=88=98=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../follow/repository/FollowsRepository.java | 6 +++ .../profile/controller/ProfileController.java | 9 ++--- .../GetProfileWithFollowCountResponseDto.java | 38 +++++++++++++++++++ .../profile/service/ProfileService.java | 23 +++++------ 4 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/example/feeda/domain/profile/dto/GetProfileWithFollowCountResponseDto.java diff --git a/src/main/java/com/example/feeda/domain/follow/repository/FollowsRepository.java b/src/main/java/com/example/feeda/domain/follow/repository/FollowsRepository.java index caa45f3..cc9f6f0 100644 --- a/src/main/java/com/example/feeda/domain/follow/repository/FollowsRepository.java +++ b/src/main/java/com/example/feeda/domain/follow/repository/FollowsRepository.java @@ -16,4 +16,10 @@ public interface FollowsRepository extends JpaRepository { Page findAllByFollowings_Id(Long followingsId, Pageable pageable); Page findAllByFollowers_Id(Long followersId, Pageable pageable); + + // 팔로워 목록 + Long countByFollowings_Id(Long followingsId); + + // 팔로잉 목록 + Long countByFollowers_Id(Long followersId); } diff --git a/src/main/java/com/example/feeda/domain/profile/controller/ProfileController.java b/src/main/java/com/example/feeda/domain/profile/controller/ProfileController.java index 22f254f..be10c44 100644 --- a/src/main/java/com/example/feeda/domain/profile/controller/ProfileController.java +++ b/src/main/java/com/example/feeda/domain/profile/controller/ProfileController.java @@ -1,9 +1,6 @@ package com.example.feeda.domain.profile.controller; -import com.example.feeda.domain.profile.dto.GetProfileResponseDto; -import com.example.feeda.domain.profile.dto.ProfileListResponseDto; -import com.example.feeda.domain.profile.dto.UpdateProfileRequestDto; -import com.example.feeda.domain.profile.dto.UpdateProfileResponseDto; +import com.example.feeda.domain.profile.dto.*; import com.example.feeda.domain.profile.service.ProfileService; import com.example.feeda.security.jwt.JwtPayload; import jakarta.validation.Valid; @@ -27,8 +24,8 @@ public ProfileController(ProfileService profileService) { */ @GetMapping("/profiles/{id}") - public ResponseEntity getProfile(@PathVariable Long id) { - GetProfileResponseDto responseDto = profileService.getProfile(id); + public ResponseEntity getProfile(@PathVariable Long id) { + GetProfileWithFollowCountResponseDto responseDto = profileService.getProfile(id); return new ResponseEntity<>(responseDto, HttpStatus.OK); } diff --git a/src/main/java/com/example/feeda/domain/profile/dto/GetProfileWithFollowCountResponseDto.java b/src/main/java/com/example/feeda/domain/profile/dto/GetProfileWithFollowCountResponseDto.java new file mode 100644 index 0000000..c3f9228 --- /dev/null +++ b/src/main/java/com/example/feeda/domain/profile/dto/GetProfileWithFollowCountResponseDto.java @@ -0,0 +1,38 @@ +package com.example.feeda.domain.profile.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.time.LocalDateTime; +import java.util.Date; + + +@AllArgsConstructor(staticName = "of") +@Getter +public class GetProfileWithFollowCountResponseDto { + + // 계정 ID + private final Long id; + + // 닉네임 + private final String nickname; + + // 생일 + private final Date birth; + + // 자기소개 + private final String bio; + + // 팔로워 수 + private final Long followerCount; + + // 팔로잉 수 + private final Long followingCount; + + //생성 시간 + private final LocalDateTime createdAt; + + //마지막 수정 시간 + private final LocalDateTime updatedAt; +} + diff --git a/src/main/java/com/example/feeda/domain/profile/service/ProfileService.java b/src/main/java/com/example/feeda/domain/profile/service/ProfileService.java index 5fc2184..b6d8d43 100644 --- a/src/main/java/com/example/feeda/domain/profile/service/ProfileService.java +++ b/src/main/java/com/example/feeda/domain/profile/service/ProfileService.java @@ -1,11 +1,10 @@ package com.example.feeda.domain.profile.service; -import com.example.feeda.domain.profile.dto.GetProfileResponseDto; -import com.example.feeda.domain.profile.dto.ProfileListResponseDto; -import com.example.feeda.domain.profile.dto.UpdateProfileRequestDto; -import com.example.feeda.domain.profile.dto.UpdateProfileResponseDto; +import com.example.feeda.domain.follow.repository.FollowsRepository; +import com.example.feeda.domain.profile.dto.*; import com.example.feeda.domain.profile.entity.Profile; import com.example.feeda.domain.profile.repository.ProfileRepository; +import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -18,30 +17,32 @@ import java.util.List; @Service +@RequiredArgsConstructor public class ProfileService { - private final ProfileRepository profileRepository; - - public ProfileService(ProfileRepository profileRepository) { - this.profileRepository = profileRepository; - } + private final FollowsRepository followsRepository; /** * 프로필 단건 조회 기능 */ @Transactional(readOnly = true) - public GetProfileResponseDto getProfile(Long id) { + public GetProfileWithFollowCountResponseDto getProfile(Long id) { Profile profile = profileRepository.findById(id) .orElseThrow(() -> new ResponseStatusException( HttpStatus.NOT_FOUND, "해당 회원을 찾을 수 없습니다." )); - return GetProfileResponseDto.of( + Long followerCount = followsRepository.countByFollowings_Id(id); + Long followingCount = followsRepository.countByFollowers_Id(id); + + return GetProfileWithFollowCountResponseDto.of( profile.getId(), profile.getNickname(), profile.getBirth(), profile.getBio(), + followerCount, + followingCount, profile.getCreatedAt(), profile.getUpdatedAt() );