fix(store): Just Pick-up 매장 아이템 정보 버그 픽스

원인: 카테고리 및 아이템 정보를 유저 아이디로 가져오게 설정되어있었다.
해결: 스토어 아이디를 통해 정보를 가져오도록 변경
This commit is contained in:
bum12ark
2022-03-17 15:42:42 +09:00
parent 50f56860e1
commit 92097150ea
4 changed files with 23 additions and 17 deletions

View File

@@ -4,7 +4,6 @@ import com.justpickup.storeservice.domain.category.entity.Category;
import com.justpickup.storeservice.domain.category.entity.QCategory;
import com.justpickup.storeservice.domain.item.entity.QItem;
import com.justpickup.storeservice.domain.store.entity.QStore;
import com.querydsl.core.QueryFactory;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
@@ -17,21 +16,25 @@ public class CategoryRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;
public List<Category> getCategoryList(Long userId){
public List<Category> getCategoryListByUserId(Long userId){
List<Category> categoryList = jpaQueryFactory.selectFrom(QCategory.category)
return jpaQueryFactory.selectFrom(QCategory.category)
.leftJoin(QCategory.category.items, QItem.item).fetchJoin()
.join(QCategory.category.store, QStore.store).fetchJoin()
.where(QCategory.category.store.userId.eq(userId))
.orderBy(QCategory.category.order.asc())
.distinct()
.fetch();
return categoryList;
}
public List<Category> getCategoryListById(Long storeId){
return jpaQueryFactory.selectFrom(QCategory.category)
.leftJoin(QCategory.category.items, QItem.item).fetchJoin()
.join(QCategory.category.store, QStore.store).fetchJoin()
.where(QCategory.category.store.id.eq(storeId))
.orderBy(QCategory.category.order.asc())
.distinct()
.fetch();
}
}

View File

@@ -26,9 +26,15 @@ public class CategoryService {
private final CategoryRepositoryCustom categoryRepositoryCustom;
private final StoreRepository storeRepository;
public List<CategoryDto> getCategoriesWithItem(Long storeId){
public List<CategoryDto> getCategoriesWithItemByUserId(Long userId){
return categoryRepositoryCustom.getCategoryListByUserId(userId)
.stream()
.map(CategoryDto::new)
.collect(Collectors.toList());
}
return categoryRepositoryCustom.getCategoryList(storeId)
public List<CategoryDto> getCategoriesWithItemById(Long storeId){
return categoryRepositoryCustom.getCategoryListById(storeId)
.stream()
.map(CategoryDto::new)
.collect(Collectors.toList());

View File

@@ -24,7 +24,7 @@ public class CategoryCustomerApiController {
@GetMapping("/categories")
public ResponseEntity<Result> getCategories(@RequestParam("storeId") Long storeId) {
List<CategoryDto> categoryList = categoryService.getCategoriesWithItem(storeId);
List<CategoryDto> categoryList = categoryService.getCategoriesWithItemById(storeId);
GetCategoriesResponse getCategoriesResponse = new GetCategoriesResponse(categoryList);

View File

@@ -22,21 +22,18 @@ public class CategoryOwnerApiController {
private final CategoryService categoryService;
@GetMapping("/category")
public ResponseEntity getCategoryList(@RequestHeader(value = "user-id") String userId ){
Long storeId = Long.parseLong(userId);
List<CategoryDto> categoryList = categoryService.getCategoriesWithItem(storeId);
public ResponseEntity getCategoryList(@RequestHeader(value = "user-id") String userHeader){
Long userId = Long.parseLong(userHeader);
List<CategoryDto> categoryList = categoryService.getCategoriesWithItemByUserId(userId);
List<CategoryResponse> categoryResponseList = categoryList.stream()
.map(CategoryResponse::new)
.collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.OK)
.body(Result.createSuccessResult(categoryResponseList));
}
@Data
static class CategoryResponse{
private Long categoryId;