fix(store-service, owner vue): category Dto 리팩토링

-category Dto  에 Store entity가 존재하는것 수정
-owner vue에 category 조회시 error 수정
This commit is contained in:
hoon7566
2022-03-10 15:46:37 +09:00
parent d012fe3fb0
commit 55ec97af93
7 changed files with 19 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ package com.justpickup.storeservice.domain.category.dto;
import com.justpickup.storeservice.domain.category.entity.Category;
import com.justpickup.storeservice.domain.category.web.CategoryOwnerApiController;
import com.justpickup.storeservice.domain.item.dto.ItemDto;
import com.justpickup.storeservice.domain.store.dto.StoreDto;
import com.justpickup.storeservice.domain.store.entity.Store;
import lombok.*;
@@ -18,7 +19,7 @@ public class CategoryDto {
private Long id;
private String name;
private Integer order;
private Store store;
private StoreDto storeDto;
private List<ItemDto> items;
@@ -37,15 +38,4 @@ public class CategoryDto {
this.order = category.getOrder();
}
public static Category createCategory(CategoryDto categoryDto){
return Category.createCategory(
categoryDto.getId()
,categoryDto.getName()
, categoryDto.getOrder()
, categoryDto.getStore());
}
public void setStore(Store store){
this.store=store;
}
}

View File

@@ -49,17 +49,13 @@ public class Category extends BaseEntity {
this.order = order;
}
private Category (Long id , String name, Integer order, Store store){
public Category (Long id , String name, Integer order, Store store){
this.id = id;
this.name = name;
this.order = order;
this.store = store;
}
public static Category createCategory(Long id ,String name, Integer order, Store store){
return new Category(id,name,order,store);
}
public static Category of(String name, Integer order, Store store) {
Category category = new Category();
category.name = name;

View File

@@ -35,23 +35,21 @@ public class CategoryService {
}
@Transactional
public void putCategoryList(Long storeId , List<CategoryDto> categoryDtoList , List<CategoryDto> deletedCategoryDtoList ){
public void putCategoryList(Long storeId ,
List<CategoryDto> categoryDtoList ,
List<CategoryDto> deletedCategoryDtoList ){
Store store = storeRepository.findById(storeId)
.orElseThrow(() -> new NotFoundStoreException(HttpStatus.BAD_REQUEST,"존재하지않는 Store"));
List<Category> categoryList =categoryDtoList.stream()
.map(categoryDto -> {
categoryDto.setStore(store);
return CategoryDto.createCategory(categoryDto);
})
.map(categoryDto ->
new Category(categoryDto.getId(), categoryDto.getName(), categoryDto.getOrder(), store))
.collect(Collectors.toList());
List<Category> deletedCategoryList =deletedCategoryDtoList.stream()
.map(categoryDto -> {
categoryDto.setStore(store);
return CategoryDto.createCategory(categoryDto);
})
.map(categoryDto ->
new Category(categoryDto.getId(), categoryDto.getName(), categoryDto.getOrder(), store))
.collect(Collectors.toList());
categoryList.forEach(

View File

@@ -40,7 +40,7 @@ public class FetchItemDto {
this.price = item.getPrice();
this.categoryDto = new CategoryDto(item.getCategory());
this.itemOptions = item.getItemOptions().stream().map(ItemOptionDto::new).collect(Collectors.toList());
this.storeDto = new StoreDto(item.getStore().getId(), item.getStore().getName());
this.storeDto = new StoreDto(item.getStore().getId(), item.getStore().getName(), item.getStore().getPhoneNumber());
}
}

View File

@@ -9,6 +9,7 @@ import com.justpickup.storeservice.domain.item.exception.NotExistItemException;
import com.justpickup.storeservice.domain.item.repository.ItemRepository;
import com.justpickup.storeservice.domain.item.repository.ItemRepositoryCustom;
import com.justpickup.storeservice.domain.itemoption.dto.ItemOptionDto;
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
import com.justpickup.storeservice.domain.itemoption.repository.ItemOptionRepository;
import com.justpickup.storeservice.domain.store.entity.Store;
import com.justpickup.storeservice.domain.store.repository.StoreRepository;

View File

@@ -51,7 +51,7 @@ public class ItemCustomerApiController {
this.itemOptions = fetchItemDto.getItemOptions()
.stream().map(ItemOptionResponse::new)
.collect(Collectors.toList());
this.storeId = fetchItemDto.getStoreDto().getStoreId();
this.storeId = fetchItemDto.getStoreDto().getId();
}
@Data
@@ -60,15 +60,12 @@ public class ItemCustomerApiController {
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();
}
}