Skip to content

Commit

Permalink
[FU-107] 촬영상품의 참고 사진 조회 API 구현 (#19)
Browse files Browse the repository at this point in the history
* FU-107 feat: 참조사진 불러오기 기능 추가

* FU-107 feat: ApiResponseDto, ProductService Interface 삭제

* FU-107 feat: Controller에 @Valid 추가

* FU-107 fix: CustomProductController 클래스 삭제
  • Loading branch information
yuseok0215 authored Aug 12, 2024
1 parent f3c699c commit 261eaf9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import java.util.List;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.foru.freebe.auth.model.MemberAdapter;
import com.foru.freebe.common.dto.ApiResponse;
import com.foru.freebe.member.entity.Member;
import com.foru.freebe.product.dto.customer.ProductBasicInfoResponse;
import com.foru.freebe.product.dto.customer.ProductResponse;
import com.foru.freebe.product.service.CustomerProductService;
Expand All @@ -20,14 +23,21 @@
public class CustomerProductController {
private final CustomerProductService customerProductService;

@GetMapping("/basic-info/{id}")
@GetMapping("/basic-info")
public ApiResponse<List<ProductBasicInfoResponse>> getBasicInfoOfAllProducts(
@PathVariable("id") Long photographerId) {
return customerProductService.getBasicInfoOfAllProducts(photographerId);
@AuthenticationPrincipal MemberAdapter memberAdapter) {
Member customer = memberAdapter.getMember();
return customerProductService.getBasicInfoOfAllProducts(customer.getId());
}

@GetMapping("/detail-info/{id}")
public ApiResponse<ProductResponse> getDetailedInfoOfProduct(@PathVariable("id") Long productId) {
return customerProductService.getDetailedInfoOfProduct(productId);
@GetMapping("/detail-info")
public ApiResponse<ProductResponse> getDetailedInfoOfProduct(@AuthenticationPrincipal MemberAdapter memberAdapter) {
Member customer = memberAdapter.getMember();
return customerProductService.getDetailedInfoOfProduct(customer.getId());
}

@GetMapping("/images/{id}")
public ApiResponse<List<String>> getReferenceImages(@PathVariable("id") Long productId) {
return customerProductService.getReferenceImages(productId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ public ApiResponse<List<RegisteredProductResponse>> getRegisteredProductList(
public ApiResponse<Void> updateProductActiveStatus(@Valid @RequestBody UpdateProductRequest updateProductRequest) {
return productService.updateProductActiveStatus(updateProductRequest);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
import com.foru.freebe.product.entity.ProductImage;

public interface ProductImageRepository extends JpaRepository<ProductImage, Long> {
List<ProductImage> findByProductId(Long productId);
List<ProductImage> findByProduct(Product product);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ public class CustomerProductService {
private final ProductOptionRepository productOptionRepository;
private final ProductDiscountRepository productDiscountRepository;

public ApiResponse<List<String>> getReferenceImages(Long productId) {
List<ProductImage> productImages = productImageRepository.findByProductId(productId);

List<String> referenceImages = new ArrayList<>();
for (ProductImage productImage : productImages) {
referenceImages.add(productImage.getOriginUrl());
}

return ApiResponse.<List<String>>builder()
.status(200)
.message("Good Response")
.data(referenceImages)
.build();
}

public ApiResponse<ProductResponse> getDetailedInfoOfProduct(Long productId) {
Product product = productRepository.findById(productId)
.orElseThrow(() -> new RestApiException(CommonErrorCode.RESOURCE_NOT_FOUND));
Expand Down
Empty file.

0 comments on commit 261eaf9

Please sign in to comment.