Skip to content

Commit 144b057

Browse files
authored
[fix] 작가 상품 목록 조회 Id 문제 버그 해결 (#391)
1 parent 8716f82 commit 144b057

File tree

5 files changed

+19
-26
lines changed

5 files changed

+19
-26
lines changed

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import jakarta.validation.Valid;
1313
import lombok.RequiredArgsConstructor;
1414
import lombok.extern.slf4j.Slf4j;
15-
import org.springframework.data.domain.PageRequest;
16-
import org.springframework.data.domain.Pageable;
1715
import org.springframework.http.ResponseEntity;
1816
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1917
import org.springframework.web.bind.annotation.*;
@@ -83,19 +81,12 @@ public ResponseEntity<RsData<ArtistPublicProfileResponse>> getArtistPublicProfil
8381
description = "특정 작가가 등록한 모든 상품을 조회합니다."
8482
)
8583
public ResponseEntity<RsData<List<ArtistProductResponse>>> getArtistProducts(
86-
@Parameter(description = "작가 ID", example = "42", required = true)
87-
@PathVariable Long artistId,
88-
89-
@Parameter(description = "페이지 번호 (1부터 시작)", example = "1")
90-
@RequestParam(defaultValue = "1") int page,
91-
92-
@Parameter(description = "페이지 크기", example = "12")
93-
@RequestParam(defaultValue = "12") int size) {
84+
@Parameter(description = "작가 프로필 ID", example = "42", required = true)
85+
@PathVariable Long artistId) {
9486

95-
log.info("작가 상품 목록 조회 - artistId: {}, page: {}, size: {}", artistId, page, size);
87+
log.info("작가 상품 목록 조회 - artistId: {}", artistId);
9688

97-
Pageable pageable = PageRequest.of(page - 1, size);
98-
List<ArtistProductResponse> response = artistPublicService.getArtistProducts(artistId, pageable);
89+
List<ArtistProductResponse> response = artistPublicService.getArtistProducts(artistId);
9990

10091
return ResponseEntity.ok(
10192
RsData.of("200", "작가 상품 목록 조회 성공", response)

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.back.global.s3.FileType;
1313
import lombok.RequiredArgsConstructor;
1414
import lombok.extern.slf4j.Slf4j;
15-
import org.springframework.data.domain.Pageable;
1615
import org.springframework.stereotype.Service;
1716
import org.springframework.transaction.annotation.Transactional;
1817

@@ -65,20 +64,20 @@ public ArtistPublicProfileResponse getPublicProfile(Long artistId) {
6564
/**
6665
* 작가 상품 목록 조회
6766
*/
68-
public List<ArtistProductResponse> getArtistProducts(Long artistId, Pageable pageable) {
69-
log.info("작가 상품 목록 조회 시작 - artistId: {}, page: {}, size: {}",
70-
artistId, pageable.getPageNumber(), pageable.getPageSize());
67+
public List<ArtistProductResponse> getArtistProducts(Long artistProfileId) {
68+
log.info("작가 상품 목록 조회 시작 - artistProfileId: {}", artistProfileId);
7169

72-
// 작가 존재 여부 확인
73-
if (!artistProfileRepository.existsByUserId(artistId)) {
74-
throw new ServiceException("404", "존재하지 않는 작가입니다.");
75-
}
70+
// 작가 프로필 조회
71+
ArtistProfile artistProfile = artistProfileRepository.findById(artistProfileId)
72+
.orElseThrow(() -> new ServiceException("404", "존재하지 않는 작가입니다."));
7673

77-
// 작가의 상품 목록 조회 (판매 중인 상품만)
78-
List<Product> products = productRepository.findByUserIdAndIsDeletedFalse(artistId, pageable);
74+
// 작가의 상품 목록 조회
75+
List<Product> products = productRepository.findByUserIdAndIsDeletedFalse(
76+
artistProfile.getUser().getId()
77+
);
7978

80-
log.info("작가 상품 목록 조회 완료 - artistId: {}, 조회된 상품 수: {}",
81-
artistId, products.size());
79+
log.info("작가 상품 목록 조회 완료 - artistProfileId: {}, 조회된 상품 수: {}",
80+
artistProfileId, products.size());
8281

8382
return products.stream()
8483
.map(this::convertToArtistProductResponse)

src/main/java/com/back/domain/product/product/repository/ProductRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public interface ProductRepository extends JpaRepository<Product, Long>, Product
3636
*/
3737
List<Product> findByUserIdAndIsDeletedFalse(Long userId, Pageable pageable);
3838

39+
List<Product> findByUserIdAndIsDeletedFalse(Long artistId);
40+
3941
// 판매 시작일이 오늘 이후인 상품 조회
4042
List<Product> findBySellingStartDateAfter(LocalDateTime dateTime);
4143

src/main/java/com/back/global/security/config/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
6565

6666
// 작가 공개 정보 조회
6767
.requestMatchers("/api/artist/profile/**", "/api/artist/list").permitAll()
68+
.requestMatchers(HttpMethod.GET, "/api/artist/profile/*/products").permitAll()
6869

6970
// 공지사항 조회 - 로그인 없이 접근 허용
7071
.requestMatchers(HttpMethod.GET, "/api/support/notices", "/api/support/notices/**").permitAll()

src/test/java/com/back/domain/artist/controller/ArtistControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ void t20() throws Exception {
649649
artistProfileRepository.save(profile);
650650

651651
// when - 상품이 없는 상태에서 조회
652-
ResultActions resultActions = mvc.perform(get("/api/artist/profile/" + user1.getId() + "/products")
652+
ResultActions resultActions = mvc.perform(get("/api/artist/profile/" + profile.getId() + "/products")
653653
.param("page", "1")
654654
.param("size", "12")
655655
.contentType(MediaType.APPLICATION_JSON))

0 commit comments

Comments
 (0)