feat(store): Just pick-up 매장 메뉴 페이지 API 구현
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
package com.justpickup.storeservice;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
import com.justpickup.storeservice.domain.category.entity.Category;
|
||||
import com.justpickup.storeservice.domain.category.repository.CategoryRepository;
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.FavoriteStore;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.item.repository.ItemRepository;
|
||||
import com.justpickup.storeservice.domain.item.service.ItemService;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import com.justpickup.storeservice.domain.map.entity.Map;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
@@ -24,55 +32,79 @@ public class StoreServiceApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner run(StoreRepository storeRepository, FavoriteStoreRepository favoriteStoreRepository) {
|
||||
CommandLineRunner run(StoreRepository storeRepository, FavoriteStoreRepository favoriteStoreRepository,
|
||||
ItemRepository itemRepository, CategoryRepository categoryRepository) {
|
||||
return args -> {
|
||||
List<Store> stores = new ArrayList<>();
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "201-20"),
|
||||
Map.of(37.5398271003404, 126.94769672415691),
|
||||
1L,
|
||||
"커피온리 마포역점"
|
||||
)
|
||||
);
|
||||
createStores(storeRepository, stores);
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "50-10"),
|
||||
Map.of(37.54010719003089, 126.94556661330861),
|
||||
2L,
|
||||
"만랩커피 마포점"
|
||||
)
|
||||
);
|
||||
createFavoriteStore(favoriteStoreRepository, stores);
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "555"),
|
||||
Map.of(37.539797393793755, 126.9453578838543),
|
||||
3L,
|
||||
"이디야커피 마포오벨리스크점"
|
||||
)
|
||||
);
|
||||
stores.forEach(store -> {
|
||||
Category 카페인 = categoryRepository.save(Category.of("카페인", 0, store));
|
||||
Category 디카페인 = categoryRepository.save(Category.of("디카페인", 1, store));
|
||||
Category 티 = categoryRepository.save(Category.of("티", 2, store));
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "영등포구 도림로", "31길 2"),
|
||||
Map.of(37.493033141569505, 126.89593667847592),
|
||||
4L,
|
||||
"이디야커피 대림역점"
|
||||
)
|
||||
);
|
||||
ItemOption ice = ItemOption.of(OptionType.REQUIRED, "ICE");
|
||||
ItemOption hot = ItemOption.of(OptionType.REQUIRED, "HOT");
|
||||
|
||||
storeRepository.saveAll(stores);
|
||||
|
||||
List<Long> userList = List.of(1L,2L,3L,4L,5L,6L,7L);
|
||||
userList.forEach(userId -> {
|
||||
stores.forEach(store -> {
|
||||
favoriteStoreRepository.save(FavoriteStore.of(userId, store));
|
||||
});
|
||||
Item 아메리카노 = Item.of("아메리카노", 1500L, 카페인, store, List.of(ice, hot));
|
||||
Item 카페라떼 = Item.of("카페라떼", 2000L, 카페인, store, List.of(ice, hot));
|
||||
Item 카페모카 = Item.of("카페모카", 3900L, 카페인, store, List.of(ice, hot));
|
||||
Item 콜드브루 = Item.of("콜드브루", 2500L, 카페인, store, List.of(ice));
|
||||
Item 녹차라떼 = Item.of("녹차라떼", 3000L, 디카페인, store, List.of(ice, hot));
|
||||
Item 딸기라떼 = Item.of("딸기라떼", 3000L, 디카페인, store, List.of(ice, hot));
|
||||
Item 녹차 = Item.of("녹차", 3000L, 티, store, List.of(hot));
|
||||
Item 히비스커스 = Item.of("히비스커스 티", 3000L, 티, store, List.of(hot));
|
||||
itemRepository.saveAll(List.of(아메리카노, 카페라떼, 콜드브루, 녹차라떼, 딸기라떼, 녹차, 히비스커스));
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private void createFavoriteStore(FavoriteStoreRepository favoriteStoreRepository, List<Store> stores) {
|
||||
List<Long> userList = List.of(1L,2L,3L,4L,5L,6L,7L);
|
||||
userList.forEach(userId -> stores.forEach(store -> favoriteStoreRepository.save(FavoriteStore.of(userId, store))));
|
||||
}
|
||||
|
||||
private void createStores(StoreRepository storeRepository, List<Store> stores) {
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "201-20"),
|
||||
Map.of(37.5398271003404, 126.94769672415691),
|
||||
1L,
|
||||
"커피온리 마포역점"
|
||||
)
|
||||
);
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "50-10"),
|
||||
Map.of(37.54010719003089, 126.94556661330861),
|
||||
2L,
|
||||
"만랩커피 마포점"
|
||||
)
|
||||
);
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "마포구 도화동", "555"),
|
||||
Map.of(37.539797393793755, 126.9453578838543),
|
||||
3L,
|
||||
"이디야커피 마포오벨리스크점"
|
||||
)
|
||||
);
|
||||
|
||||
stores.add(
|
||||
Store.of(
|
||||
new Address("서울시", "영등포구 도림로", "31길 2"),
|
||||
Map.of(37.493033141569505, 126.89593667847592),
|
||||
4L,
|
||||
"이디야커피 대림역점"
|
||||
)
|
||||
);
|
||||
|
||||
storeRepository.saveAll(stores);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.justpickup.storeservice.domain.category.repository.CategoryRepository
|
||||
import com.justpickup.storeservice.domain.category.repository.CategoryRepositoryCustom;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.global.exception.CustomException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -27,7 +26,7 @@ public class CategoryService {
|
||||
private final CategoryRepositoryCustom categoryRepositoryCustom;
|
||||
private final StoreRepository storeRepository;
|
||||
|
||||
public List<CategoryDto> getCategoryList(Long storeId){
|
||||
public List<CategoryDto> getCategoriesWithItem(Long storeId){
|
||||
|
||||
return categoryRepositoryCustom.getCategoryList(storeId)
|
||||
.stream()
|
||||
@@ -74,6 +73,6 @@ public class CategoryService {
|
||||
.orElseThrow(() -> new NotFoundStoreException(HttpStatus.BAD_REQUEST,"존재하지않는 Category")));
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.justpickup.storeservice.domain.category.web;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
import com.justpickup.storeservice.domain.category.service.CategoryService;
|
||||
import com.justpickup.storeservice.global.dto.Result;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/customer/")
|
||||
public class CategoryCustomerApiController {
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<Result> getCategories(@RequestParam("storeId") Long storeId) {
|
||||
List<CategoryDto> categoryList = categoryService.getCategoriesWithItem(storeId);
|
||||
|
||||
GetCategoriesResponse getCategoriesResponse = new GetCategoriesResponse(categoryList);
|
||||
|
||||
return ResponseEntity.ok(Result.createSuccessResult(getCategoriesResponse));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor
|
||||
static class GetCategoriesResponse {
|
||||
private List<_Category> categories;
|
||||
|
||||
public GetCategoriesResponse(List<CategoryDto> categoryDtoList) {
|
||||
this. categories = categoryDtoList
|
||||
.stream()
|
||||
.map(_Category::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class _Category {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Integer order;
|
||||
private List<_Item> items;
|
||||
|
||||
public _Category(CategoryDto categoryDto) {
|
||||
List<_Item> items = categoryDto.getItems()
|
||||
.stream()
|
||||
.map(itemDto -> new _Item(itemDto.getId(), itemDto.getName(), itemDto.getPrice()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
this.id = categoryDto.getId();
|
||||
this.name = categoryDto.getName();
|
||||
this.order = categoryDto.getOrder();
|
||||
this.items = items;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
static class _Item {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Long price;
|
||||
|
||||
public _Item(Long id, String name, Long price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class CategoryOwnerApiController {
|
||||
@GetMapping("/category")
|
||||
public ResponseEntity getCategoryList(@RequestHeader(value = "user-id") String userId ){
|
||||
Long storeId = Long.parseLong(userId);
|
||||
List<CategoryDto> categoryList = categoryService.getCategoryList(storeId);
|
||||
List<CategoryDto> categoryList = categoryService.getCategoriesWithItem(storeId);
|
||||
|
||||
List<CategoryResponse> categoryResponseList = categoryList.stream()
|
||||
.map(CategoryResponse::new)
|
||||
|
||||
@@ -20,9 +20,7 @@ import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -61,7 +59,7 @@ public class ItemServiceImpl implements ItemService {
|
||||
|
||||
Page<Item> itemList = itemRepositoryCustom.findItem(storeId,word,pageable);
|
||||
return PageableExecutionUtils.getPage(itemList.stream()
|
||||
.map(ItemDto::createWithCategoryItemDto)
|
||||
.map(ItemDto::createWithCategory)
|
||||
.collect(Collectors.toList()),pageable,itemList::getTotalElements);
|
||||
}
|
||||
|
||||
@@ -106,9 +104,7 @@ public class ItemServiceImpl implements ItemService {
|
||||
|
||||
List<ItemOption> itemOptions = itemOptionDtos
|
||||
.stream()
|
||||
.map(itemOptionDto -> {
|
||||
return ItemOption.of(itemOptionDto.getOptionType(), itemOptionDto.getName());
|
||||
})
|
||||
.map(itemOptionDto -> ItemOption.of(itemOptionDto.getOptionType(), itemOptionDto.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Item createdItem = Item.of(itemName, itemPrice, category, store, itemOptions);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.justpickup.storeservice.domain.store.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class StoreDto {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String phoneNumber;
|
||||
|
||||
public StoreDto(Store store) {
|
||||
this.id = store.getId();
|
||||
this.name = store.getName();
|
||||
this.phoneNumber = store.getPhoneNumber();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.FetchType.LAZY;
|
||||
@@ -48,13 +49,14 @@ public class Store extends BaseEntity {
|
||||
private Long userId;
|
||||
|
||||
@OneToMany(mappedBy = "store")
|
||||
private List<Category> categories;
|
||||
private List<Category> categories = new ArrayList<>();
|
||||
|
||||
@OneToMany(mappedBy = "store")
|
||||
private List<Item> items;
|
||||
private List<Item> items = new ArrayList<>();
|
||||
|
||||
@OneToMany(mappedBy = "store")
|
||||
private List<FavoriteStore> favoriteStores;
|
||||
private List<FavoriteStore> favoriteStores = new ArrayList<>();
|
||||
|
||||
// == 연관관계 편의 메소드 == //
|
||||
public void addCategory(Category category) {
|
||||
categories.add(category);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.justpickup.storeservice.domain.store.exception;
|
||||
|
||||
import com.justpickup.storeservice.global.exception.CustomException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NotExistStoreException extends CustomException {
|
||||
|
||||
public NotExistStoreException(String message) {
|
||||
super(HttpStatus.CONFLICT, message);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.justpickup.storeservice.domain.store.service;
|
||||
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreDto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
|
||||
@@ -10,4 +11,5 @@ import java.util.List;
|
||||
public interface StoreService {
|
||||
SliceImpl<SearchStoreResult> findSearchStoreScroll(SearchStoreCondition condition, Pageable pageable);
|
||||
List<SearchStoreResult> findFavoriteStore(SearchStoreCondition condition, Long userId);
|
||||
StoreDto findStore(Long storeId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.justpickup.storeservice.domain.store.service;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreCustom;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreDto;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.exception.NotExistStoreException;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepositoryCustom;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -10,7 +14,6 @@ import org.springframework.data.domain.SliceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -18,6 +21,7 @@ public class StoreServiceImpl implements StoreService {
|
||||
|
||||
private final StoreRepositoryCustom storeRepositoryCustom;
|
||||
private final FavoriteStoreCustom favoriteStoreCustom;
|
||||
private final StoreRepository storeRepository;
|
||||
|
||||
@Override
|
||||
public SliceImpl<SearchStoreResult> findSearchStoreScroll(SearchStoreCondition condition, Pageable pageable) {
|
||||
@@ -41,4 +45,12 @@ public class StoreServiceImpl implements StoreService {
|
||||
});
|
||||
return favoriteStores;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoreDto findStore(Long storeId) {
|
||||
Store store = storeRepository.findById(storeId)
|
||||
.orElseThrow(() -> new NotExistStoreException(storeId + "는 없는 매장 고유번호입니다."));
|
||||
|
||||
return new StoreDto(store);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.justpickup.storeservice.domain.store.web;
|
||||
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreDto;
|
||||
import com.justpickup.storeservice.domain.store.service.StoreService;
|
||||
import com.justpickup.storeservice.global.dto.Result;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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;
|
||||
|
||||
@@ -9,4 +17,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/store")
|
||||
public class StoreController {
|
||||
|
||||
private final StoreService storeService;
|
||||
|
||||
@GetMapping("/{storeId}")
|
||||
public ResponseEntity<Result> getStore(@PathVariable("storeId") Long storeId) {
|
||||
StoreDto storeDto = storeService.findStore(storeId);
|
||||
|
||||
GetStoreResponse getStoreResponse = new GetStoreResponse(storeDto);
|
||||
return ResponseEntity.ok(Result.createSuccessResult(getStoreResponse));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor
|
||||
static class GetStoreResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String phoneNumber;
|
||||
|
||||
public GetStoreResponse(StoreDto storeDto) {
|
||||
this.id = storeDto.getId();
|
||||
this.name = storeDto.getName();
|
||||
this.phoneNumber = storeDto.getPhoneNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class CategoryOwnerApiControllerTest {
|
||||
.order(2)
|
||||
.build());
|
||||
|
||||
given(categoryService.getCategoryList(any())).willReturn(categoryDtoList);
|
||||
given(categoryService.getCategoriesWithItem(any())).willReturn(categoryDtoList);
|
||||
//when
|
||||
|
||||
ResultActions actions = mockMvc.perform(MockMvcRequestBuilders.get("/api/owner/category")
|
||||
|
||||
Reference in New Issue
Block a user