feat(owner-vue, store-service): 메뉴 등록
owner-vue에 Menu Modal view 개발, store-service에서 getItem 수정
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'font-awesome/css/font-awesome.min.css' // Ensure you are using css-loader
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import vuetify from './plugins/vuetify'
|
||||
@@ -6,11 +5,11 @@ import router from './router'
|
||||
import axios from "axios";
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.$axios = axios;
|
||||
|
||||
new Vue({
|
||||
vuetify,
|
||||
router,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
||||
Vue.component('axios',axios)
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ import {
|
||||
mdiContentSave, mdiDelete,
|
||||
mdiPlus,
|
||||
} from '@mdi/js'
|
||||
import axios from "axios";
|
||||
|
||||
export default {
|
||||
name: "Category",
|
||||
@@ -115,7 +114,7 @@ export default {
|
||||
}
|
||||
data.categoryList.push(category)
|
||||
})
|
||||
axios({
|
||||
this.$axios({
|
||||
method:'put',
|
||||
url:'/store-service/category',
|
||||
headers: {
|
||||
@@ -134,7 +133,7 @@ export default {
|
||||
},
|
||||
getCategoryList:function(){
|
||||
var vm =this;
|
||||
axios({
|
||||
this.$axios({
|
||||
method:'get',
|
||||
url:'/store-service/category',
|
||||
responseType:'json'
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
<div>
|
||||
<v-subheader class="py-0 d-flex justify-space-between rounded-lg">
|
||||
<h3>메뉴 관리</h3>
|
||||
<MenuItem
|
||||
:modalData="modalData"
|
||||
:icon="modalSet.icon.register"
|
||||
:color="modalSet.color.red"
|
||||
:name="modalSet.words.register"
|
||||
@save="itemSave"
|
||||
/>
|
||||
|
||||
</v-subheader>
|
||||
<v-form @submit.prevent>
|
||||
<v-container>
|
||||
@@ -28,6 +36,18 @@
|
||||
hide-default-footer
|
||||
class="elevation-1"
|
||||
>
|
||||
|
||||
<template v-slot:item.modify="{ item }">
|
||||
<MenuItem
|
||||
:modalData="modalData"
|
||||
:icon="modalSet.icon.modify"
|
||||
:color="modalSet.color.primary"
|
||||
:name="modalSet.words.modify"
|
||||
@init="editItem(item)"
|
||||
@save="itemSave"
|
||||
/>
|
||||
</template>
|
||||
|
||||
</v-data-table>
|
||||
<div class="text-center pt-2">
|
||||
<v-pagination
|
||||
@@ -47,58 +67,13 @@ import {
|
||||
mdiPlus,
|
||||
|
||||
} from '@mdi/js'
|
||||
import axios from "axios";
|
||||
// import axios from "axios";
|
||||
import MenuItem from "@/views/MenuItem";
|
||||
|
||||
export default {
|
||||
name: "Category",
|
||||
name: "Menu",
|
||||
components:{
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
icons: {
|
||||
mdiContentSave,
|
||||
mdiPlus,
|
||||
mdiDelete,
|
||||
},
|
||||
page: 1,
|
||||
pageCount: 1,
|
||||
itemsPerPage: 10,
|
||||
totalVisible: 10,
|
||||
headers: [
|
||||
{
|
||||
text: '메뉴번호',
|
||||
align: 'start',
|
||||
sortable: false,
|
||||
value: 'id',
|
||||
},
|
||||
{ text: '이름', value: 'name' },
|
||||
{ text: '카테고리', value: 'categoryName' },
|
||||
{ text: '가격', value: 'price' },
|
||||
],
|
||||
word:"",
|
||||
menus: [],
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
getMenu(){
|
||||
var vm = this;
|
||||
const searchParam= {
|
||||
word: vm.word,
|
||||
page: vm.page-1
|
||||
}
|
||||
axios({
|
||||
method:'get',
|
||||
url:'/store-service/item',
|
||||
params : searchParam,
|
||||
responseType:'json'
|
||||
})
|
||||
.then(function (response) {
|
||||
const page = response.data.data.page;
|
||||
vm.menus = response.data.data.itemList;
|
||||
vm.page = page.startPage+1;
|
||||
vm.pageCount = page.totalPage;
|
||||
});
|
||||
}
|
||||
MenuItem,
|
||||
},
|
||||
watch:{
|
||||
page:function () {
|
||||
@@ -111,8 +86,130 @@ export default {
|
||||
this.page =1;
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
icons: {
|
||||
mdiContentSave,
|
||||
mdiPlus,
|
||||
mdiDelete,
|
||||
},
|
||||
modalSet:{
|
||||
words:{
|
||||
register:"상품 등록",
|
||||
modify:"수정 하기",
|
||||
},
|
||||
icon:{
|
||||
register: "mdi-plus",
|
||||
modify: "mdi-pencil",
|
||||
},
|
||||
color:{
|
||||
primary: "primary",
|
||||
red: "red"
|
||||
}
|
||||
},
|
||||
modalData:{
|
||||
itemId : Number,
|
||||
itemName : String,
|
||||
itemPrice : Number,
|
||||
category: String,
|
||||
categoryList : ['카테고리1','카테고리2'],
|
||||
requiredOption : ['Ice' , 'Hot'],
|
||||
otherOption : ['얼음많이','샷추가','생크림많이','덜 뜨겁게']
|
||||
},
|
||||
page: 1,
|
||||
pageCount: 1,
|
||||
itemsPerPage: 10,
|
||||
totalVisible: 10,
|
||||
headers: [
|
||||
{
|
||||
text: '메뉴번호',
|
||||
align: 'start',
|
||||
sortable: false,
|
||||
value: 'id',
|
||||
},
|
||||
{ text: '이름', value: 'name' , sortable: false},
|
||||
{ text: '카테고리', value: 'categoryName', sortable: false },
|
||||
{ text: '가격', value: 'price' , sortable: false},
|
||||
{ text: '수정', value: 'modify' , sortable: false},
|
||||
],
|
||||
word:"",
|
||||
menus: [],
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
getMenu(){
|
||||
var vm = this;
|
||||
const searchParam= {
|
||||
word: vm.word,
|
||||
page: vm.page-1
|
||||
}
|
||||
this.$axios({
|
||||
method:'get',
|
||||
url:'/store-service/item',
|
||||
params : searchParam,
|
||||
responseType:'json'
|
||||
})
|
||||
.then(function (response) {
|
||||
const page = response.data.data.page;
|
||||
vm.menus = response.data.data.itemList;
|
||||
vm.page = page.startPage+1;
|
||||
vm.pageCount = page.totalPage;
|
||||
});
|
||||
},
|
||||
getModalData:function(){
|
||||
var vm =this;
|
||||
this.modalData = {
|
||||
itemName : '',
|
||||
itemPrice : 0,
|
||||
category: '',
|
||||
categoryList : [],
|
||||
requiredOption : [],
|
||||
otherOption : []
|
||||
}
|
||||
|
||||
this.$axios({
|
||||
method:'get',
|
||||
url:'/store-service/category',
|
||||
responseType:'json'
|
||||
})
|
||||
.then(function (response) {
|
||||
response.data.data.forEach(function (ele){
|
||||
vm.modalData.categoryList.push(ele.name)
|
||||
})
|
||||
});
|
||||
},
|
||||
editItem:function(item){
|
||||
var vm = this
|
||||
this.getModalData();
|
||||
// var vm =this;
|
||||
this.$axios({
|
||||
method:'get',
|
||||
url:'/store-service/item/'+item.id,
|
||||
responseType:'json'
|
||||
})
|
||||
.then(function (response) {
|
||||
var item = response.data.data;
|
||||
vm.modalData.itemId = item.id;
|
||||
vm.modalData.itemName = item.name;
|
||||
vm.modalData.itemPrice = item.price;
|
||||
vm.modalData.category = item.categoryName;
|
||||
item.itemOptions.forEach(function(ele){
|
||||
if(ele.optionType === "REQUIRED")
|
||||
vm.modalData.requiredOption.push(ele.name)
|
||||
else
|
||||
vm.modalData.otherOption.push(ele.name)
|
||||
})
|
||||
});
|
||||
console.log(this.modalData)
|
||||
},
|
||||
itemSave:function(){
|
||||
console.log(this.modalData)
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.getMenu()
|
||||
this.getModalData()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,12 +2,16 @@ package com.justpickup.storeservice.domain.item.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.itemoption.dto.ItemOptionDto;
|
||||
import com.justpickup.storeservice.global.entity.Yn;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -24,10 +28,11 @@ public class ItemDto {
|
||||
|
||||
private CategoryDto categoryDto;
|
||||
|
||||
private List<ItemOptionDto> itemOptions;
|
||||
|
||||
/*
|
||||
private PhotoDto photoDto;
|
||||
private StoreDto storeDto;
|
||||
private List<ItemOptionDto> itemOptionDtoList;
|
||||
*/
|
||||
|
||||
// == 생성 메소드 == //
|
||||
@@ -57,6 +62,19 @@ public class ItemDto {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ItemDto createWithCategoryItemDtoAndItemOption(Item item) {
|
||||
return ItemDto.builder()
|
||||
.id(item.getId())
|
||||
.name(item.getName())
|
||||
.categoryDto(new CategoryDto(item.getCategory()))
|
||||
.price(item.getPrice())
|
||||
.salesYn(item.getSalesYn())
|
||||
.itemOptions(item.getItemOptions()
|
||||
.stream().map(ItemOptionDto::new)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
// TODO: 2022/02/03 queryDsl 쿼리 생성 시 구현 필요
|
||||
// public static ItemDto createFullItemDto(Item item) {
|
||||
// return null
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package com.justpickup.storeservice.domain.item.service;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.exception.NotFoundStoreException;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemSearch;
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
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.store.entity.Store;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -37,7 +32,7 @@ public class ItemServiceImpl implements ItemService {
|
||||
Item findItem = itemRepository.findById(itemId)
|
||||
.orElseThrow(() -> new NotExistItemException("존재하지 않는 아이템 입니다."));
|
||||
|
||||
return ItemDto.createItemDto(findItem);
|
||||
return ItemDto.createWithCategoryItemDtoAndItemOption(findItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
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.ItemOption;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import com.justpickup.storeservice.global.dto.Result;
|
||||
import com.justpickup.storeservice.global.entity.Yn;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -83,8 +86,6 @@ public class ItemController {
|
||||
int startPage;
|
||||
int totalPage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -103,12 +104,37 @@ public class ItemController {
|
||||
private String name;
|
||||
private Yn salesYn;
|
||||
private Long price;
|
||||
private String CategoryName;
|
||||
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.CategoryName = itemDto.getCategoryDto().getName();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.justpickup.storeservice.domain.itemoption.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.OptionType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ItemOptionDto {
|
||||
|
||||
private Long id;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.justpickup.storeservice.domain.itemoption.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.itemoption.entity.ItemOption;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ItemOptionRepository extends JpaRepository<ItemOption,Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ItemOptionRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
|
||||
public List<ItemOption> findByItem(Long itemId) {
|
||||
|
||||
return queryFactory.selectFrom(QItemOption.itemOption)
|
||||
.join(QItemOption.itemOption.item)
|
||||
.on(QItem.item.id.eq(itemId))
|
||||
.fetch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.justpickup.storeservice.domain.itemoption.service;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.itemoption.dto.ItemOptionDto;
|
||||
import com.justpickup.storeservice.domain.itemoption.repository.ItemOptionRepository;
|
||||
import com.justpickup.storeservice.domain.itemoption.repository.ItemOptionRepositoryCustom;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ItemOptionService {
|
||||
private final ItemOptionRepositoryCustom itemOptionRepositoryCustom;
|
||||
|
||||
public List<ItemOptionDto> getItemOption( ItemDto itemDto){
|
||||
return itemOptionRepositoryCustom.findByItem(itemDto.getId())
|
||||
.stream().map(ItemOptionDto::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.justpickup.storeservice.domain.itemoption.web;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class ItemOptionController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user