Merge remote-tracking branch 'origin/master'
# Conflicts: # store-service/src/main/java/com/justpickup/storeservice/domain/category/service/CategoryService.java # store-service/src/main/java/com/justpickup/storeservice/domain/category/web/CategoryOwnerApiController.java
This commit is contained in:
@@ -95,8 +95,8 @@ operation::put-categoryList[snippets='curl-request,http-request,http-response,re
|
||||
== 매장
|
||||
=== 매장 검색 조회
|
||||
operation::api-customer-store-search[snippets='curl-request,http-request,http-response,request-parameters,response-fields']
|
||||
|
||||
=== 자주찾는 매장
|
||||
operation::favoriteStore-get[snippets='curl-request,http-request,http-response,request-headers,request-parameters,response-fields']
|
||||
|
||||
=== 매장 조회
|
||||
operation::store-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
package com.justpickup.storeservice;
|
||||
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.FavoriteStore;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.map.entity.Map;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.global.entity.Address;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@@ -23,56 +12,4 @@ public class StoreServiceApplication {
|
||||
SpringApplication.run(StoreServiceApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner run(StoreRepository storeRepository, FavoriteStoreRepository favoriteStoreRepository) {
|
||||
return args -> {
|
||||
List<Store> stores = new ArrayList<>();
|
||||
|
||||
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);
|
||||
|
||||
List<Long> userList = List.of(1L,2L,3L,4L,5L,6L,7L);
|
||||
userList.forEach(userId -> {
|
||||
stores.forEach(store -> {
|
||||
favoriteStoreRepository.save(FavoriteStore.of(userId, store));
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,11 @@ public class Category extends BaseEntity {
|
||||
return new Category(id,name,order,store);
|
||||
}
|
||||
|
||||
public static Category of(String name, Integer order, Store store) {
|
||||
Category category = new Category();
|
||||
category.name = name;
|
||||
category.order = order;
|
||||
category.store = store;
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,9 +26,9 @@ public class CategoryService {
|
||||
private final CategoryRepositoryCustom categoryRepositoryCustom;
|
||||
private final StoreRepository storeRepository;
|
||||
|
||||
public List<CategoryDto> getCategoryList(Long userId){
|
||||
public List<CategoryDto> getCategoriesWithItem(Long storeId){
|
||||
|
||||
return categoryRepositoryCustom.getCategoryList(userId)
|
||||
return categoryRepositoryCustom.getCategoryList(storeId)
|
||||
.stream()
|
||||
.map(CategoryDto::new)
|
||||
.collect(Collectors.toList());
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ public class CategoryOwnerApiController {
|
||||
|
||||
@GetMapping("/category")
|
||||
public ResponseEntity getCategoryList(@RequestHeader(value = "user-id") String userId ){
|
||||
List<CategoryDto> categoryList = categoryService.getCategoryList(Long.parseLong(userId));
|
||||
Long storeId = Long.parseLong(userId);
|
||||
List<CategoryDto> categoryList = categoryService.getCategoriesWithItem(storeId);
|
||||
|
||||
List<CategoryResponse> categoryResponseList = categoryList.stream()
|
||||
.map(CategoryResponse::new)
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ItemDto {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ItemDto createWithCategoryItemDto(Item item) {
|
||||
public static ItemDto createWithCategory(Item item) {
|
||||
return ItemDto.builder()
|
||||
.id(item.getId())
|
||||
.name(item.getName())
|
||||
@@ -79,9 +79,4 @@ public class ItemDto {
|
||||
.build();
|
||||
}
|
||||
|
||||
// TODO: 2022/02/03 queryDsl 쿼리 생성 시 구현 필요
|
||||
// public static ItemDto createFullItemDto(Item item) {
|
||||
// return null
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,9 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.PERSIST;
|
||||
import static javax.persistence.CascadeType.REMOVE;
|
||||
import static javax.persistence.FetchType.LAZY;
|
||||
|
||||
@Entity
|
||||
@@ -45,8 +43,8 @@ public class Item extends BaseEntity {
|
||||
@JoinColumn(name = "store_id")
|
||||
private Store store;
|
||||
|
||||
@OneToMany(mappedBy = "item" ,cascade = {REMOVE,PERSIST} )
|
||||
private List<ItemOption> itemOptions;
|
||||
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL)
|
||||
private List<ItemOption> itemOptions = new ArrayList<>();
|
||||
|
||||
// == 연관관계 편의 메소드 ==//
|
||||
public void addItemOption(ItemOption itemOption) {
|
||||
@@ -71,19 +69,15 @@ public class Item extends BaseEntity {
|
||||
}
|
||||
|
||||
// == 생성 메소드 == //
|
||||
public static Item createdItem(Category category, Store store, List<ItemOption> itemOptions) {
|
||||
public static Item of(String name, Long price, Category category, Store store, List<ItemOption> itemOptions) {
|
||||
Item item = new Item();
|
||||
item.setCategory(category);
|
||||
item.setStore(store);
|
||||
itemOptions.forEach(item::addItemOption);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static Item createdFullItem(Category category, Store store, List<ItemOption> itemOptions, String name , Long price) {
|
||||
Item item = new Item();
|
||||
item.setItemNameAndPriceAndCategory( name, price ,category);
|
||||
item.setStore(store);
|
||||
itemOptions.forEach(item::addItemOption);
|
||||
item.name = name;
|
||||
item.price = price;
|
||||
item.category = category;
|
||||
item.store = store;
|
||||
for (ItemOption itemOption : itemOptions) {
|
||||
item.addItemOption(itemOption);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.justpickup.storeservice.domain.item.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ItemRepository extends JpaRepository<Item, Long> {
|
||||
|
||||
List<Item> findByStore(Store store);
|
||||
}
|
||||
|
||||
@@ -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(userId,word,pageable);
|
||||
return PageableExecutionUtils.getPage(itemList.stream()
|
||||
.map(ItemDto::createWithCategoryItemDto)
|
||||
.map(ItemDto::createWithCategory)
|
||||
.collect(Collectors.toList()),pageable,itemList::getTotalElements);
|
||||
}
|
||||
|
||||
@@ -96,7 +94,6 @@ public class ItemServiceImpl implements ItemService {
|
||||
Long itemPrice,
|
||||
Long categoryId,
|
||||
List<ItemOptionDto> itemOptionDtos) {
|
||||
|
||||
//find Store
|
||||
Store store = storeRepository.findByUserId(userId)
|
||||
.orElseThrow(() -> new NotExistItemException("존재하지 않는 매장 입니다."));
|
||||
@@ -105,11 +102,13 @@ public class ItemServiceImpl implements ItemService {
|
||||
Category category = categoryRepository.findById(categoryId)
|
||||
.orElseThrow(() -> new NotExistItemException("존재하지 않는 카테고리 입니다."));
|
||||
|
||||
//create Item
|
||||
Item item = Item.createdFullItem(category,store,new ArrayList<>() ,itemName, itemPrice);
|
||||
List<ItemOption> itemOptions = itemOptionDtos
|
||||
.stream()
|
||||
.map(itemOptionDto -> ItemOption.of(itemOptionDto.getOptionType(), itemOptionDto.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//add ItemOption
|
||||
itemOptionDtos.forEach((itemOptionDto ->
|
||||
itemOptionRepository.save(ItemOptionDto.createItemOption(itemOptionDto, item))));
|
||||
Item createdItem = Item.of(itemName, itemPrice, category, store, itemOptions);
|
||||
|
||||
itemRepository.save(createdItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,10 +128,8 @@ public class ItemOwnerApiController {
|
||||
private String name;
|
||||
|
||||
public ItemOptionResponse(ItemOptionDto itemOptionDto) {
|
||||
|
||||
this.id = itemOptionDto.getId();
|
||||
this.optionType = itemOptionDto.getOptionType();
|
||||
this.price = itemOptionDto.getPrice();
|
||||
this.name = itemOptionDto.getName();
|
||||
}
|
||||
}
|
||||
@@ -181,13 +179,11 @@ public class ItemOwnerApiController {
|
||||
private Long id;
|
||||
private String name;
|
||||
private OptionType optionType;
|
||||
private Long price;
|
||||
|
||||
public static ItemOptionDto createItemOptionDto(ItemOptionRequest itemOptionRequest){
|
||||
return ItemOptionDto.builder()
|
||||
.id(itemOptionRequest.getId())
|
||||
.name(itemOptionRequest.getName())
|
||||
.price(itemOptionRequest.getPrice())
|
||||
.optionType(itemOptionRequest.getOptionType())
|
||||
.build();
|
||||
|
||||
|
||||
@@ -20,20 +20,15 @@ public class ItemOptionDto {
|
||||
|
||||
private OptionType optionType;
|
||||
|
||||
private Long price;
|
||||
|
||||
private String name;
|
||||
|
||||
public ItemOptionDto (ItemOption itemOption){
|
||||
this.id = itemOption.getId();
|
||||
this.optionType = itemOption.getOptionType();
|
||||
this.price = itemOption.getPrice();
|
||||
this.name = itemOption.getName();
|
||||
}
|
||||
|
||||
public static ItemOption createItemOption (ItemOptionDto itemOptionDto, Item item){
|
||||
|
||||
return new ItemOption(itemOptionDto.getOptionType(),itemOptionDto.getPrice(),itemOptionDto.getName(),item);
|
||||
|
||||
return new ItemOption(itemOptionDto.getOptionType(), itemOptionDto.getName(),item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ public class ItemOption extends BaseEntity {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private OptionType optionType;
|
||||
|
||||
private Long price;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToOne(fetch = LAZY , cascade = CascadeType.ALL)
|
||||
@@ -36,10 +34,16 @@ public class ItemOption extends BaseEntity {
|
||||
item.getItemOptions().add(this);
|
||||
}
|
||||
|
||||
public ItemOption(OptionType optionType, Long price, String name, Item item) {
|
||||
public ItemOption(OptionType optionType, String name, Item item) {
|
||||
this.optionType = optionType;
|
||||
this.price = price;
|
||||
this.name = name;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public static ItemOption of(OptionType type, String name) {
|
||||
ItemOption itemOption = new ItemOption();
|
||||
itemOption.optionType = type;
|
||||
itemOption.name = name;
|
||||
return itemOption;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.justpickup.storeservice.domain.itemoption.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.item.entity.QItem;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.QItemOption;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.justpickup.storeservice.domain.item.entity.QItem.item;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ItemOptionRepositoryCustom {
|
||||
@@ -21,7 +20,9 @@ public class ItemOptionRepositoryCustom {
|
||||
|
||||
return queryFactory.selectFrom(QItemOption.itemOption)
|
||||
.join(QItemOption.itemOption.item)
|
||||
.on(QItem.item.id.eq(itemId))
|
||||
.on(item.id.eq(itemId))
|
||||
.fetch();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.justpickup.storeservice.domain.store.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.justpickup.storeservice.domain.store.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.FavoriteStore;
|
||||
import com.justpickup.storeservice.domain.favoritestore.entity.QFavoriteStore;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
|
||||
@@ -83,7 +82,7 @@ public class StoreRepositoryCustom {
|
||||
return content;
|
||||
}
|
||||
|
||||
private NumberExpression<Double> getHaversineDistance (double SearchLatitude, double SearchLongitude){
|
||||
private NumberExpression<Double> getHaversineDistance(double SearchLatitude, double SearchLongitude){
|
||||
Expression<Double> latitude = Expressions.constant(SearchLatitude);
|
||||
Expression<Double> longitude = Expressions.constant(SearchLongitude);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.justpickup.storeservice.global;
|
||||
|
||||
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.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;
|
||||
import com.justpickup.storeservice.global.entity.Address;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SqlCommandLineRunner implements CommandLineRunner {
|
||||
|
||||
private final StoreRepository storeRepository;
|
||||
private final FavoriteStoreRepository favoriteStoreRepository;
|
||||
private final ItemRepository itemRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
List<Store> stores = new ArrayList<>();
|
||||
|
||||
createStores(storeRepository, stores);
|
||||
|
||||
createFavoriteStore(favoriteStoreRepository, stores);
|
||||
|
||||
createItemAndCategories(itemRepository, categoryRepository, stores);
|
||||
}
|
||||
|
||||
private void createItemAndCategories(ItemRepository itemRepository, CategoryRepository categoryRepository, List<Store> stores) {
|
||||
stores.forEach(store -> {
|
||||
Category 카페인 = categoryRepository.save(Category.of("카페인", 0, store));
|
||||
Category 디카페인 = categoryRepository.save(Category.of("디카페인", 1, store));
|
||||
Category 티 = categoryRepository.save(Category.of("티", 2, store));
|
||||
|
||||
ItemOption ice = ItemOption.of(OptionType.REQUIRED, "ICE");
|
||||
ItemOption hot = ItemOption.of(OptionType.REQUIRED, "HOT");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -45,17 +45,9 @@ class CategoryOwnerApiControllerTest {
|
||||
@MockBean
|
||||
private CategoryService categoryService;
|
||||
|
||||
@MockBean
|
||||
private StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
private FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("카테고리리스트_가져오기_성공")
|
||||
void getCategoryList_success() throws Exception {
|
||||
|
||||
//given
|
||||
Long storeId = 1L;
|
||||
List<CategoryDto> categoryDtoList = new ArrayList<>();
|
||||
@@ -75,7 +67,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")
|
||||
@@ -108,7 +100,6 @@ class CategoryOwnerApiControllerTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("카테고리리스트_수정_성공")
|
||||
void putCategoryList_success() throws Exception {
|
||||
|
||||
@@ -56,12 +56,6 @@ class ItemOwnerApiControllerTest {
|
||||
@MockBean
|
||||
ItemService itemService;
|
||||
|
||||
@MockBean
|
||||
private StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
private FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
@Test
|
||||
@DisplayName("상품 리스트 조회")
|
||||
void getItemList() throws Exception {
|
||||
@@ -177,9 +171,9 @@ class ItemOwnerApiControllerTest {
|
||||
Long categoryId = 1L;
|
||||
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> requiredOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED,null));
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED));
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> otherOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER,null));
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가", OptionType.OTHER));
|
||||
|
||||
|
||||
ItemOwnerApiController.ItemRequest itemRequest =
|
||||
@@ -208,12 +202,10 @@ class ItemOwnerApiControllerTest {
|
||||
fieldWithPath("requiredOption[*].id").description("옵션 고유번호"),
|
||||
fieldWithPath("requiredOption[*].name").description("옵션 이름"),
|
||||
fieldWithPath("requiredOption[*].optionType").description("옵션 타입"),
|
||||
fieldWithPath("requiredOption[*].price").description("옵션 가격"),
|
||||
fieldWithPath("otherOption").description("추가옵션"),
|
||||
fieldWithPath("otherOption[*].id").description("옵션 고유번호"),
|
||||
fieldWithPath("otherOption[*].name").description("옵션 이름"),
|
||||
fieldWithPath("otherOption[*].optionType").description("옵션 타입"),
|
||||
fieldWithPath("otherOption[*].price").description("옵션 가격")
|
||||
fieldWithPath("otherOption[*].optionType").description("옵션 타입")
|
||||
))
|
||||
);
|
||||
}
|
||||
@@ -227,9 +219,9 @@ class ItemOwnerApiControllerTest {
|
||||
Long categoryId = 1L;
|
||||
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> requiredOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED,null));
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED));
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> otherOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER,null));
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER));
|
||||
|
||||
|
||||
ItemOwnerApiController.ItemRequest itemRequest =
|
||||
@@ -257,12 +249,10 @@ class ItemOwnerApiControllerTest {
|
||||
fieldWithPath("requiredOption[*].id").description("옵션 고유번호"),
|
||||
fieldWithPath("requiredOption[*].name").description("옵션 이름"),
|
||||
fieldWithPath("requiredOption[*].optionType").description("옵션 타입"),
|
||||
fieldWithPath("requiredOption[*].price").description("옵션 가격"),
|
||||
fieldWithPath("otherOption").description("추가옵션"),
|
||||
fieldWithPath("otherOption[*].id").description("옵션 고유번호"),
|
||||
fieldWithPath("otherOption[*].name").description("옵션 이름"),
|
||||
fieldWithPath("otherOption[*].optionType").description("옵션 타입"),
|
||||
fieldWithPath("otherOption[*].price").description("옵션 가격")
|
||||
fieldWithPath("otherOption[*].optionType").description("옵션 타입")
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.justpickup.storeservice.domain.store.web;
|
||||
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreDto;
|
||||
import com.justpickup.storeservice.domain.store.service.StoreService;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(StoreController.class)
|
||||
@Import(TestConfig.class)
|
||||
@AutoConfigureRestDocs(uriHost = "just-pickup.com", uriPort = 8000)
|
||||
class StoreControllerTest {
|
||||
|
||||
private final String url = "/store";
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
StoreService storeService;
|
||||
|
||||
@Test
|
||||
@DisplayName("[store] 매장 정보 가져오기")
|
||||
void getStore() throws Exception {
|
||||
//given
|
||||
String storeId = "1";
|
||||
given(storeService.findStore(1L)).willReturn(getWillReturnStore());
|
||||
|
||||
//when
|
||||
ResultActions actions = mockMvc.perform(get("/store/{storeId}", storeId));
|
||||
|
||||
//then
|
||||
actions.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andDo(document("store-get",
|
||||
pathParameters(
|
||||
parameterWithName("storeId").description("매장 고유번호")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data.id").description("매장 고유번호"),
|
||||
fieldWithPath("data.name").description("매장 이름"),
|
||||
fieldWithPath("data.phoneNumber").description("매장 번호")
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private StoreDto getWillReturnStore() {
|
||||
return StoreDto.builder().id(1L).name("이디야커피 대림역점").phoneNumber("010-1234-5678").build();
|
||||
}
|
||||
}
|
||||
@@ -93,16 +93,17 @@ class StoreCustomerApiControllerTest {
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data[*].id").description("매장 고유번호"),
|
||||
fieldWithPath("data[*].name").description("매장 이름"),
|
||||
fieldWithPath("data[*].distance").description("고객과의 거리차이 m/km")
|
||||
fieldWithPath("data[*].distance").description("고객과의 거리차이 m/km"),
|
||||
fieldWithPath("data[*].favoriteCounts").description("즐겨찾기 회수")
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
private List<SearchStoreResult> getWillReturnSearchStore(){
|
||||
SearchStoreResult result_1 = new SearchStoreResult(1L, "이디야커피 마포오벨리스크점", 145.11980562222007);
|
||||
SearchStoreResult result_2 = new SearchStoreResult(2L, "만랩커피 마포점", 150.97181089895466);
|
||||
SearchStoreResult result_3 = new SearchStoreResult(3L, "커피온리 마포역점", 341.25696860337655);
|
||||
SearchStoreResult result_1 = new SearchStoreResult(1L, "이디야커피 마포오벨리스크점", 145.11980562222007, 5L);
|
||||
SearchStoreResult result_2 = new SearchStoreResult(2L, "만랩커피 마포점", 150.97181089895466, 5L);
|
||||
SearchStoreResult result_3 = new SearchStoreResult(3L, "커피온리 마포역점", 341.25696860337655, 5L);
|
||||
|
||||
return List.of(result_1,result_2,result_3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user