diff --git a/src/main/java/trothly/trothcam/config/SecurityConfig.java b/src/main/java/trothly/trothcam/config/SecurityConfig.java index 21ef170..49b0168 100644 --- a/src/main/java/trothly/trothcam/config/SecurityConfig.java +++ b/src/main/java/trothly/trothcam/config/SecurityConfig.java @@ -37,7 +37,7 @@ public void configure(WebSecurity web) { "/auth/check-id/**", "/auth/signup", "/auth/login", "/auth/logout", "/h2-console/**", "/health-check", "/sample/**", "/api/image/authenticate", - "/api/product-detail", "/api/product-ranking/**", "/api/view-all/**"); + "/api/product-detail/**", "/api/product-ranking/**", "/api/view-all/**"); } // 스프링시큐리티 설정 @@ -64,7 +64,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers("/health-check").permitAll() .antMatchers("/sample/**").permitAll() .antMatchers("/api/image/authenticate").permitAll() - .antMatchers("/api/product-detail").permitAll() + .antMatchers("/api/product-detail/**").permitAll() .antMatchers("/api/product-ranking/**").permitAll() .antMatchers("/api/view-all/**").permitAll() diff --git a/src/main/java/trothly/trothcam/controller/web/HistoryController.java b/src/main/java/trothly/trothcam/controller/web/HistoryController.java index fc5096a..97ecc2b 100644 --- a/src/main/java/trothly/trothcam/controller/web/HistoryController.java +++ b/src/main/java/trothly/trothcam/controller/web/HistoryController.java @@ -2,15 +2,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import trothly.trothcam.domain.member.Member; import trothly.trothcam.dto.web.HistoryResDto; -import trothly.trothcam.dto.web.TransactionReqDto; import trothly.trothcam.exception.base.BaseResponse; -import trothly.trothcam.exception.custom.BadRequestException; import trothly.trothcam.service.web.HistoryService; @RequiredArgsConstructor @@ -20,13 +15,9 @@ public class HistoryController { private final HistoryService historyService; - @PostMapping("/transaction") - public BaseResponse saveHistory(@RequestBody TransactionReqDto req, @AuthenticationPrincipal Member member) { - if(req.getProductId() == null) { - throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); - } - - HistoryResDto res = historyService.saveTransaction(req, member); + @PostMapping("/transaction/{productId}/{price}") + public BaseResponse saveHistory(@PathVariable Long productId, @PathVariable Long price, @AuthenticationPrincipal Member member) { + HistoryResDto res = historyService.saveTransaction(productId, price, member); return BaseResponse.onSuccess(res); } } diff --git a/src/main/java/trothly/trothcam/controller/web/LikeProductController.java b/src/main/java/trothly/trothcam/controller/web/LikeProductController.java index 2bd1cba..5cf17f8 100644 --- a/src/main/java/trothly/trothcam/controller/web/LikeProductController.java +++ b/src/main/java/trothly/trothcam/controller/web/LikeProductController.java @@ -4,7 +4,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import trothly.trothcam.domain.member.Member; -import trothly.trothcam.dto.web.ProductReqDto; import trothly.trothcam.dto.web.LikeResDto; import trothly.trothcam.exception.base.BaseResponse; import trothly.trothcam.exception.custom.BadRequestException; @@ -18,24 +17,16 @@ public class LikeProductController { private final LikeProductService likeProductService; /* 좋아요 저장 */ - @PostMapping("") - public BaseResponse saveLike(@RequestBody ProductReqDto req, @AuthenticationPrincipal Member member) { - if(req.getProductId() == null) { - throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); - } - - LikeResDto res = likeProductService.saveLike(req, member); + @PostMapping("/{productId}") + public BaseResponse saveLike(@PathVariable Long productId, @AuthenticationPrincipal Member member) { + LikeResDto res = likeProductService.saveLike(productId, member); return BaseResponse.onSuccess(res); } /* 좋아요 삭제 */ - @DeleteMapping("") - public BaseResponse deleteLike(@RequestBody ProductReqDto req, @AuthenticationPrincipal Member member) { - if(req.getProductId() == null) { - throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); - } - - LikeResDto res = likeProductService.deleteLike(req, member); + @DeleteMapping("/{productId}") + public BaseResponse deleteLike(@PathVariable Long productId, @AuthenticationPrincipal Member member) { + LikeResDto res = likeProductService.deleteLike(productId, member); return BaseResponse.onSuccess(res); } } diff --git a/src/main/java/trothly/trothcam/controller/web/ProductController.java b/src/main/java/trothly/trothcam/controller/web/ProductController.java index 63f6ee8..b3ebb43 100644 --- a/src/main/java/trothly/trothcam/controller/web/ProductController.java +++ b/src/main/java/trothly/trothcam/controller/web/ProductController.java @@ -47,24 +47,16 @@ public BaseResponse> findPublicProducts( } /* 상품 detail 화면 조회 - 로그인 0*/ - @GetMapping("/product-detail/{webId}") - public BaseResponse findProductDetailOn(@PathVariable String webId, @RequestBody ProductReqDto req, @AuthenticationPrincipal Member member) { - if(req.getProductId() == null) { - throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); - } - - ProductDetailResDto res = productService.findProductDetailOn(req, member); + @GetMapping("/{webId}/product-detail/{productId}") + public BaseResponse findProductDetailOn(@PathVariable String webId, @PathVariable Long productId, @AuthenticationPrincipal Member member) { + ProductDetailResDto res = productService.findProductDetailOn(productId, member); return BaseResponse.onSuccess(res); } /* 상품 detail 화면 조회 - 로그인 X*/ - @GetMapping("/product-detail") - public BaseResponse findProductDetail(@RequestBody ProductReqDto req) { - if(req.getProductId() == null) { - throw new BadRequestException("존재하지 않는 상품 아이디 입니다."); - } - - ProductDetailResDto res = productService.findProductDetail(req); + @GetMapping("/product-detail/{productId}") + public BaseResponse findProductDetail(@PathVariable Long productId) { + ProductDetailResDto res = productService.findProductDetail(productId); return BaseResponse.onSuccess(res); } diff --git a/src/main/java/trothly/trothcam/dto/web/ProductReqDto.java b/src/main/java/trothly/trothcam/dto/web/ProductReqDto.java deleted file mode 100644 index c0ae49d..0000000 --- a/src/main/java/trothly/trothcam/dto/web/ProductReqDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package trothly.trothcam.dto.web; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class ProductReqDto { - private Long productId; -} diff --git a/src/main/java/trothly/trothcam/dto/web/ProductsPagingLikedResDto.java b/src/main/java/trothly/trothcam/dto/web/ProductsPagingLikedResDto.java deleted file mode 100644 index 30891cd..0000000 --- a/src/main/java/trothly/trothcam/dto/web/ProductsPagingLikedResDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package trothly.trothcam.dto.web; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.List; -// -//@Getter -//@NoArgsConstructor(access = AccessLevel.PROTECTED) -//@AllArgsConstructor -//public class ProductsPagingLikedResDto { -// private List getProductPagingResDto; -// private int totalPages; -//} diff --git a/src/main/java/trothly/trothcam/dto/web/TransactionReqDto.java b/src/main/java/trothly/trothcam/dto/web/TransactionReqDto.java deleted file mode 100644 index 8b59e30..0000000 --- a/src/main/java/trothly/trothcam/dto/web/TransactionReqDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package trothly.trothcam.dto.web; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class TransactionReqDto { - private Long productId; - private Long price; -} diff --git a/src/main/java/trothly/trothcam/service/web/HistoryService.java b/src/main/java/trothly/trothcam/service/web/HistoryService.java index ed60516..c0f3174 100644 --- a/src/main/java/trothly/trothcam/service/web/HistoryService.java +++ b/src/main/java/trothly/trothcam/service/web/HistoryService.java @@ -11,10 +11,7 @@ import trothly.trothcam.domain.product.ProductRepository; import trothly.trothcam.dto.web.HistoryDto; import trothly.trothcam.dto.web.HistoryResDto; -import trothly.trothcam.dto.web.ProductReqDto; -import trothly.trothcam.dto.web.TransactionReqDto; import trothly.trothcam.exception.base.BaseException; -import trothly.trothcam.exception.custom.BadRequestException; import java.util.ArrayList; import java.util.List; @@ -31,8 +28,8 @@ public class HistoryService { private final MemberRepository memberRepository; // 거래 내역 전체 조회 - public List findAllHistory(ProductReqDto req) { - List findHistories = historyRepository.findAllByProductIdOrderBySoldAtDesc(req.getProductId()); + public List findAllHistory(Long productId) { + List findHistories = historyRepository.findAllByProductIdOrderBySoldAtDesc(productId); // if(findHistories == null || findHistories.isEmpty()) { // throw new BaseException(HISTORIES_NOT_FOUND); // } @@ -48,8 +45,8 @@ public List findAllHistory(ProductReqDto req) { } // 거래 내역 저장 - public HistoryResDto saveTransaction(TransactionReqDto req, Member member) { - Product product = productRepository.findById(req.getProductId()).orElseThrow( + public HistoryResDto saveTransaction(Long productId, Long price, Member member) { + Product product = productRepository.findById(productId).orElseThrow( () -> new BaseException(PRODUCT_IS_NOT_FOUND) ); @@ -61,10 +58,10 @@ public HistoryResDto saveTransaction(TransactionReqDto req, Member member) { throw new BaseException(SAME_MEMBER); } - History newHistory = historyRepository.save(new History(product, seller, member, req.getPrice())); + History newHistory = historyRepository.save(new History(product, seller, member, price)); product.updateOwner(member); - return new HistoryResDto(newHistory.getId(), product.getId(), member.getId(), seller.getId(), req.getPrice(), newHistory.getSoldAt(), member.getId()); + return new HistoryResDto(newHistory.getId(), product.getId(), member.getId(), seller.getId(), price, newHistory.getSoldAt(), member.getId()); } } diff --git a/src/main/java/trothly/trothcam/service/web/LikeProductService.java b/src/main/java/trothly/trothcam/service/web/LikeProductService.java index 2664c42..2551343 100644 --- a/src/main/java/trothly/trothcam/service/web/LikeProductService.java +++ b/src/main/java/trothly/trothcam/service/web/LikeProductService.java @@ -8,7 +8,6 @@ import trothly.trothcam.domain.member.Member; import trothly.trothcam.domain.product.Product; import trothly.trothcam.domain.product.ProductRepository; -import trothly.trothcam.dto.web.ProductReqDto; import trothly.trothcam.dto.web.LikeResDto; import trothly.trothcam.exception.base.BaseException; import trothly.trothcam.exception.custom.BadRequestException; @@ -26,14 +25,14 @@ public class LikeProductService { private final ProductRepository productRepository; // 좋아요 저장 - public LikeResDto saveLike(ProductReqDto req, Member member) { - Optional like = likeProductRepository.findByProductIdAndMemberId(req.getProductId(), member.getId()); + public LikeResDto saveLike(Long productId, Member member) { + Optional like = likeProductRepository.findByProductIdAndMemberId(productId, member.getId()); if(like.isPresent()) { throw new BaseException(ALREADY_LIKED); } - Product product = productRepository.findById(req.getProductId()).orElseThrow( + Product product = productRepository.findById(productId).orElseThrow( () -> new BaseException(PRODUCT_IS_NOT_FOUND) ); @@ -43,8 +42,8 @@ public LikeResDto saveLike(ProductReqDto req, Member member) { } // 좋아요 삭제 - public LikeResDto deleteLike(ProductReqDto req, Member member) { - LikeProduct likeProduct = likeProductRepository.findByProductIdAndMemberId(req.getProductId(), member.getId()).orElseThrow( + public LikeResDto deleteLike(Long productId, Member member) { + LikeProduct likeProduct = likeProductRepository.findByProductIdAndMemberId(productId, member.getId()).orElseThrow( () -> new BaseException(NOT_LIKED) ); diff --git a/src/main/java/trothly/trothcam/service/web/ProductService.java b/src/main/java/trothly/trothcam/service/web/ProductService.java index 6af80ec..4eee082 100644 --- a/src/main/java/trothly/trothcam/service/web/ProductService.java +++ b/src/main/java/trothly/trothcam/service/web/ProductService.java @@ -99,10 +99,10 @@ public List findPrivateProducts(String webToken) throws BaseExce /* 상품 detail 화면 조회 - 로그인 0 */ @Transactional - public ProductDetailResDto findProductDetailOn(ProductReqDto req, Member member) { + public ProductDetailResDto findProductDetailOn(Long productId, Member member) { Boolean liked = false; - Product product = productRepository.findById(req.getProductId()).orElseThrow( + Product product = productRepository.findById(productId).orElseThrow( () -> new BaseException(PRODUCT_IS_NOT_FOUND) ); @@ -121,10 +121,10 @@ public ProductDetailResDto findProductDetailOn(ProductReqDto req, Member member) // 조회수 갱신 product.updateViews(product.getViews() + 1); - Long likes = likeProductRepository.countByProductId(req.getProductId()); + Long likes = likeProductRepository.countByProductId(productId); //좋아요 여부 - Optional isLiked = likeProductRepository.findByProductIdAndMemberId(req.getProductId(), member.getId()); + Optional isLiked = likeProductRepository.findByProductIdAndMemberId(productId, member.getId()); if(isLiked.isPresent()) { liked = true; @@ -132,19 +132,19 @@ public ProductDetailResDto findProductDetailOn(ProductReqDto req, Member member) liked = false; } - List historyDto = historyService.findAllHistory(req); + List historyDto = historyService.findAllHistory(productId); - return new ProductDetailResDto(req.getProductId(), product.getImage().getId(), findOwner.getWebToken(), findAuthorship.getWebToken(), product.getTitle(), + return new ProductDetailResDto(productId, product.getImage().getId(), findOwner.getWebToken(), findAuthorship.getWebToken(), product.getTitle(), product.getTags(), product.getPrice(), product.getDescription(),product.getViews(), likes, product.getPublicYn(), product.getCreatedAt(), product.getLastModifiedAt(), liked, historyDto); } /* 상품 detail 화면 조회 - 로그인 x */ @Transactional - public ProductDetailResDto findProductDetail(ProductReqDto req) { + public ProductDetailResDto findProductDetail(Long productId) { Boolean liked = false; - Product product = productRepository.findById(req.getProductId()).orElseThrow( + Product product = productRepository.findById(productId).orElseThrow( () -> new BaseException(PRODUCT_IS_NOT_FOUND) ); @@ -163,11 +163,11 @@ public ProductDetailResDto findProductDetail(ProductReqDto req) { // 조회수 갱신 product.updateViews(product.getViews() + 1); - Long likes = likeProductRepository.countByProductId(req.getProductId()); + Long likes = likeProductRepository.countByProductId(productId); - List historyDto = historyService.findAllHistory(req); + List historyDto = historyService.findAllHistory(productId); - return new ProductDetailResDto(req.getProductId(), product.getImage().getId(), findOwner.getWebToken(), findAuthorship.getWebToken(), product.getTitle(), + return new ProductDetailResDto(productId, product.getImage().getId(), findOwner.getWebToken(), findAuthorship.getWebToken(), product.getTitle(), product.getTags(), product.getPrice(), product.getDescription(),product.getViews(), likes, product.getPublicYn(), product.getCreatedAt(), product.getLastModifiedAt(), liked, historyDto); }