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() );