Skip to content

Commit

Permalink
SCRUM-44 feat: 상품 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
yeopyeop-82 committed Aug 13, 2024
1 parent d7fa34b commit b7b58b0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
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));
}
}
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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public class Product extends BaseEntity {
@Column(nullable = false)
private Long productQuantity;

@Column(nullable = false)
@Column()
private Float predictReviewStar;

@Column(nullable = false)
@Column()
private Float productStar;

public static Product from(Long productId, Seller seller, Cart cart, List<Review> reviewList,
Expand Down
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 "상품등록 성공";
}
}

0 comments on commit b7b58b0

Please sign in to comment.