Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

컬럼 추가, 상품 이미지 수정, 컨트롤러 경로 수정 #208

Merged
merged 2 commits into from
Nov 14, 2024
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 @@ -23,7 +23,7 @@ public boolean supports(ImageType type) {
@Override
public void handleImageDeletion(Image image) {
Product product = productService.findProductById(image.getReferenceId());
product.setImageUrl(null);
product.getImages().remove(image);
productService.saveExistedProduct(product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public boolean supports(ImageType type) {
@Override
public void link(Long referenceId, Image savedImage) {
Product product = productService.findProductById(referenceId);
product.setImageUrl(savedImage.getImageUrl());
product.getImages().add(savedImage);
productService.saveExistedProduct(product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public PaymentPreRegisterRequest productPreOrderRegister(ProductOrderRegisterReq
throw new BusinessException(PRODUCT_STOCK_ZERO);
}

if(product.getOrderLimit() < quantityInCart)
throw new BusinessException(BusinessError.COUNT_LIMIT_EXCEEDED);

String productDescription = product.getDescription();
String productName = product.getName();
BigDecimal price = product.getPrice().multiply(BigDecimal.valueOf((long) quantityInCart));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@Controller
@RequiredArgsConstructor
@RequestMapping("/api/cart")
@RequestMapping("/api/carts")
public class CartController {

private final CartService cartService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package poomasi.domain.product._category.dto;

import java.math.BigDecimal;
import java.util.List;
import lombok.Builder;
import poomasi.domain.image.entity.Image;
import poomasi.domain.product.entity.Product;

@Builder
public record ProductListInCategoryResponse(
Long categoryId,
String name,
String description,
String imageUrl,
List<Image> images,
Integer quantity,
BigDecimal price
) {
Expand All @@ -19,7 +21,7 @@ public static ProductListInCategoryResponse fromEntity(Product product) {
.categoryId(product.getCategoryId())
.name(product.getName())
.description(product.getDescription())
.imageUrl(product.getImageUrl())
.images(product.getImages())
.quantity(product.getStock())
.price(product.getPrice())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Controller
@RequiredArgsConstructor
@RequestMapping("/api/product/{productId}/intro")
@RequestMapping("/api/products/{productId}/intro")
public class ProductIntroController {

private final ProductIntroService productIntroService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/product")
@RequestMapping("/api/products")
public class ProductController {

private final ProductService productService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/product")
@RequestMapping("/api/products")
@Slf4j
public class ProductFarmerController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import poomasi.domain.product.dto.ProductTagRequest;
import poomasi.domain.product.service.ProductTagService;

@Controller
@RequiredArgsConstructor
@RequestMapping("/api/products")
public class ProductTagController {

private final ProductTagService productTagService;

@Secured("ROLE_ADMIN")
@PostMapping("/api/products/tag")
@PostMapping("/tag")
public ResponseEntity<?> addTag(@RequestBody ProductTagRequest productTagRequest) {
productTagService.addTag(productTagRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@Secured("ROLE_ADMIN")
@DeleteMapping("/api/products/tag")
@DeleteMapping("/tag")
public ResponseEntity<?> deleteTag(@RequestBody ProductTagRequest productTagRequest) {
productTagService.deleteTag(productTagRequest);
return ResponseEntity.ok().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,33 @@ public record ProductRegisterRequest(

//product intro
String mainTitle,
//Long mainImageId,

String subTitle1,
String subDesc1,
//Long subImage1Id,

String subTitle2,
String subDesc2,
//Long subImage2Id,

String subTitle3,
String subDesc3
//Long subImage3Id
String subDesc3,

String oneLineDescription,
Integer orderLimit

) {

public Product toEntity(Member member, Store store) {
ProductIntro productIntro = ProductIntro.builder()
.mainTitle(mainTitle)
//.mainImage(mainImage)

.subTitle1(subTitle1)
.subDesc1(subDesc1)
//.subImage1(subImage1)

.subTitle2(subTitle2)
.subDesc2(subDesc2)
//.subImage2(subImage2)

.subTitle3(subTitle3)
.subDesc3(subDesc3)
//.subImage3(subImage3)
.build();

return Product.builder()
Expand All @@ -70,6 +65,8 @@ public Product toEntity(Member member, Store store) {
.growEnv(growEnv)
.shippingFee(shippingFee)
.productIntro(productIntro)
.oneLineDescription(oneLineDescription)
.orderLimit(orderLimit)
.build();
}
}
11 changes: 8 additions & 3 deletions src/main/java/poomasi/domain/product/dto/ProductResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.math.BigDecimal;
import java.util.List;
import lombok.Builder;
import poomasi.domain.image.entity.Image;
import poomasi.domain.product._intro.dto.ProductIntroResponse;
import poomasi.domain.product.entity.Product;
import poomasi.domain.product.entity.ProductTagEnum;
Expand All @@ -14,13 +15,15 @@ public record ProductResponse(
BigDecimal price,
Integer stock,
String description,
String imageUrl,
List<Image> images,
Long categoryId,
String storeName,
List<String> tags,
ProductIntroResponse productIntro,
String growEnv,
BigDecimal shippingFee
BigDecimal shippingFee,
String oneLineDescription,
Integer orderLimit
) {

public static ProductResponse fromEntity(Product product) {
Expand All @@ -32,11 +35,13 @@ public static ProductResponse fromEntity(Product product) {
.price(product.getPrice())
.stock(product.getStock())
.description(product.getDescription())
.imageUrl(product.getImageUrl())
.images(product.getImages())
.storeName(product.getStore().getName())
.categoryId(product.getCategoryId())
.growEnv(product.getGrowEnv())
.shippingFee(product.getShippingFee())
.oneLineDescription(product.getOneLineDescription())
.orderLimit(product.getOrderLimit())
.tags(tags)
.productIntro(ProductIntroResponse.fromEntity(product.getProductIntro()))
.build();
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/poomasi/domain/product/entity/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import poomasi.domain.image.entity.Image;
import poomasi.domain.product._intro.entity.ProductIntro;
import poomasi.domain.order.entity._product.OrderedProduct;
import poomasi.domain.store.entity.Store;
Expand Down Expand Up @@ -43,8 +44,9 @@ public class Product {
private String description;

@Setter
@Comment("이미지 URL")
private String imageUrl;
@Comment("이미지")
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<Image> images;

@Comment("재고")
private Integer stock;
Expand All @@ -58,6 +60,12 @@ public class Product {
@Comment("배송비")
BigDecimal shippingFee;

@Comment("한줄 소개")
private String oneLineDescription;

@Comment("인당 최대 개수 제한")
private Integer orderLimit;

@Comment("삭제 일시")
private LocalDateTime deletedAt;

Expand All @@ -69,7 +77,7 @@ public class Product {

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "entityId")
List<Review> reviewList = new ArrayList<>();
List<Review> reviewList;

@ManyToOne
@JoinColumn(name = "store_id") // 외래 키 컬럼 지정
Expand Down Expand Up @@ -111,30 +119,36 @@ public Product(Long productId,
Store store,
String growEnv,
BigDecimal shippingFee,
ProductIntro productIntro) {
ProductIntro productIntro,
String oneLineDescription,
Integer orderLimit) {
this.id = productId;
this.categoryId = categoryId;
this.farmerId = farmerId;
this.name = name;
this.description = description;
this.imageUrl = imageUrl;
this.images = new ArrayList<>();
this.stock = stock;
this.price = price;
this.store = store;
this.productIntro = productIntro;
this.growEnv = growEnv;
this.shippingFee = shippingFee;
this.reviewList = new ArrayList<>();
this.oneLineDescription = oneLineDescription;
this.orderLimit = orderLimit;
}

public Product modify(ProductRegisterRequest productRegisterRequest) {
this.categoryId = productRegisterRequest.categoryId();
this.name = productRegisterRequest.name();
this.description = productRegisterRequest.description();
this.imageUrl = productRegisterRequest.imageUrl();
this.stock = productRegisterRequest.stock();
this.price = productRegisterRequest.price();
this.growEnv = productRegisterRequest.growEnv();
this.shippingFee = productRegisterRequest.shippingFee();
this.oneLineDescription = productRegisterRequest.oneLineDescription();
this.orderLimit = productRegisterRequest.orderLimit();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public Long registerProduct(Member member, ProductRegisterRequest request) {
Category category = getCategory(request.categoryId());
Store store = member.getStore();

// Image introMainImage = getImage(request.mainImageId());
// Image introSubImage1 = getImage(request.subImage1Id());
// Image introSubImage2 = getImage(request.subImage2Id());
// Image introSubImage3 = getImage(request.subImage3Id());

Product saveProduct = productRepository.save(request.toEntity(member,store));

category.addProduct(saveProduct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class FarmReviewController {

private final FarmReviewService farmReviewService;

@GetMapping("/api/farm/{farmId}/reviews")
@GetMapping("/api/farms/{farmId}/reviews")
public ResponseEntity<?> getProductReviews(@PathVariable Long farmId) {
List<ReviewResponse> response = farmReviewService.getFarmReview(farmId);
return new ResponseEntity<>(response, HttpStatus.OK);
}

@PostMapping("/api/farm/{reservationId}/reviews")
@PostMapping("/api/farms/{reservationId}/reviews")
public ResponseEntity<?> registerProductReview(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long reservationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/store")
@RequestMapping("/api/stores")
public class StoreController {
private final StoreService storeService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package poomasi.domain.wishlist.dto;

import java.math.BigDecimal;
import java.util.List;
import poomasi.domain.image.entity.Image;
import poomasi.domain.wishlist.entity.WishList;

public record WishListResponse(
Long productId,
String productName,
BigDecimal price,
String imageUrl,
List<Image> images,
String description
) {
public static WishListResponse fromEntity(WishList wishList) {
return new WishListResponse(
wishList.getProduct().getId(),
wishList.getProduct().getName(),
wishList.getProduct().getPrice(),
wishList.getProduct().getImageUrl(),
wishList.getProduct().getImages(),
wishList.getProduct().getDescription()
);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/poomasi/global/error/BusinessError.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public enum BusinessError {
ORDER_PRODUCT_DETAILS_NOT_FOUND(HttpStatus.NOT_FOUND, "주문을 찾을 수 없습니다."),
ORDER_PRODUCT_DETAILS_NOT_OWNED_EXCEPTION(HttpStatus.UNAUTHORIZED, "허가되지 않은 주문입니다."),
ORDERED_PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "찾을 수 없는 주문입니다."),
COUNT_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST, "주문 가능 최대 개수 보다 많이 요청했습니다."),

//Store
STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "등록된 상점이 없습니다."),
Expand Down
Loading