Skip to content

Commit

Permalink
feat: 등록할 때 아이디 반환 (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
canyos authored Nov 14, 2024
1 parent 8f966bd commit 826bc09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import poomasi.domain.auth.security.userdetail.UserDetailsImpl;
import poomasi.domain.member.entity.Member;
import poomasi.domain.product.dto.ProductRegisterRequest;
import poomasi.domain.product.dto.ProductRegisterResponse;
import poomasi.domain.product.dto.UpdateProductQuantityRequest;
import poomasi.domain.product.service.ProductFarmerService;

Expand All @@ -34,8 +35,8 @@ public class ProductFarmerController {
(@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody ProductRegisterRequest product) {
Member member = userDetails.getMember();
Long productId = productFarmerService.registerProduct(member, product);
return new ResponseEntity<>(productId, HttpStatus.CREATED);
ProductRegisterResponse response = productFarmerService.registerProduct(member, product);
return new ResponseEntity<>(response, HttpStatus.CREATED);
}

@Secured({"ROLE_FARMER", "ROLE_ADMIN"})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package poomasi.domain.product.dto;

public record ProductRegisterResponse(
Long productId,
Long productIntroId
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import poomasi.domain.product._category.entity.Category;
import poomasi.domain.product._category.repository.CategoryRepository;
import poomasi.domain.product._category.service.CategoryService;
import poomasi.domain.product._intro.entity.ProductIntro;
import poomasi.domain.product._intro.repository.ProductIntroRepository;
import poomasi.domain.product.dto.ProductRegisterResponse;
import poomasi.domain.store.entity.Store;
import poomasi.domain.store.repository.StoreRepository;
import poomasi.domain.product.dto.ProductRegisterRequest;
Expand All @@ -29,9 +32,10 @@ public class ProductFarmerService {
private final CategoryService categoryService;
private final StoreService storeService;
private final ImageRepository imageRepository;
private final ProductIntroRepository productIntroRepository;

@Transactional
public Long registerProduct(Member member, ProductRegisterRequest request) {
public ProductRegisterResponse registerProduct(Member member, ProductRegisterRequest request) {
Category category = getCategory(request.categoryId());
Store store = member.getStore();

Expand All @@ -40,7 +44,7 @@ public Long registerProduct(Member member, ProductRegisterRequest request) {
category.addProduct(saveProduct);
store.addProduct(saveProduct);
saveProduct.getProductIntro().setProduct(saveProduct);
return saveProduct.getId();
return new ProductRegisterResponse(saveProduct.getId(), saveProduct.getProductIntro().getId());
}

private Image getImage(Long imageId) {
Expand Down

0 comments on commit 826bc09

Please sign in to comment.