-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add: 부스 상품 필드를 업데이트할 dto 객체 추가 * Add: 부스 상품 엔티티에 업데이트 메서드 추가 * Add: 부스 상품 수정 요청 객체 추가 * Feat: 부스 상품의 내용을 업데이트하는 기능 추가 * Add: 다른 부스의 카테고리 id를 요청했을 경우의 에러코드 추가 * Feat: 부스 상품의 카테고리를 변경하는 기능 추가 * Feat: 부스 상품 수정 api 컨트롤러 추가 * Refactor: 부스 상품 이미지 서비스 분리 * Refactor: 부스 상품 카테고리 수정 기능 클래스 분리 * Add: 부스 상품 이미지를 수정하는 기능 * Style: 사용하지 않은 줄 삭제 * Fix: 이미지 파일을 받을 수 있도록 요청 방식 변경 * Fix: 카테고리를 변경하지 않는 경우의 처리
- Loading branch information
Showing
9 changed files
with
150 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/openbook/openbook/api/booth/request/ProductModifyRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.openbook.openbook.api.booth.request; | ||
|
||
import java.util.List; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record ProductModifyRequest( | ||
String name, | ||
String description, | ||
Integer stock, | ||
Integer price, | ||
Long categoryId, | ||
List<MultipartFile> imageToAdd, | ||
List<Long> imageToDelete | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/openbook/openbook/service/booth/BoothProductImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.openbook.openbook.service.booth; | ||
|
||
import com.openbook.openbook.domain.booth.BoothProduct; | ||
import com.openbook.openbook.domain.booth.BoothProductImage; | ||
import com.openbook.openbook.exception.ErrorCode; | ||
import com.openbook.openbook.exception.OpenBookException; | ||
import com.openbook.openbook.repository.booth.BoothProductImageRepository; | ||
import com.openbook.openbook.util.S3Service; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BoothProductImageService { | ||
|
||
private final BoothProductImageRepository boothProductImageRepository; | ||
private final S3Service s3Service; | ||
|
||
public void createBoothProductImage(final List<MultipartFile> images, final BoothProduct product) { | ||
if(images==null || images.isEmpty()) return; | ||
images.forEach(image -> boothProductImageRepository.save( | ||
BoothProductImage.builder() | ||
.imageUrl(s3Service.uploadFileAndGetUrl(image)) | ||
.linkedProduct(product) | ||
.build() | ||
)); | ||
} | ||
|
||
public List<BoothProductImage> getProductImages(final BoothProduct product) { | ||
return boothProductImageRepository.findAllByLinkedProductId(product.getId()); | ||
} | ||
|
||
public void modifyReviewImage(List<MultipartFile> add, List<Long> delete, BoothProduct product) { | ||
int addSize = (add!=null)?add.size():0, deleteSize = (delete!=null)?delete.size():0; | ||
if(getProductImageCount(product) - deleteSize + addSize > 5) { | ||
throw new OpenBookException(ErrorCode.EXCEED_MAXIMUM_IMAGE); | ||
} | ||
createBoothProductImage(add, product); | ||
for(int i = 0; i < deleteSize; i++) { | ||
BoothProductImage image = getProductImageOrException(delete.get(i)); | ||
boothProductImageRepository.delete(image); | ||
} | ||
} | ||
|
||
private BoothProductImage getProductImageOrException(long id) { | ||
return boothProductImageRepository.findById(id).orElseThrow(() -> | ||
new OpenBookException(ErrorCode.IMAGE_NOT_FOUND) | ||
); | ||
} | ||
|
||
private int getProductImageCount(final BoothProduct product) { | ||
return boothProductImageRepository.countAllByLinkedProductId(product.getId()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/openbook/openbook/service/booth/dto/BoothProductUpdateData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.openbook.openbook.service.booth.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record BoothProductUpdateData( | ||
String name, | ||
String description, | ||
Integer stock, | ||
Integer price | ||
) { | ||
} |