fix(store-service): refactor , testcode
- api 리팩토링 - testcode 작성
This commit is contained in:
@@ -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,220 @@
|
||||
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.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/owner")
|
||||
public class ItemOwnerApiController {
|
||||
|
||||
private final ItemService itemService;
|
||||
|
||||
@GetMapping("/item")
|
||||
public ResponseEntity<Result<GetItemResponse>> getItemList( @RequestParam String word,
|
||||
@PageableDefault 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) {
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user