Skip to content

Commit 5238ca6

Browse files
authored
[fix] 팔로우 상태 표시 버그 해결 (#400)
1 parent 9bb9132 commit 5238ca6

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

src/main/java/com/back/domain/artist/controller/ArtistController.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,24 @@ public ResponseEntity<RsData<List<ArtistListResponse>>> getArtistList() {
5959
@GetMapping("/profile/{artistId}")
6060
@Operation(
6161
summary = "작가 공개 프로필 상세 조회",
62-
description = "작가의 공개 프로필 상세 정보를 조회합니다."
62+
description = "작가의 공개 프로필 상세 정보를 조회합니다. 로그인한 경우 팔로우 여부가 포함됩니다."
6363
)
6464
public ResponseEntity<RsData<ArtistPublicProfileResponse>> getArtistPublicProfile(
6565
@Parameter(description = "작가 ID", example = "42", required = true)
66-
@PathVariable Long artistId) {
67-
68-
log.info("작가 공개 프로필 조회 - artistId: {}", artistId);
66+
@PathVariable Long artistId,
67+
@AuthenticationPrincipal CustomUserDetails userDetails) {
6968

70-
ArtistPublicProfileResponse response = artistPublicService.getPublicProfile(artistId);
69+
ArtistPublicProfileResponse response;
70+
71+
if (userDetails != null) {
72+
// 로그인한 사용자 - 팔로우 상태 포함
73+
log.info("작가 공개 프로필 조회 (로그인) - artistId: {}, userId: {}", artistId, userDetails.getUserId());
74+
response = artistPublicService.getPublicProfile(artistId, userDetails.getUserId());
75+
} else {
76+
// 비로그인 사용자 - 팔로우 상태 미포함
77+
log.info("작가 공개 프로필 조회 (비로그인) - artistId: {}", artistId);
78+
response = artistPublicService.getPublicProfile(artistId);
79+
}
7180

7281
return ResponseEntity.ok(
7382
RsData.of("200", "작가 프로필 조회 성공", response)

src/main/java/com/back/domain/artist/dto/response/ArtistPublicProfileResponse.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public record ArtistPublicProfileResponse(
3636
@Schema(description = "등록 상품 수", example = "15")
3737
Integer productCount,
3838

39+
@Schema(description = "팔로우 여부", example = "true")
40+
Boolean isFollowing,
41+
3942
@Schema(description = "작가 등록일", example = "2024-01-15T10:30:00")
4043
LocalDateTime createdAt
4144
) {
@@ -50,6 +53,23 @@ public static ArtistPublicProfileResponse from(ArtistProfile artistProfile) {
5053
artistProfile.getFollowerCount(),
5154
artistProfile.getTotalSales(),
5255
artistProfile.getProductCount(),
56+
false, // 기본값, Service에서 설정 필요
57+
artistProfile.getCreateDate()
58+
);
59+
}
60+
61+
public static ArtistPublicProfileResponse from(ArtistProfile artistProfile, boolean isFollowing) {
62+
return new ArtistPublicProfileResponse(
63+
artistProfile.getId(),
64+
artistProfile.getArtistName(),
65+
artistProfile.getProfileImageUrl(),
66+
artistProfile.getDescription(),
67+
artistProfile.getMainProducts(),
68+
artistProfile.getSnsAccount(),
69+
artistProfile.getFollowerCount(),
70+
artistProfile.getTotalSales(),
71+
artistProfile.getProductCount(),
72+
isFollowing,
5373
artistProfile.getCreateDate()
5474
);
5575
}

src/main/java/com/back/domain/artist/service/ArtistPublicService.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.back.domain.artist.dto.response.ArtistPublicProfileResponse;
66
import com.back.domain.artist.entity.ArtistProfile;
77
import com.back.domain.artist.repository.ArtistProfileRepository;
8+
import com.back.domain.follow.repository.FollowRepository;
89
import com.back.domain.product.product.entity.Product;
910
import com.back.domain.product.product.entity.ProductImage;
1011
import com.back.domain.product.product.repository.ProductRepository;
@@ -29,6 +30,7 @@ public class ArtistPublicService {
2930

3031
private final ArtistProfileRepository artistProfileRepository;
3132
private final ProductRepository productRepository;
33+
private final FollowRepository followRepository;
3234

3335
/**
3436
* 작가 목록 조회
@@ -46,10 +48,10 @@ public List<ArtistListResponse> getArtistList() {
4648
}
4749

4850
/**
49-
* 작가 공개 프로필 상세 조회
51+
* 작가 공개 프로필 상세 조회 (비로그인 사용자)
5052
*/
5153
public ArtistPublicProfileResponse getPublicProfile(Long artistId) {
52-
log.info("작가 공개 프로필 조회 시작 - artistId: {}", artistId);
54+
log.info("작가 공개 프로필 조회 시작 (비로그인) - artistId: {}", artistId);
5355

5456
// 작가 프로필 조회
5557
ArtistProfile artistProfile = artistProfileRepository.findById(artistId)
@@ -61,6 +63,25 @@ public ArtistPublicProfileResponse getPublicProfile(Long artistId) {
6163
return ArtistPublicProfileResponse.from(artistProfile);
6264
}
6365

66+
/**
67+
* 작가 공개 프로필 상세 조회 (로그인 사용자)
68+
*/
69+
public ArtistPublicProfileResponse getPublicProfile(Long artistId, Long currentUserId) {
70+
log.info("작가 공개 프로필 조회 시작 (로그인) - artistId: {}, currentUserId: {}", artistId, currentUserId);
71+
72+
// 작가 프로필 조회
73+
ArtistProfile artistProfile = artistProfileRepository.findById(artistId)
74+
.orElseThrow(() -> new ServiceException("404", "존재하지 않는 작가입니다."));
75+
76+
// 팔로우 여부 확인
77+
boolean isFollowing = followRepository.existsByFollowerIdAndFollowingArtistId(currentUserId, artistId);
78+
79+
log.info("작가 공개 프로필 조회 완료 - artistId: {}, artistName: {}, isFollowing: {}",
80+
artistId, artistProfile.getArtistName(), isFollowing);
81+
82+
return ArtistPublicProfileResponse.from(artistProfile, isFollowing);
83+
}
84+
6485
/**
6586
* 작가 상품 목록 조회
6687
*/

0 commit comments

Comments
 (0)