Skip to content

Commit

Permalink
[ feat ] Get store & product info with auth member
Browse files Browse the repository at this point in the history
  • Loading branch information
Minuooooo committed Aug 23, 2023
1 parent d5e0642 commit fdf6aff
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
import greeny.backend.domain.product.dto.GetSimpleProductInfosResponseDto;
import greeny.backend.domain.product.entity.Product;
import greeny.backend.domain.product.service.ProductService;
import greeny.backend.domain.review.entity.ProductReview;
import greeny.backend.domain.review.entity.StoreReview;
import greeny.backend.domain.store.dto.GetSimpleStoreInfosResponseDto;
import greeny.backend.domain.store.entity.Store;
import greeny.backend.domain.store.service.StoreService;
import greeny.backend.exception.situation.ProductNotFound;
import greeny.backend.exception.situation.StoreNotFound;
import greeny.backend.exception.situation.TypeDoesntExistsException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -26,9 +22,6 @@
import java.util.List;
import java.util.Optional;

import static greeny.backend.domain.review.dto.GetReviewListResponseDto.toProductReviewDTO;
import static greeny.backend.domain.review.dto.GetReviewListResponseDto.toStoreReviewDTO;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -73,15 +66,17 @@ public void toggleStoreBookmark(String type, Long id, Member liker) { // 타입
}

private void checkAndToggleStoreBookmarkBySituation(Store store, Member liker) { // 찜한 정보 DB에 저장 or 취소 시 DB 에서 삭제
Optional<StoreBookmark> storeBookmark = storeBookmarkRepository.findByStoreIdAndLikerId(store.getId(), liker.getId());
Optional<StoreBookmark> storeBookmark = getOptionalStoreBookmark(store.getId(), liker.getId());

if(storeBookmark.isPresent())
storeBookmarkRepository.delete(storeBookmark.get());
else
storeBookmarkRepository.save(toEntity(store, liker));
}

private void toggleProductBookmark(Product product, Member liker) { // 찜한 정보 DB에 저장 or 취소 시 DB 에서 삭제
Optional<ProductBookmark> productBookmark = productBookmarkRepository.findByProductIdAndLikerId(product.getId(), liker.getId());
Optional<ProductBookmark> productBookmark = getOptionalProductBookmark(product.getId(), liker.getId());

if(productBookmark.isPresent())
productBookmarkRepository.delete(productBookmark.get());
else
Expand All @@ -101,4 +96,12 @@ private ProductBookmark toEntity(Product product, Member liker) {
.liker(liker)
.build();
}

public Optional<StoreBookmark> getOptionalStoreBookmark(Long storeId, Long likerId) {
return storeBookmarkRepository.findByStoreIdAndLikerId(storeId, likerId);
}

public Optional<ProductBookmark> getOptionalProductBookmark(Long productId, Long likerId) {
return productBookmarkRepository.findByProductIdAndLikerId(productId, likerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public Response getSimpleProductInfosWithAuthMember(@RequestParam(required = fal
public Response getProductInfo(Long productId){
return success(SUCCESS_TO_GET_PRODUCT_INFO, productService.getProductInfo(productId));
}

// 인증된 사용자에 대한 제품 상세 조회 API
@Operation(summary = "Get product info with auth member API", description = "put product id what you want to see.")
@ResponseStatus(OK)
@GetMapping("/auth")
public Response getProductInfoWithAuthMember(Long productId){
return success(
SUCCESS_TO_GET_PRODUCT_INFO,
productService.getProductInfoWithAuthMember(
productId,
bookmarkService.getOptionalProductBookmark(productId, memberService.getCurrentMember().getId())
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class GetProductInfoResponseDto {
private Integer deliveryFee;
private String contentUrl;
private String phone;
private Boolean isBookmarked;

public static GetProductInfoResponseDto from(Product product) {
public static GetProductInfoResponseDto from(Product product, boolean isBookmarked) {
return GetProductInfoResponseDto.builder()
.id(product.getId())
.name(product.getName())
Expand All @@ -32,6 +33,7 @@ public static GetProductInfoResponseDto from(Product product) {
.deliveryFee(product.getDeliveryFee())
.contentUrl(product.getContentUrl())
.phone(product.getStore().getPhone())
.isBookmarked(isBookmarked)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -59,7 +60,15 @@ public Page<GetSimpleProductInfosResponseDto> getSimpleProductInfosWithAuthMembe
// 제품 상세정보 조회
public GetProductInfoResponseDto getProductInfo(Long productId){
Product foundProduct = getProduct(productId);
return GetProductInfoResponseDto.from(foundProduct);
return GetProductInfoResponseDto.from(foundProduct, false);
}

public GetProductInfoResponseDto getProductInfoWithAuthMember(Long productId, Optional<ProductBookmark> optionalProductBookmark) {

if(optionalProductBookmark.isPresent())
return GetProductInfoResponseDto.from(getProduct(productId), true);

return GetProductInfoResponseDto.from(getProduct(productId), false);
}

public Product getProduct(Long productId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ public Response getSimpleStoreInfosWithAuthMember(
public Response getStoreInfo(Long storeId) {
return success(SUCCESS_TO_GET_STORE_INFO, storeService.getStoreInfo(storeId));
}

// 인증된 사용자에 대한 스토어 상세 정보 API
@Operation(summary = "Get store info with auth member API", description = "put store id what you want to see.")
@ResponseStatus(OK)
@GetMapping("/auth")
public Response getStoreInfoWithAuthMember(Long storeId) {
return success(
SUCCESS_TO_GET_STORE_INFO,
storeService.getStoreInfoWithAuthMember(
storeId,
bookmarkService.getOptionalStoreBookmark(storeId, memberService.getCurrentMember().getId())
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class GetStoreInfoResponseDto { // 스토어 상세 정보
private String imageUrl;
private String location;
private String phone;
private Boolean isBookmarked;

public static GetStoreInfoResponseDto from(Store store) {
public static GetStoreInfoResponseDto from(Store store, boolean isBookmarked) {
return GetStoreInfoResponseDto.builder()
.id(store.getId())
.category(store.getCategory())
Expand All @@ -28,6 +29,7 @@ public static GetStoreInfoResponseDto from(Store store) {
.imageUrl(store.getImageUrl())
.location(store.getLocation())
.phone(store.getPhone())
.isBookmarked(isBookmarked)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -40,7 +41,15 @@ public Page<GetSimpleStoreInfosResponseDto> getSimpleStoreInfosWithAuthMember(St
);
}
public GetStoreInfoResponseDto getStoreInfo(Long storeId) { // Store 상세 정보 가져오기
return GetStoreInfoResponseDto.from(getStore(storeId));
return GetStoreInfoResponseDto.from(getStore(storeId), false);
}

public GetStoreInfoResponseDto getStoreInfoWithAuthMember(Long storeId, Optional<StoreBookmark> optionalStoreBookmark) {

if(optionalStoreBookmark.isPresent())
return GetStoreInfoResponseDto.from(getStore(storeId), true);

return GetStoreInfoResponseDto.from(getStore(storeId), false);
}

public Store getStore(Long storeId) { // Id 값을 통해 Store 객체 가져오기
Expand Down

0 comments on commit fdf6aff

Please sign in to comment.