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 @@ -12,8 +12,6 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -83,19 +81,12 @@ public ResponseEntity<RsData<ArtistPublicProfileResponse>> getArtistPublicProfil
description = "특정 작가가 등록한 모든 상품을 조회합니다."
)
public ResponseEntity<RsData<List<ArtistProductResponse>>> getArtistProducts(
@Parameter(description = "작가 ID", example = "42", required = true)
@PathVariable Long artistId,

@Parameter(description = "페이지 번호 (1부터 시작)", example = "1")
@RequestParam(defaultValue = "1") int page,

@Parameter(description = "페이지 크기", example = "12")
@RequestParam(defaultValue = "12") int size) {
@Parameter(description = "작가 프로필 ID", example = "42", required = true)
@PathVariable Long artistId) {

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

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

return ResponseEntity.ok(
RsData.of("200", "작가 상품 목록 조회 성공", response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.back.global.s3.FileType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

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

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

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

return products.stream()
.map(this::convertToArtistProductResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface ProductRepository extends JpaRepository<Product, Long>, Product
*/
List<Product> findByUserIdAndIsDeletedFalse(Long userId, Pageable pageable);

List<Product> findByUserIdAndIsDeletedFalse(Long artistId);

// 판매 시작일이 오늘 이후인 상품 조회
List<Product> findBySellingStartDateAfter(LocalDateTime dateTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

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

// 공지사항 조회 - 로그인 없이 접근 허용
.requestMatchers(HttpMethod.GET, "/api/support/notices", "/api/support/notices/**").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void t20() throws Exception {
artistProfileRepository.save(profile);

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