-
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 #147 from Troth-Cam/dev
Dev
- Loading branch information
Showing
7 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/trothly/trothcam/controller/web/CertificateController.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,44 @@ | ||
package trothly.trothcam.controller.web; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
import trothly.trothcam.domain.member.Member; | ||
import trothly.trothcam.dto.web.ProductDetailResDto; | ||
import trothly.trothcam.dto.web.certificate.ProductDto; | ||
import trothly.trothcam.dto.web.certificate.PublicResDto; | ||
import trothly.trothcam.exception.base.BaseResponse; | ||
import trothly.trothcam.service.web.CertificateService; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/products") | ||
public class CertificateController { | ||
|
||
private final CertificateService certificateService; | ||
|
||
// 공개 인증서 비공개 인증서로 변환 (비공개하기[판매취소] 클릭 시) | ||
@PatchMapping("/{productId}/convert-to-private") | ||
public BaseResponse<List<ProductDto>> getPrivateCertificates(@AuthenticationPrincipal Member member, @PathVariable Long productId) { | ||
List<ProductDto> getPrivateCertificates = certificateService.getPrivateCertificates(member, productId); | ||
return BaseResponse.onSuccess(getPrivateCertificates); | ||
} | ||
|
||
// 비공개 인증서 공개 인증서로 변환 (온라인에 게시하기[판매하기] 버튼 클릭 시) | ||
@PatchMapping("/{productId}/convert-to-public") | ||
public BaseResponse<String> updatePublicCertificates(@AuthenticationPrincipal Member member, @PathVariable Long productId, @RequestBody PublicResDto publicResDto) { | ||
String result = certificateService.updatePublicCertificates(member, productId, publicResDto); | ||
return BaseResponse.onSuccess(result); | ||
} | ||
|
||
// 비공개 인증서 product detail 조회 | ||
|
||
// 공개 인증서 product detail 조회 | ||
// @GetMapping("/public/{productId}") | ||
// public BaseResponse<ProductDetailResDto> getPublicProductDetail(@PathVariable Long productId) { | ||
// ProductDetailResDto getPublicProductDetail = certificateService.getPublicProductDetail(productId); | ||
// return BaseResponse.onSuccess(getPublicProductDetail); | ||
// } | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/trothly/trothcam/dto/web/certificate/ProductDto.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,25 @@ | ||
package trothly.trothcam.dto.web.certificate; | ||
|
||
import lombok.Builder; | ||
import trothly.trothcam.domain.product.Product; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ProductDto { | ||
private Long productId; | ||
private String title; | ||
private String webToken; | ||
private Long price; | ||
private boolean isLiked; | ||
private LocalDateTime updatedAt; | ||
|
||
@Builder | ||
public ProductDto(Product product, String webToken, boolean isLiked) { | ||
this.productId = product.getId(); | ||
this.title = product.getTitle(); | ||
this.webToken = webToken; | ||
this.price = product.getPrice(); | ||
this.isLiked = isLiked; | ||
this.updatedAt = product.getLastModifiedAt(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/trothly/trothcam/dto/web/certificate/PublicResDto.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,12 @@ | ||
package trothly.trothcam.dto.web.certificate; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PublicResDto { | ||
private Long price; | ||
private String description; | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/trothly/trothcam/service/web/CertificateService.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,75 @@ | ||
package trothly.trothcam.service.web; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import trothly.trothcam.domain.image.Image; | ||
import trothly.trothcam.domain.like.LikeProduct; | ||
import trothly.trothcam.domain.like.LikeProductRepository; | ||
import trothly.trothcam.domain.member.Member; | ||
import trothly.trothcam.domain.product.Product; | ||
import trothly.trothcam.domain.product.ProductRepository; | ||
import trothly.trothcam.domain.product.PublicYn; | ||
import trothly.trothcam.dto.web.ProductDetailResDto; | ||
import trothly.trothcam.dto.web.ProductsResDto; | ||
import trothly.trothcam.dto.web.certificate.ProductDto; | ||
import trothly.trothcam.dto.web.certificate.PublicResDto; | ||
import trothly.trothcam.exception.base.BaseException; | ||
import trothly.trothcam.exception.base.ErrorCode; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CertificateService { | ||
private final ProductRepository productRepository; | ||
private final LikeProductRepository likeProductRepository; | ||
|
||
// 공개 인증서 비공개 인증서로 변환 (비공개하기[판매취소] 클릭 시) | ||
public List<ProductDto> getPrivateCertificates(Member member, Long productId) { | ||
Optional<Product> getProduct = productRepository.findById(productId); | ||
if(getProduct.isEmpty()) | ||
throw new BaseException(ErrorCode.PRODUCT_NOT_FOUND); | ||
|
||
Product product = getProduct.get(); | ||
product.updatePublicYn(PublicYn.N); // 1. 해당 인증서 비공개로 전환 | ||
productRepository.save(product); | ||
|
||
List<Product> productList = productRepository.findAllByMemberAndIdAndPublicYn(member, productId, PublicYn.N); // 2. 비공개 리스트 조회 | ||
List<ProductDto> productDtoList = productList.stream() | ||
.map(p -> { | ||
Member getMember = p.getMember(); | ||
String webToken = getMember.getWebToken(); // 1. webToken 가져오기 | ||
|
||
// 2. 좋아요 눌렀는지 체크 | ||
Optional<LikeProduct> getLikeProduct = likeProductRepository.findByProductAndMember(p, p.getMember()); | ||
boolean isLiked = getLikeProduct.isPresent(); | ||
|
||
return new ProductDto(p, webToken, isLiked); | ||
}) | ||
.collect(Collectors.toList()); | ||
|
||
return productDtoList; | ||
} | ||
|
||
// 비공개 인증서 공개 인증서로 변환 (온라인에 게시하기[판매하기] 버튼 클릭 시) | ||
public String updatePublicCertificates(Member member, Long productId, PublicResDto publicResDto) { | ||
Optional<Product> getProduct = productRepository.findById(productId); | ||
if(getProduct.isEmpty()) | ||
throw new BaseException(ErrorCode.PRODUCT_NOT_FOUND); | ||
|
||
Product product = getProduct.get(); | ||
product.updatePublicYn(PublicYn.Y); // 1. 해당 인증서 공개로 변환 | ||
product.updateInfo(publicResDto); // 2. 가격, 설명 업데이트 | ||
productRepository.save(product); | ||
|
||
return "공개 인증서로 변환 성공"; | ||
} | ||
|
||
// 비공개 인증서 product detail 조회 | ||
|
||
// 공개 인증서 product detail 조회 | ||
} |