Merge pull request #42 from Development-team-1/refactor-item
Refactor item
This commit is contained in:
@@ -2,12 +2,12 @@ import axios from "axios";
|
||||
|
||||
export default {
|
||||
getCategoryList(){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/category');
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/owner/category');
|
||||
},
|
||||
putCategoryList(data){
|
||||
return axios({
|
||||
method:'put',
|
||||
url:process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/category',
|
||||
url:process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/owner/category',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
@@ -17,10 +17,10 @@ export default {
|
||||
})
|
||||
},
|
||||
getItemById(itemId){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item/'+itemId)
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/owner/item/'+itemId)
|
||||
},
|
||||
saveItem(method, itemData){
|
||||
const _url = process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item'+(method==='put'?+"/"+itemData.itemId:'')
|
||||
const _url = process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/owner/item'+(method==='put'?+"/"+itemData.itemId:'')
|
||||
console.log(_url)
|
||||
return axios({
|
||||
method:method,
|
||||
@@ -34,6 +34,6 @@ export default {
|
||||
})
|
||||
},
|
||||
getMenu(searchParam){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item',searchParam);
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/owner/item',searchParam);
|
||||
},
|
||||
}
|
||||
@@ -70,6 +70,17 @@ operation::item-get[snippets='curl-request,http-request,http-response,path-param
|
||||
=== 상품 조회 (존재하지 않는 상품)
|
||||
operation::item-get-notExistItemException[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
|
||||
|
||||
=== 상품 조회(판매자)
|
||||
operation::owner-item-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
=== 상품 리스트 조회
|
||||
operation::owner-itemList-get[snippets='curl-request,http-request,http-response,response-fields']
|
||||
|
||||
=== 상품 수정
|
||||
operation::owner-put-item[snippets='curl-request,http-request,http-response']
|
||||
=== 상품 등록
|
||||
operation::owner-create-item[snippets='curl-request,http-request,http-response']
|
||||
|
||||
== 카테고리
|
||||
== 카테고리 조회
|
||||
operation::get-categoryList[snippets='curl-request,http-request,http-response,request-parameters,response-fields']
|
||||
@@ -77,6 +88,10 @@ operation::get-categoryList[snippets='curl-request,http-request,http-response,re
|
||||
== 카테고리 수정
|
||||
operation::put-categoryList[snippets='curl-request,http-request,http-response,request-body,request-fields']
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
== 매장
|
||||
=== 매장 검색 조회
|
||||
operation::api-customer-store-search[snippets='curl-request,http-request,http-response,request-parameters,response-fields']
|
||||
|
||||
@@ -48,9 +48,11 @@ public class CategoryOwnerApiController {
|
||||
this.categoryId = categoryDto.getId();
|
||||
this.name= categoryDto.getName();
|
||||
this.order= categoryDto.getOrder();
|
||||
this.items = categoryDto.getItems().stream()
|
||||
this.items = categoryDto.getItems()!=null
|
||||
?categoryDto.getItems().stream()
|
||||
.map(ItemResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
.collect(Collectors.toList())
|
||||
:null;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -12,6 +12,8 @@ public interface ItemService {
|
||||
|
||||
ItemDto findItemByItemId(Long itemId);
|
||||
|
||||
ItemDto findFullItemByItemId(Long itemId);
|
||||
|
||||
Page<ItemDto> findItemList(Long storeId,String word, Pageable pageable);
|
||||
|
||||
void putItem(Long itemId, String itemName, Long itemPrice, Long categoryId, List<ItemOptionDto> itemOptionDtos);
|
||||
|
||||
@@ -41,6 +41,14 @@ public class ItemServiceImpl implements ItemService {
|
||||
|
||||
@Override
|
||||
public ItemDto findItemByItemId(Long itemId) {
|
||||
Item findItem = itemRepository.findById(itemId)
|
||||
.orElseThrow(() -> new NotExistItemException("존재하지 않는 아이템 입니다."));
|
||||
|
||||
return ItemDto.createWithCategoryItemDtoAndItemOption(findItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDto findFullItemByItemId(Long itemId) {
|
||||
Item findItem = itemRepositoryCustom.findById(itemId)
|
||||
.orElseThrow(() -> new NotExistItemException("존재하지 않는 아이템 입니다."));
|
||||
|
||||
|
||||
@@ -25,64 +25,6 @@ public class ItemController {
|
||||
|
||||
private final ItemService itemService;
|
||||
|
||||
@GetMapping("/item")
|
||||
public ResponseEntity<Result<GetItemResponse>> getItemList( @RequestParam String word,
|
||||
@PageableDefault(page = 0, size = 10) Pageable pageable,
|
||||
@RequestHeader(value = "user-id") String userId ){
|
||||
|
||||
Long storeId = Long.parseLong(userId);
|
||||
|
||||
Page<ItemDto> itemDtoList = itemService.findItemList(storeId,word,pageable);
|
||||
List<GetItemListResponse.Item> itemList = itemDtoList.stream()
|
||||
.map(GetItemListResponse.Item::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
GetItemListResponse getItemResponse = new GetItemListResponse(
|
||||
itemList,
|
||||
itemDtoList.getNumber(),
|
||||
itemDtoList.getTotalPages()
|
||||
);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body((Result<GetItemResponse>)Result.createSuccessResult(getItemResponse));
|
||||
}
|
||||
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class GetItemListResponse {
|
||||
private List<Item> itemList;
|
||||
private Page page;
|
||||
|
||||
public GetItemListResponse(List<Item> itemList, int startPage,int totalPage) {
|
||||
this.itemList = itemList;
|
||||
this.page = new Page(startPage,totalPage);
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Item{
|
||||
private Long id;
|
||||
private String name;
|
||||
private Yn salesYn;
|
||||
private Long price;
|
||||
private String categoryName;
|
||||
|
||||
public Item(ItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.salesYn = itemDto.getSalesYn();
|
||||
this.price = itemDto.getPrice();
|
||||
this.categoryName = itemDto.getCategoryDto().getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Data @AllArgsConstructor
|
||||
static class Page {
|
||||
int startPage;
|
||||
int totalPage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/item/{itemId}")
|
||||
public ResponseEntity getItem(@PathVariable("itemId") Long itemId) {
|
||||
@@ -99,121 +41,14 @@ public class ItemController {
|
||||
private String name;
|
||||
private Yn salesYn;
|
||||
private Long price;
|
||||
private Long CategoryId;
|
||||
private List<ItemOptionResponse> itemOptions;
|
||||
|
||||
public GetItemResponse(ItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.salesYn = itemDto.getSalesYn();
|
||||
this.price = itemDto.getPrice();
|
||||
this.CategoryId = itemDto.getCategoryDto().getId();
|
||||
this.itemOptions = itemDto.getItemOptions()
|
||||
.stream().map(ItemOptionResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class ItemOptionResponse{
|
||||
private Long id;
|
||||
|
||||
private OptionType optionType;
|
||||
|
||||
private Long price;
|
||||
|
||||
private String name;
|
||||
|
||||
public ItemOptionResponse(ItemOptionDto itemOptionDto) {
|
||||
|
||||
this.id = itemOptionDto.getId();
|
||||
this.optionType = itemOptionDto.getOptionType();
|
||||
this.price = itemOptionDto.getPrice();
|
||||
this.name = itemOptionDto.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/item")
|
||||
public ResponseEntity<Result> putItem(@RequestBody @Valid ItemRequest itemRequest){
|
||||
|
||||
List<ItemOptionDto> itemOption = itemRequest.getRequiredOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList());
|
||||
itemOption.addAll(itemRequest.getOtherOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
itemService.putItem(itemRequest.getItemId()
|
||||
, itemRequest.getItemName()
|
||||
, itemRequest.getItemPrice()
|
||||
, itemRequest.getCategoryId()
|
||||
, itemOption);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.NO_CONTENT)
|
||||
.body(Result.success());
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ItemRequest {
|
||||
private Long itemId;
|
||||
@NotNull
|
||||
private String itemName;
|
||||
@NotNull
|
||||
private Long itemPrice;
|
||||
@NotNull
|
||||
private Long categoryId;
|
||||
private List<ItemOptionRequest> requiredOption;
|
||||
private List<ItemOptionRequest> otherOption;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public static class ItemOptionRequest {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/item")
|
||||
public ResponseEntity createItem( @RequestBody @Valid ItemRequest itemRequest,
|
||||
@RequestHeader(value = "user-id") String userId ){
|
||||
|
||||
Long storeId = Long.parseLong(userId);
|
||||
|
||||
List<ItemOptionDto> itemOption = itemRequest.getRequiredOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList());
|
||||
itemOption.addAll(itemRequest.getOtherOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
itemService.createItem(storeId
|
||||
, itemRequest.getItemName()
|
||||
, itemRequest.getItemPrice()
|
||||
, itemRequest.getCategoryId()
|
||||
, itemOption);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(Result.success());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
package com.justpickup.storeservice.domain.item.web;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.item.service.ItemService;
|
||||
import com.justpickup.storeservice.domain.itemoption.dto.ItemOptionDto;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import com.justpickup.storeservice.global.dto.Result;
|
||||
import com.justpickup.storeservice.global.entity.Yn;
|
||||
import lombok.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/owner")
|
||||
public class ItemOwnerApiController {
|
||||
|
||||
private final ItemService itemService;
|
||||
|
||||
@GetMapping("/item")
|
||||
public ResponseEntity<Result<GetItemResponse>> getItemList(@RequestParam(required = false) Optional<String> word,
|
||||
@PageableDefault Pageable pageable,
|
||||
@RequestHeader(value = "user-id") String userId ){
|
||||
|
||||
Long storeId = Long.parseLong(userId);
|
||||
|
||||
Page<ItemDto> itemDtoList =
|
||||
itemService.findItemList(storeId,
|
||||
word.orElse(""),
|
||||
pageable);
|
||||
List<GetItemListResponse.Item> itemList = itemDtoList.stream()
|
||||
.map(GetItemListResponse.Item::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
GetItemListResponse getItemResponse = new GetItemListResponse(
|
||||
itemList,
|
||||
itemDtoList.getNumber(),
|
||||
itemDtoList.getTotalPages()
|
||||
);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body((Result<GetItemResponse>)Result.createSuccessResult(getItemResponse));
|
||||
}
|
||||
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class GetItemListResponse {
|
||||
private List<Item> itemList;
|
||||
private Page page;
|
||||
|
||||
public GetItemListResponse(List<Item> itemList, int startPage,int totalPage) {
|
||||
this.itemList = itemList;
|
||||
this.page = new Page(startPage,totalPage);
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Item{
|
||||
private Long id;
|
||||
private String name;
|
||||
private Yn salesYn;
|
||||
private Long price;
|
||||
private String categoryName;
|
||||
|
||||
public Item(ItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.salesYn = itemDto.getSalesYn();
|
||||
this.price = itemDto.getPrice();
|
||||
this.categoryName = itemDto.getCategoryDto().getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Data @AllArgsConstructor
|
||||
static class Page {
|
||||
int startPage;
|
||||
int totalPage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/item/{itemId}")
|
||||
public ResponseEntity getItem(@PathVariable("itemId") Long itemId) {
|
||||
ItemDto itemByItemId = itemService.findFullItemByItemId(itemId);
|
||||
|
||||
GetItemResponse getItemResponse = new GetItemResponse(itemByItemId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(Result.createSuccessResult(getItemResponse));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class GetItemResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Yn salesYn;
|
||||
private Long price;
|
||||
private Long CategoryId;
|
||||
private List<ItemOptionResponse> itemOptions;
|
||||
|
||||
public GetItemResponse(ItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.salesYn = itemDto.getSalesYn();
|
||||
this.price = itemDto.getPrice();
|
||||
this.CategoryId = itemDto.getCategoryDto().getId();
|
||||
this.itemOptions = itemDto.getItemOptions()
|
||||
.stream().map(ItemOptionResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class ItemOptionResponse{
|
||||
private Long id;
|
||||
|
||||
private OptionType optionType;
|
||||
|
||||
private Long price;
|
||||
|
||||
private String name;
|
||||
|
||||
public ItemOptionResponse(ItemOptionDto itemOptionDto) {
|
||||
|
||||
this.id = itemOptionDto.getId();
|
||||
this.optionType = itemOptionDto.getOptionType();
|
||||
this.price = itemOptionDto.getPrice();
|
||||
this.name = itemOptionDto.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/item/{itemId}")
|
||||
public ResponseEntity<Result> putItem(@RequestBody @Valid ItemRequest itemRequest,@PathVariable Long itemId){
|
||||
|
||||
List<ItemOptionDto> itemOption = itemRequest.getRequiredOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList());
|
||||
itemOption.addAll(itemRequest.getOtherOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
itemService.putItem(itemId
|
||||
, itemRequest.getItemName()
|
||||
, itemRequest.getItemPrice()
|
||||
, itemRequest.getCategoryId()
|
||||
, itemOption);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.NO_CONTENT)
|
||||
.body(Result.success());
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ItemRequest {
|
||||
private Long itemId;
|
||||
@NotNull
|
||||
private String itemName;
|
||||
@NotNull
|
||||
private Long itemPrice;
|
||||
@NotNull
|
||||
private Long categoryId;
|
||||
private List<ItemOptionRequest> requiredOption;
|
||||
private List<ItemOptionRequest> otherOption;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public static class ItemOptionRequest {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/item")
|
||||
public ResponseEntity createItem( @RequestBody @Valid ItemRequest itemRequest,
|
||||
@RequestHeader(value = "user-id") String userId ){
|
||||
|
||||
Long storeId = Long.parseLong(userId);
|
||||
|
||||
List<ItemOptionDto> itemOption = itemRequest.getRequiredOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList());
|
||||
itemOption.addAll(itemRequest.getOtherOption().stream()
|
||||
.map(ItemRequest.ItemOptionRequest::createItemOptionDto)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
itemService.createItem(storeId
|
||||
, itemRequest.getItemName()
|
||||
, itemRequest.getItemPrice()
|
||||
, itemRequest.getCategoryId()
|
||||
, itemOption);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(Result.success());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
import com.justpickup.storeservice.domain.category.service.CategoryService;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -23,6 +25,8 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
@@ -41,6 +45,13 @@ class CategoryOwnerApiControllerTest {
|
||||
@MockBean
|
||||
private CategoryService categoryService;
|
||||
|
||||
@MockBean
|
||||
private StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
private FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("카테고리리스트_가져오기_성공")
|
||||
void getCategoryList_success() throws Exception {
|
||||
@@ -51,21 +62,25 @@ class CategoryOwnerApiControllerTest {
|
||||
categoryDtoList.add(CategoryDto.builder()
|
||||
.id(10L)
|
||||
.name("카테고리1")
|
||||
.items(List.of(new ItemDto(1L,"아메리카노",null,5000L)
|
||||
,new ItemDto(1L,"카페라테",null,5000L)))
|
||||
.order(1)
|
||||
.build());
|
||||
|
||||
categoryDtoList.add(CategoryDto.builder()
|
||||
.id(11L)
|
||||
.name("카테고리2")
|
||||
.items(List.of(new ItemDto(1L,"비스킷",null,5000L)
|
||||
,new ItemDto(1L,"와플",null,5000L)))
|
||||
.order(2)
|
||||
.build());
|
||||
|
||||
BDDMockito.given(categoryService.getCategoryList(1L)).willReturn(categoryDtoList);
|
||||
given(categoryService.getCategoryList(any())).willReturn(categoryDtoList);
|
||||
//when
|
||||
|
||||
ResultActions actions = mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/category")
|
||||
ResultActions actions = mockMvc.perform(MockMvcRequestBuilders.get("/api/owner/category")
|
||||
.param("storeId",String.valueOf(storeId))
|
||||
.header("user-id","2")
|
||||
);
|
||||
|
||||
//then
|
||||
@@ -85,7 +100,9 @@ class CategoryOwnerApiControllerTest {
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data[*].categoryId").description("카테고리 고유 번호"),
|
||||
fieldWithPath("data[*].name").description("카테고리 명"),
|
||||
fieldWithPath("data[*].order").description("순서")
|
||||
fieldWithPath("data[*].order").description("순서"),
|
||||
fieldWithPath("data[*].items[*].id").description("아이템 고유번호"),
|
||||
fieldWithPath("data[*].items[*].name").description("아이템 명")
|
||||
)
|
||||
));
|
||||
|
||||
@@ -130,7 +147,7 @@ class CategoryOwnerApiControllerTest {
|
||||
//when
|
||||
ResultActions actions = mockMvc.perform(
|
||||
MockMvcRequestBuilders
|
||||
.put("/category")
|
||||
.put("/api/owner//category")
|
||||
.content(objectMapper.writeValueAsString(putCategoryRequest) )
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.justpickup.storeservice.domain.item.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.item.exception.NotExistItemException;
|
||||
import com.justpickup.storeservice.domain.item.service.ItemService;
|
||||
import com.justpickup.storeservice.domain.itemoption.dto.ItemOptionDto;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.global.dto.Code;
|
||||
import com.justpickup.storeservice.global.entity.Yn;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -17,18 +16,12 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDoc
|
||||
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.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
|
||||
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;
|
||||
@@ -51,6 +44,12 @@ class ItemControllerTest {
|
||||
@MockBean
|
||||
ItemService itemService;
|
||||
|
||||
@MockBean
|
||||
private StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
private FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
@Test
|
||||
@DisplayName("상품 조회")
|
||||
void getItem() throws Exception {
|
||||
@@ -89,8 +88,7 @@ class ItemControllerTest {
|
||||
fieldWithPath("data.salesYn").description("화면 표시 여부 Y/N"),
|
||||
fieldWithPath("data.price").description("상품 가격")
|
||||
)
|
||||
))
|
||||
;
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,34 +122,5 @@ class ItemControllerTest {
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("메뉴 등록")
|
||||
void created_item_success() throws Exception{
|
||||
//given
|
||||
String itemName = "테스트아이템";
|
||||
Long itemPrice = 3000L;
|
||||
Long categoryId = 1L;
|
||||
|
||||
List<ItemController.ItemRequest.ItemOptionRequest> requiredOption = List.of(new ItemController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED,null));
|
||||
List<ItemController.ItemRequest.ItemOptionRequest> otherOption = List.of(new ItemController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER,null));
|
||||
|
||||
|
||||
ItemController.ItemRequest itemRequest = new ItemController.ItemRequest(null,itemName,itemPrice,categoryId,requiredOption,otherOption);
|
||||
|
||||
String body = objectMapper.writeValueAsString(itemRequest);
|
||||
|
||||
//when
|
||||
ResultActions perform = mockMvc.perform(post("/item")
|
||||
.content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
|
||||
//then
|
||||
ResultActions resultActions = perform.andExpect(status().isCreated())
|
||||
.andDo(print());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
package com.justpickup.storeservice.domain.item.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.item.exception.NotExistItemException;
|
||||
import com.justpickup.storeservice.domain.item.service.ItemService;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.global.dto.Code;
|
||||
import com.justpickup.storeservice.global.entity.Yn;
|
||||
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.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(ItemOwnerApiController.class)
|
||||
@Import(TestConfig.class)
|
||||
@AutoConfigureRestDocs(uriHost = "127.0.0.1", uriPort = 8001)
|
||||
class ItemOwnerApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
ItemService itemService;
|
||||
|
||||
@MockBean
|
||||
private StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
private FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
@Test
|
||||
@DisplayName("상품 리스트 조회")
|
||||
void getItemList() throws Exception {
|
||||
// GIVEN
|
||||
List<ItemDto> items = List.of(
|
||||
ItemDto.builder()
|
||||
.id(1L)
|
||||
.salesYn(Yn.Y)
|
||||
.price(1500L)
|
||||
.name("아메리카노")
|
||||
.itemOptions(new ArrayList<>())
|
||||
.categoryDto(new CategoryDto())
|
||||
.build(),
|
||||
ItemDto.builder()
|
||||
.id(2L)
|
||||
.salesYn(Yn.Y)
|
||||
.price(2000L)
|
||||
.name("카페라테")
|
||||
.itemOptions(new ArrayList<>())
|
||||
.categoryDto(new CategoryDto())
|
||||
.build()
|
||||
);
|
||||
|
||||
Page<ItemDto> page = PageableExecutionUtils.getPage(items, Pageable.ofSize(10), () -> 1);
|
||||
|
||||
given(itemService.findItemList(eq(1L),eq(""),any()))
|
||||
.willReturn(page);
|
||||
|
||||
// WHEN
|
||||
ResultActions actions = mockMvc.perform(
|
||||
get("/api/owner/item/")
|
||||
.header("user-id","1")
|
||||
.param("word","")
|
||||
);
|
||||
|
||||
// THEN
|
||||
actions.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andDo(document("owner-itemList-get",
|
||||
requestParameters(
|
||||
parameterWithName("word").description("아이템 명 or 카테고리 명")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data.itemList[*].id").description("상품 고유 번호"),
|
||||
fieldWithPath("data.itemList[*].name").description("상품 이름"),
|
||||
fieldWithPath("data.itemList[*].salesYn").description("화면 표시 여부 Y/N"),
|
||||
fieldWithPath("data.itemList[*].price").description("상품 가격"),
|
||||
fieldWithPath("data.itemList[*].categoryName").description("카테고리 명"),
|
||||
fieldWithPath("data.page.startPage").description("현제 페이지"),
|
||||
fieldWithPath("data.page.totalPage").description("토탈 페이지")
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("상품 조회")
|
||||
void getItem() throws Exception {
|
||||
// GIVEN
|
||||
long itemId = 1L;
|
||||
ItemDto willReturnDto = ItemDto.builder()
|
||||
.id(1L)
|
||||
.salesYn(Yn.Y)
|
||||
.price(1500L)
|
||||
.name("아메리카노")
|
||||
.itemOptions(new ArrayList<>())
|
||||
.categoryDto(new CategoryDto())
|
||||
.build();
|
||||
given(itemService.findFullItemByItemId(itemId))
|
||||
.willReturn(willReturnDto);
|
||||
|
||||
// WHEN
|
||||
ResultActions actions = mockMvc.perform(
|
||||
get("/api/owner/item/{itemId}", itemId)
|
||||
);
|
||||
|
||||
// THEN
|
||||
actions.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("code").value(Code.SUCCESS.name()))
|
||||
.andExpect(jsonPath("message").value(""))
|
||||
.andExpect(jsonPath("data.id").value(itemId))
|
||||
.andExpect(jsonPath("data.name").value("아메리카노"))
|
||||
.andExpect(jsonPath("data.salesYn").value(Yn.Y.name()))
|
||||
.andExpect(jsonPath("data.price").value(1500))
|
||||
.andDo(print())
|
||||
.andDo(document("owner-item-get",
|
||||
pathParameters(
|
||||
parameterWithName("itemId").description("상품 고유 번호")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data.id").description("상품 고유 번호"),
|
||||
fieldWithPath("data.name").description("상품 이름"),
|
||||
fieldWithPath("data.salesYn").description("화면 표시 여부 Y/N"),
|
||||
fieldWithPath("data.price").description("상품 가격"),
|
||||
fieldWithPath("data.itemOptions").description("아이템 옵션"),
|
||||
fieldWithPath("data.categoryId").description("카테고리 고유번호")
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("메뉴 등록")
|
||||
void created_item_success() throws Exception{
|
||||
//given
|
||||
String itemName = "테스트아이템";
|
||||
Long itemPrice = 3000L;
|
||||
Long categoryId = 1L;
|
||||
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> requiredOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED,null));
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> otherOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER,null));
|
||||
|
||||
|
||||
ItemOwnerApiController.ItemRequest itemRequest =
|
||||
new ItemOwnerApiController.ItemRequest(null,itemName,itemPrice,categoryId,requiredOption,otherOption);
|
||||
|
||||
String body = objectMapper.writeValueAsString(itemRequest);
|
||||
|
||||
//when
|
||||
ResultActions perform = mockMvc.perform(post("/api/owner/item")
|
||||
.header("user-id","2")
|
||||
.content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
|
||||
//then
|
||||
ResultActions resultActions = perform.andExpect(status().isCreated())
|
||||
.andDo(print())
|
||||
.andDo(document("owner-create-item",
|
||||
requestFields(
|
||||
fieldWithPath("itemId").description("아이템 고유번호"),
|
||||
fieldWithPath("itemName").description("아이템 이름"),
|
||||
fieldWithPath("itemPrice").description("아이템 가격"),
|
||||
fieldWithPath("categoryId").description("카테고리 고유번호"),
|
||||
fieldWithPath("requiredOption").description("필수옵션"),
|
||||
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("옵션 가격")
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("메뉴 수정")
|
||||
void put_item_success() throws Exception{
|
||||
//given
|
||||
String itemName = "테스트아이템";
|
||||
Long itemPrice = 3000L;
|
||||
Long categoryId = 1L;
|
||||
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> requiredOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "HOT",OptionType.REQUIRED,null));
|
||||
List<ItemOwnerApiController.ItemRequest.ItemOptionRequest> otherOption =
|
||||
List.of(new ItemOwnerApiController.ItemRequest.ItemOptionRequest(null, "샷 추가",OptionType.OTHER,null));
|
||||
|
||||
|
||||
ItemOwnerApiController.ItemRequest itemRequest =
|
||||
new ItemOwnerApiController.ItemRequest(1L,itemName,itemPrice,categoryId,requiredOption,otherOption);
|
||||
|
||||
String body = objectMapper.writeValueAsString(itemRequest);
|
||||
|
||||
//when
|
||||
ResultActions perform = mockMvc.perform(put("/api/owner/item/"+itemRequest.getItemId())
|
||||
.header("user-id","2")
|
||||
.content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
//then
|
||||
ResultActions resultActions = perform.andExpect(status().isNoContent())
|
||||
.andDo(print())
|
||||
.andDo(document("owner-put-item",
|
||||
requestFields(
|
||||
fieldWithPath("itemId").description("아이템 고유번호"),
|
||||
fieldWithPath("itemName").description("아이템 이름"),
|
||||
fieldWithPath("itemPrice").description("아이템 가격"),
|
||||
fieldWithPath("categoryId").description("카테고리 고유번호"),
|
||||
fieldWithPath("requiredOption").description("필수옵션"),
|
||||
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("옵션 가격")
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.justpickup.storeservice.domain.store.web;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
@@ -15,7 +14,6 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDoc
|
||||
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.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
@@ -24,20 +22,17 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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.requestParameters;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user