Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public interface FollowsRepository extends JpaRepository<Follows, Long> {
Page<Follows> findAllByFollowings_Id(Long followingsId, Pageable pageable);

Page<Follows> findAllByFollowers_Id(Long followersId, Pageable pageable);

// 팔로워 목록
Long countByFollowings_Id(Long followingsId);

// 팔로잉 목록
Long countByFollowers_Id(Long followersId);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,8 +24,8 @@ public ProfileController(ProfileService profileService) {
*/

@GetMapping("/profiles/{id}")
public ResponseEntity<GetProfileResponseDto> getProfile(@PathVariable Long id) {
GetProfileResponseDto responseDto = profileService.getProfile(id);
public ResponseEntity<GetProfileWithFollowCountResponseDto> getProfile(@PathVariable Long id) {
GetProfileWithFollowCountResponseDto responseDto = profileService.getProfile(id);
return new ResponseEntity<>(responseDto, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
);
Expand Down