Skip to content

Commit

Permalink
Merge pull request #84 from team-ecolink/feature/product
Browse files Browse the repository at this point in the history
  • Loading branch information
uuujini authored Feb 7, 2024
2 parents bfcec4c + 0e8e5cc commit eacd8d4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.ecolink.core.product.controller;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecolink.core.auth.token.UserPrincipal;
import com.ecolink.core.common.response.ApiCursorPageResponse;
import com.ecolink.core.product.dto.request.GetStoreProductRequest;
import com.ecolink.core.product.dto.response.GetStoreProductResponse;
import com.ecolink.core.product.service.StoreProductSearchService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
Expand All @@ -37,4 +41,18 @@ public ApiCursorPageResponse<GetStoreProductResponse, Long> searchStoreProducts(
return ApiCursorPageResponse.ok(storeProductSearchService.searchStoreProducts(storeId, request));
}

@Tag(name = "${swagger.tag.manager}")
@Operation(summary = "점주 매장 판매 제품 목록 조회 API- 인증 필요",
description = "점주 매장 판매 제품 목록 조회 API - 인증 필요",
security = {@SecurityRequirement(name = "session-token")})
@PreAuthorize("hasRole('MANAGER')")
@GetMapping("/m/stores/{id}/products")
public ApiCursorPageResponse<GetStoreProductResponse, Long> searchStoreProductsByManager(
@Valid @ParameterObject GetStoreProductRequest request,
@PathVariable("id") @NotNull @Positive Long storeId,
@AuthenticationPrincipal UserPrincipal principal) {
return ApiCursorPageResponse.ok(
storeProductSearchService.searchStoreProductsByManager(storeId, request, principal));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ecolink.core.common.domain.BaseTimeEntity;
import com.ecolink.core.store.domain.Store;
import com.ecolink.core.tag.domain.Product;
import com.ecolink.core.tag.domain.Tag;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -47,4 +48,9 @@ public class StoreProduct extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Product product;

@NotNull
@JoinColumn(name = "tag_id")
@ManyToOne(fetch = FetchType.LAZY)
private Tag tag;

}
36 changes: 0 additions & 36 deletions src/main/java/com/ecolink/core/product/domain/StoreProductTag.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.ecolink.core.product.domain.QStoreProduct.*;
import static com.ecolink.core.product.domain.QStoreProductPhoto.*;
import static com.ecolink.core.product.domain.QStoreProductTag.*;
import static com.ecolink.core.tag.domain.QProduct.*;
import static com.ecolink.core.tag.domain.QTag.*;

Expand All @@ -28,7 +27,8 @@ public StoreProductJpaRepository(EntityManager entityManager) {
this.queryFactory = new JPAQueryFactory(entityManager);
}

public List<GetStoreProductResponse> queryByNameAndTag(Long storeId, GetStoreProductRequest request, Boolean onSale) {
public List<GetStoreProductResponse> queryByNameAndTag(Long storeId, GetStoreProductRequest request,
Boolean onSale) {

JPAQuery<GetStoreProductResponse> common = queryFactory.select(new QGetStoreProductResponse(
storeProduct,
Expand Down Expand Up @@ -56,14 +56,11 @@ private static JPAQuery<GetStoreProductResponse> withCondition(JPAQuery<GetStore
builder.and(product.name.contains(request.getKeyword()));

if (request.getTagId() != null) {
common.leftJoin(storeProductTag)
.on(storeProductTag.storeProduct.eq(storeProduct))
.join(tag)
.on(tag.eq(storeProductTag.tag));
common.join(storeProduct.tag, tag);
builder.and(tag.id.eq(request.getTagId()));
}

if(onSale != null)
if (onSale != null)
builder.and(storeProduct.onSale.eq(onSale));

return common.where(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ecolink.core.auth.token.UserPrincipal;
import com.ecolink.core.common.dto.CursorPage;
import com.ecolink.core.common.error.ErrorCode;
import com.ecolink.core.common.error.exception.ManagerForbiddenException;
import com.ecolink.core.common.util.AuthorityUtil;
import com.ecolink.core.product.dto.request.GetStoreProductRequest;
import com.ecolink.core.product.dto.response.GetStoreProductResponse;
import com.ecolink.core.tag.constant.TagCategory;
Expand All @@ -27,4 +31,16 @@ public CursorPage<GetStoreProductResponse, Long> searchStoreProducts(Long storeI
GetStoreProductResponse::getId);
}

public CursorPage<GetStoreProductResponse, Long> searchStoreProductsByManager(Long storeId,
GetStoreProductRequest request, UserPrincipal principal) {
if(!principal.isManagerOf(storeId) && !AuthorityUtil.hasAdminAuthority(principal))
throw new ManagerForbiddenException(ErrorCode.NOT_MANAGER_OF_STORE);

if (request.getTagId() != null)
tagService.validateCategory(request.getTagId(), TagCategory.PRODUCT);

return CursorPage.of(storeProductService.getByNameAndTag(storeId, request, null), request.getSize(),
GetStoreProductResponse::getId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void addTop3StoreProductsToDto(StoreSearchDto dto) {
}
}

public List<GetStoreProductResponse> getByNameAndTag(Long storeId, GetStoreProductRequest request, boolean onSale) {
public List<GetStoreProductResponse> getByNameAndTag(Long storeId, GetStoreProductRequest request, Boolean onSale) {
return storeProductJpaRepository.queryByNameAndTag(storeId, request, onSale);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ swagger:
my-page: '04. 마이페이지'
store: '05. 매장 상세 페이지'
bookmark: '06. 북마크'
manager: '07. 매장 관리페이지'
account: '08. 계정 관리페이지'
tag: '10.태그'

0 comments on commit eacd8d4

Please sign in to comment.