-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Troth-Cam/dev
feat(#126): ProductController 수정
- Loading branch information
Showing
11 changed files
with
66 additions
and
77 deletions.
There are no files selected for viewing
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
49 changes: 26 additions & 23 deletions
49
src/main/java/trothly/trothcam/controller/web/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,49 +1,52 @@ | ||
package trothly.trothcam.controller.web; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.ObjectError; | ||
import org.springframework.web.bind.annotation.*; | ||
import trothly.trothcam.domain.member.Member; | ||
import trothly.trothcam.domain.product.Product; | ||
import trothly.trothcam.dto.web.ProductDetailResDto; | ||
import trothly.trothcam.dto.web.ProductReqDto; | ||
import trothly.trothcam.dto.web.ProductsResDto; | ||
import trothly.trothcam.exception.base.BaseException; | ||
import trothly.trothcam.exception.base.BaseResponse; | ||
import trothly.trothcam.exception.base.ErrorCode; | ||
import trothly.trothcam.exception.custom.BadRequestException; | ||
import trothly.trothcam.service.web.ProductService; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api") | ||
public class ProductController { | ||
|
||
private final ProductService productService; | ||
|
||
// TODO: 2023/08/13 응답 값이 비어있음. 엥? 로그도 안찍힘.. JPA 문제? query 직접 짜보기. | ||
/* 공개 인증서 조회 */ | ||
// @GetMapping("/products") | ||
// public<T> BaseResponse<ProductsResDto> findPublicProducts(@RequestParam(value = "id") String id) { | ||
// List<Product> findProducts = productService.findPublicProducts(id); | ||
// | ||
// // TODO: 2023/08/11 liked 여부 확인하는 로직 필요 | ||
// // TODO: 2023/08/11 createdAt LocalDateTime -> String 변환 로직 필요 | ||
// List<ProductsResDto> collect = findProducts.stream() | ||
// .map(m -> new ProductsResDto(m.getTitle(), m.getMember().getWebId(), "20230605", m.getPrice(), true)) | ||
// .collect(Collectors.toList()); | ||
// | ||
// return new BaseResponse<ProductsResDto>(collect); | ||
// } | ||
@GetMapping("/products") | ||
public BaseResponse<List<ProductsResDto>> findPublicProducts(@RequestParam(value = "web-id") String webId) { | ||
List<ProductsResDto> result = productService.findPublicProducts(webId); | ||
log.trace("인증서 가져오기 controller"); | ||
if (result.isEmpty()) { | ||
throw new BaseException(ErrorCode.PRODUCT_NOT_FOUND); | ||
} | ||
|
||
return BaseResponse.onSuccess(result); | ||
} | ||
|
||
/* 상품 detail 화면 조회 */ // 구현은 했으나 테스트 아직 못해봄 | ||
// @GetMapping("/product-detail") | ||
// public BaseResponse<ProductDetailResDto> findProductDetail(@RequestBody ProductReqDto req, @AuthenticationPrincipal Member member) { | ||
// if(req.getProductId() == null) { | ||
// throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); | ||
// } | ||
// | ||
// ProductDetailResDto res = productService.findProductDetail(req, member); | ||
// return BaseResponse.onSuccess(res); | ||
// } | ||
@GetMapping("/product-detail") | ||
public BaseResponse<ProductDetailResDto> findProductDetail(@RequestBody ProductReqDto req, @AuthenticationPrincipal Member member) { | ||
if(req.getProductId() == null) { | ||
throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); | ||
} | ||
|
||
ProductDetailResDto res = productService.findProductDetail(req, member); | ||
return BaseResponse.onSuccess(res); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...othly/trothcam/domain/product/Public.java → ...hly/trothcam/domain/product/PublicYn.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,5 +1,5 @@ | ||
package trothly.trothcam.domain.product; | ||
|
||
public enum Public { | ||
public enum PublicYn { | ||
Y, N | ||
} |
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
20 changes: 0 additions & 20 deletions
20
src/main/java/trothly/trothcam/exception/custom/ProductNotFoundException.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