-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: category 위치 이동 #36 * refactor: RequestMapping으로 묶음 #36 * refactor: Member 도메인 일부 수정 - SQLSelect 삭제 - isDeleted -> deletedAt #36 * feature: 상품 등록 시 validation - 농부인가? - 존재하는 카테고리인가? #36 * feature: 상품 단건 조회 & 다건 조회 #36 * feature: 상품 단건 조회 & 다건 조회 #36 * refactor: 요청 방식 수정 - 리소스 기반으로 표현 #36 * refactor: 요청 방식 수정 - 리소스 기반으로 표현 #36 * refactor: 파일 위치 수정 #36 * refactor: 파일 위치 수정 #36 * refactor: 중복코드 삭제 #36 * fix: 수량 업데이트 동작 안하는 부분 수정 #36 * feature: 상품 단건 조회 - 나중에 DTO는 바껴야할듯 #36 * feature: 회원 조회 조건 수정 - DeletedAtIsNull #36
- Loading branch information
Showing
22 changed files
with
221 additions
and
90 deletions.
There are no files selected for viewing
22 changes: 0 additions & 22 deletions
22
src/main/java/poomasi/domain/category/service/CategoryService.java
This file was deleted.
Oops, something went wrong.
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
6 changes: 3 additions & 3 deletions
6
...y/controller/CategoryAdminController.java → ...y/controller/CategoryAdminController.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
6 changes: 3 additions & 3 deletions
6
...tegory/controller/CategoryController.java → ...tegory/controller/CategoryController.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
4 changes: 2 additions & 2 deletions
4
.../domain/category/dto/CategoryRequest.java → ...roduct/_category/dto/CategoryRequest.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
4 changes: 2 additions & 2 deletions
4
...domain/category/dto/CategoryResponse.java → ...oduct/_category/dto/CategoryResponse.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
4 changes: 2 additions & 2 deletions
4
...masi/domain/category/entity/Category.java → ...in/product/_category/entity/Category.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
4 changes: 2 additions & 2 deletions
4
...tegory/repository/CategoryRepository.java → ...tegory/repository/CategoryRepository.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
9 changes: 4 additions & 5 deletions
9
...ategory/service/CategoryAdminService.java → ...ategory/service/CategoryAdminService.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
31 changes: 31 additions & 0 deletions
31
src/main/java/poomasi/domain/product/_category/service/CategoryService.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,31 @@ | ||
package poomasi.domain.product._category.service; | ||
|
||
import java.util.List; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import poomasi.domain.product._category.dto.CategoryResponse; | ||
import poomasi.domain.product._category.entity.Category; | ||
import poomasi.domain.product._category.repository.CategoryRepository; | ||
import poomasi.global.error.BusinessError; | ||
import poomasi.global.error.BusinessException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CategoryService { | ||
|
||
private final CategoryRepository categoryRepository; | ||
|
||
public List<CategoryResponse> getAllCategories() { | ||
List<Category> categories = categoryRepository.findAll(); | ||
return categories.stream() | ||
.map(CategoryResponse::fromEntity) | ||
.toList(); | ||
} | ||
|
||
public Category getCategory(Long categoryId) { | ||
return categoryRepository.findById(categoryId) | ||
.orElseThrow(() -> new BusinessException(BusinessError.CATEGORY_NOT_FOUND)); | ||
|
||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/poomasi/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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package poomasi.domain.product.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import poomasi.domain.product.service.ProductService; | ||
import poomasi.domain.product.dto.ProductResponse; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/product") | ||
public class ProductController { | ||
private final ProductService productService; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<?> getAllProducts() { | ||
List<ProductResponse> products = productService.getAllProducts(); | ||
return new ResponseEntity<>(products, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/{productId}") | ||
public ResponseEntity<ProductResponse> getProduct(@PathVariable Long productId) { | ||
ProductResponse product = productService.getProductByProductId(productId); | ||
return ResponseEntity.ok(product); | ||
} | ||
} |
34 changes: 19 additions & 15 deletions
34
src/main/java/poomasi/domain/product/controller/ProductFarmerController.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,48 +1,52 @@ | ||
package poomasi.domain.product.controller; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
import poomasi.domain.product.dto.ProductRegisterRequest; | ||
import poomasi.domain.product.dto.UpdateProductQuantityRequest; | ||
import poomasi.domain.product.service.ProductFarmerService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/product") | ||
@Slf4j | ||
public class ProductFarmerController { | ||
|
||
private final ProductFarmerService productFarmerService; | ||
|
||
@PostMapping("/api/products") | ||
@PostMapping("") | ||
public ResponseEntity<?> registerProduct(@RequestBody ProductRegisterRequest product) { | ||
Long productId = productFarmerService.registerProduct(product); | ||
return new ResponseEntity<>(productId, HttpStatus.CREATED); | ||
} | ||
|
||
@PutMapping("/api/products/{productId}") | ||
@PutMapping("/{productId}") | ||
public ResponseEntity<?> modifyProduct(@RequestBody ProductRegisterRequest product, | ||
@PathVariable Long productId) { | ||
productFarmerService.modifyProduct(product, productId); | ||
return new ResponseEntity<>(productId, HttpStatus.OK); | ||
} | ||
|
||
@DeleteMapping("/api/products/{productId}") | ||
@DeleteMapping("/{productId}") | ||
public ResponseEntity<?> deleteProduct(@PathVariable Long productId) { | ||
// TODO: farmerId를 SecurityContextHolder에서 가져와서 비교해야함. | ||
|
||
productFarmerService.deleteProduct(productId); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
@PatchMapping("/api/products/{productId}/count/{quantity}") | ||
public ResponseEntity<?> addQuantity(@PathVariable Long productId, | ||
@PathVariable Integer quantity) { | ||
productFarmerService.addQuantity(productId, quantity); | ||
|
||
@PatchMapping("/{productId}") | ||
public ResponseEntity<?> updateProductQuantity(@PathVariable Long productId, | ||
@RequestBody UpdateProductQuantityRequest request) { | ||
log.debug("Product ID: {}", productId); | ||
log.debug("Update Request: {}", request); | ||
productFarmerService.addQuantity(productId, request); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/poomasi/domain/product/dto/ProductResponse.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,27 @@ | ||
package poomasi.domain.product.dto; | ||
|
||
import lombok.Builder; | ||
import poomasi.domain.product.entity.Product; | ||
|
||
@Builder | ||
public record ProductResponse( | ||
long id, | ||
String name, | ||
Long price, | ||
int stock, | ||
String description, | ||
String imageUrl, | ||
long categoryId | ||
) { | ||
public static ProductResponse fromEntity(Product product) { | ||
return ProductResponse.builder() | ||
.id(product.getId()) | ||
.name(product.getName()) | ||
.price(product.getPrice()) | ||
.stock(product.getStock()) | ||
.description(product.getDescription()) | ||
.imageUrl(product.getImageUrl()) | ||
.categoryId(product.getCategoryId()) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/poomasi/domain/product/dto/UpdateProductQuantityRequest.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,5 @@ | ||
package poomasi.domain.product.dto; | ||
|
||
public record UpdateProductQuantityRequest(Integer quantity) { | ||
} | ||
|
Oops, something went wrong.