Skip to content

Commit

Permalink
Feature/thumbnail (#22)
Browse files Browse the repository at this point in the history
* feature: 썸넀일 생성 둜직

* feature: 쑰회 μ‹œ 성별 없이 쑰회 κ°€λŠ₯

* doc: 개발용 토큰 λͺ…μ‹œ
  • Loading branch information
mushroom1324 authored Mar 20, 2024
1 parent eea1a86 commit 6d33680
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SuccessResponse<Boolean> likeProduct(@RequestParam Long productId) {

@GetMapping("/recommendation")
public SuccessResponse<List<GetProductThumbnail>> getMainPageRecommendation(
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam String gender,
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam(required = false) String gender,
@Parameter(description = "1번째 νŽ˜μ΄μ§€ μ‘°νšŒμ‹œ null, " +
"2번째 이상 νŽ˜μ΄μ§€ μ‘°νšŒμ‹œ 직전 νŽ˜μ΄μ§€μ˜ λ§ˆμ§€λ§‰ episode id") @RequestParam(required = false) Long cursorId,
@Parameter(description = "ν•œ νŽ˜μ΄μ§€μ— κ°€μ Έμ˜¬ μ—ν”Όμ†Œλ“œ 개수, κΈ°λ³Έκ°’ 4") @RequestParam(required = false) Integer pageSize) {
Expand All @@ -52,7 +52,7 @@ public SuccessResponse<List<GetProductThumbnail>> getMainPageRecommendation(

@GetMapping("/latest")
public SuccessResponse<List<GetProductThumbnail>> getLatestProduct(
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam String gender,
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam(required = false) String gender,
@Parameter(description = "μΉ΄ν…Œκ³ λ¦¬") @RequestParam(required = false) String category,
@Parameter(description = "μŠ€νƒ€μΌ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "μ΅œμ†Œ 가격") @RequestParam(required = false) Long minPrice,
Expand All @@ -68,7 +68,7 @@ public SuccessResponse<List<GetProductThumbnail>> getLatestProduct(

@GetMapping("/lowest-price")
public SuccessResponse<List<GetProductThumbnail>> getLowestProduct(
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam String gender,
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam(required = false) String gender,
@Parameter(description = "μΉ΄ν…Œκ³ λ¦¬") @RequestParam(required = false) String category,
@Parameter(description = "μŠ€νƒ€μΌ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "μ΅œμ†Œ 가격") @RequestParam(required = false) Long minPrice,
Expand All @@ -84,7 +84,7 @@ public SuccessResponse<List<GetProductThumbnail>> getLowestProduct(

@GetMapping("/highest-price")
public SuccessResponse<List<GetProductThumbnail>> getHighestProduct(
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam String gender,
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam(required = false) String gender,
@Parameter(description = "μΉ΄ν…Œκ³ λ¦¬") @RequestParam(required = false) String category,
@Parameter(description = "μŠ€νƒ€μΌ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "μ΅œμ†Œ 가격") @RequestParam(required = false) Long minPrice,
Expand All @@ -100,7 +100,7 @@ public SuccessResponse<List<GetProductThumbnail>> getHighestProduct(

@GetMapping("/highest-discount")
public SuccessResponse<List<GetProductThumbnail>> getHighestDiscountProduct(
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam String gender,
@Parameter(description = "쑰회 의λ₯˜ 성별") @RequestParam(required = false) String gender,
@Parameter(description = "μΉ΄ν…Œκ³ λ¦¬") @RequestParam(required = false) String category,
@Parameter(description = "μŠ€νƒ€μΌ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "μ΅œμ†Œ 가격") @RequestParam(required = false) Long minPrice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public void update(Product product) {
this.qualityRate = product.qualityRate;
this.gender = product.gender;
}

public void updateThumbnailImageUrl(String thumbnailImageUrl) {
this.thumbnailImageUrl = thumbnailImageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ public class ProductService {
private final UserRepository userRepository;
private final ProductLikeRepository productLikeRepository;

private void uploadImage(List<MultipartFile> images, Product product) {
private String uploadImage(List<MultipartFile> images, Product product) {
String thumbnailGeneratedUrl = null;
try {
int sequence = 0;
for (MultipartFile image : images) {
String imageUrl = s3UploadService.saveFile(image, "product/" + product.getId().toString());
productImageRepository.save(ProductImage.of(product, imageUrl, sequence++));
if (sequence == 0) {
String imageUrl = s3UploadService.saveFile(image, "product/thumbnail/" + product.getId().toString());
thumbnailGeneratedUrl = imageUrl.replace("thumbnail/", "thumbnail_generated/");
productImageRepository.save(ProductImage.of(product, imageUrl, sequence++));
} else {
String imageUrl = s3UploadService.saveFile(image, "product/" + product.getId().toString());
productImageRepository.save(ProductImage.of(product, imageUrl, sequence++));
}
}
return thumbnailGeneratedUrl;
}
catch (Exception e) {
throw new CustomException(IMAGE_UPLOAD_FAILED);
Expand Down Expand Up @@ -65,7 +73,8 @@ public ProductResponse registerProduct(PostProduct postProduct) {
Product product = productRepository.save(postProduct.toProduct(user));

// productImage
uploadImage(postProduct.images(), product);
String thumbnailGeneratedUrl = uploadImage(postProduct.images(), product);
product.updateThumbnailImageUrl(thumbnailGeneratedUrl);

// productCategory
addCategory(postProduct.categories(), product);
Expand Down Expand Up @@ -115,7 +124,8 @@ public ProductResponse updateProduct(Long productId, PatchProduct patchProduct)

// productImage
productImageRepository.findByProductId(product.getId()).forEach(ProductImage::delete);
uploadImage(patchProduct.images(), product);
String thumbnailGeneratedUrl = uploadImage(patchProduct.images(), product);
product.updateThumbnailImageUrl(thumbnailGeneratedUrl);

// productCategory
productCategoryRepository.findByProductId(product.getId()).forEach(ProductCategory::delete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
---
### 개발용 토큰
`eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyODg2MjMzNzQ3Iiwicm9sZSI6IlVTRVIiLCJpYXQiOjE3MDk1NTMxNTIsImV4cCI6MTcxODE5MzE1Mn0.85v06Tf4T56-CBjbtzhls_S5_lq7YRhhIaDGH9W7xew`
---
"""),
servers = {
@Server(url = "https://www.repick-server.shop/api", description = "Server URL"),
Expand Down

0 comments on commit 6d33680

Please sign in to comment.