-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7fa34b
commit b7b58b0
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/kakaoteck/golagola/domain/product/controller/ProductController.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 |
---|---|---|
@@ -1,4 +1,29 @@ | ||
package com.kakaoteck.golagola.domain.product.controller; | ||
|
||
import com.kakaoteck.golagola.domain.product.dto.ProductRequest; | ||
import com.kakaoteck.golagola.domain.product.service.ProductService; | ||
import com.kakaoteck.golagola.domain.seller.dto.SellerResponse; | ||
import com.kakaoteck.golagola.domain.seller.entity.Seller; | ||
import com.kakaoteck.golagola.global.common.ApiResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/product") | ||
@CrossOrigin("*") | ||
public class ProductController { | ||
|
||
private final ProductService productService; | ||
|
||
@Operation(summary = "상품 등록", description = "상품을 등록합니다. 판매자 전용") | ||
@PostMapping() | ||
public ApiResponse<String> postProduct( | ||
@AuthenticationPrincipal Seller seller, | ||
@RequestBody ProductRequest request | ||
) { | ||
return ApiResponse.onSuccess(productService.postProduct(seller, request)); | ||
} | ||
} |
17 changes: 16 additions & 1 deletion
17
src/main/java/com/kakaoteck/golagola/domain/product/dto/ProductRequest.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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
package com.kakaoteck.golagola.domain.product.dto; | ||
|
||
public record ProductRequest() { | ||
import com.kakaoteck.golagola.global.common.enums.Category; | ||
import com.kakaoteck.golagola.global.common.enums.DetailCategory; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ProductRequest( | ||
String productName, | ||
String productExplanation, | ||
String productImage, | ||
Long productPrice, | ||
Long productInventory, | ||
Category category, | ||
DetailCategory detailCategory, | ||
Long discount, | ||
Long productQuantity | ||
) { | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/kakaoteck/golagola/domain/product/service/ProductService.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 |
---|---|---|
@@ -1,4 +1,48 @@ | ||
package com.kakaoteck.golagola.domain.product.service; | ||
|
||
import com.kakaoteck.golagola.domain.product.dto.ProductRequest; | ||
import com.kakaoteck.golagola.domain.product.entity.Product; | ||
import com.kakaoteck.golagola.domain.product.repository.ProductRepository; | ||
import com.kakaoteck.golagola.domain.seller.entity.Seller; | ||
import com.kakaoteck.golagola.domain.seller.repository.SellerRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalTime; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
@Slf4j | ||
public class ProductService { | ||
|
||
private final SellerRepository sellerRepository; | ||
private final ProductRepository productRepository; | ||
|
||
public String postProduct(Seller seller, ProductRequest request) { | ||
// Product 객체 생성 | ||
Product product = Product.builder() | ||
.seller(seller) | ||
.productName(request.productName()) | ||
.productExplanation(request.productExplanation()) | ||
.productImage(request.productImage()) | ||
.productPrice(request.productPrice()) | ||
.productInventory(request.productInventory()) | ||
.category(request.category()) | ||
.detailCategory(request.detailCategory()) | ||
.discount(request.discount()) | ||
.createTime(LocalTime.now()) | ||
.updateTime(LocalTime.now()) | ||
.productQuantity(request.productQuantity()) | ||
.predictReviewStar(0.0f) // 초기 예상 리뷰 별점 | ||
.productStar(0.0f) // 초기 실제 리뷰 별점 | ||
.build(); | ||
|
||
// Product 저장 | ||
productRepository.save(product); | ||
|
||
return "상품등록 성공"; | ||
} | ||
} |