feat(owner-vue, store-service): 메뉴 관리 페이지네이션, 검색
owner-vue에 menu 화면 개발, store-service에 menu pagenation 개발
This commit is contained in:
@@ -14,6 +14,11 @@ const routes = [
|
||||
name: 'category',
|
||||
component: () => import('./../views/Category')
|
||||
},
|
||||
{
|
||||
path: '/menu',
|
||||
name: 'menu',
|
||||
component: () => import('./../views/Menu')
|
||||
},
|
||||
]
|
||||
|
||||
const router = new VueRouter({
|
||||
|
||||
@@ -133,13 +133,13 @@ export default {
|
||||
url:'/store-service/category',
|
||||
responseType:'json'
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log(response.data.data)
|
||||
vm.categoryList = response.data.data;
|
||||
});
|
||||
.then(function (response) {
|
||||
console.log(response.data.data)
|
||||
vm.categoryList = response.data.data;
|
||||
});
|
||||
}
|
||||
},
|
||||
created() {
|
||||
mounted() {
|
||||
this.getCategoryList();
|
||||
}
|
||||
}
|
||||
|
||||
122
owner-vue/src/views/Menu.vue
Normal file
122
owner-vue/src/views/Menu.vue
Normal file
@@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<div>
|
||||
<v-subheader class="py-0 d-flex justify-space-between rounded-lg">
|
||||
<h3>메뉴 관리</h3>
|
||||
</v-subheader>
|
||||
<v-form @submit.prevent>
|
||||
<v-container>
|
||||
<v-row>
|
||||
<v-col
|
||||
cols="12"
|
||||
md="4"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="word"
|
||||
label="검색"
|
||||
required
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-form>
|
||||
<v-col>
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="menus"
|
||||
:items-per-page="itemsPerPage"
|
||||
hide-default-footer
|
||||
class="elevation-1"
|
||||
>
|
||||
</v-data-table>
|
||||
<div class="text-center pt-2">
|
||||
<v-pagination
|
||||
v-model="page"
|
||||
:length="pageCount"
|
||||
:total-visible="totalVisible"
|
||||
@click="getMenu"
|
||||
></v-pagination>
|
||||
</div>
|
||||
</v-col>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
mdiContentSave, mdiDelete,
|
||||
mdiPlus,
|
||||
|
||||
} from '@mdi/js'
|
||||
import axios from "axios";
|
||||
|
||||
export default {
|
||||
name: "Category",
|
||||
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;
|
||||
});
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
page:function () {
|
||||
this.getMenu();
|
||||
},
|
||||
word:function () {
|
||||
if(this.page == 1)
|
||||
this.getMenu()
|
||||
else
|
||||
this.page =1;
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.getMenu()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -1,11 +1,17 @@
|
||||
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.global.entity.Yn;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ItemDto {
|
||||
|
||||
private Long id;
|
||||
@@ -16,15 +22,15 @@ public class ItemDto {
|
||||
|
||||
private Long price;
|
||||
|
||||
private CategoryDto categoryDto;
|
||||
|
||||
/*
|
||||
private PhotoDto photoDto;
|
||||
private CategoryDto categoryDto;
|
||||
private StoreDto storeDto;
|
||||
private List<ItemOptionDto> itemOptionDtoList;
|
||||
*/
|
||||
|
||||
// == 생성 메소드 == //
|
||||
@Builder
|
||||
public ItemDto(Long id, String name, Yn salesYn, Long price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@@ -41,6 +47,16 @@ public class ItemDto {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ItemDto createWithCategoryItemDto(Item item) {
|
||||
return ItemDto.builder()
|
||||
.id(item.getId())
|
||||
.name(item.getName())
|
||||
.categoryDto(new CategoryDto(item.getCategory()))
|
||||
.price(item.getPrice())
|
||||
.salesYn(item.getSalesYn())
|
||||
.build();
|
||||
}
|
||||
|
||||
// TODO: 2022/02/03 queryDsl 쿼리 생성 시 구현 필요
|
||||
// public static ItemDto createFullItemDto(Item item) {
|
||||
// return null
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.justpickup.storeservice.domain.item.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ItemSearch {
|
||||
|
||||
@NotNull
|
||||
private String type;
|
||||
|
||||
private String word;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.justpickup.storeservice.domain.item.repository;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.entity.QCategory;
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.item.entity.QItem;
|
||||
import com.justpickup.storeservice.domain.store.entity.QStore;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ItemRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
|
||||
public Page<Item> findItem(Long storeId,String word, Pageable pageable){
|
||||
|
||||
//count 가져오기
|
||||
Long count = queryFactory.select(QItem.item.count())
|
||||
.from(QItem.item)
|
||||
.join(QItem.item.category)
|
||||
.leftJoin(QItem.item.store)
|
||||
.on(QItem.item.store.id.eq(storeId))
|
||||
.where(
|
||||
QItem.item.name.contains(word)
|
||||
.or(QItem.item.category.name.contains(word))
|
||||
)
|
||||
.limit(pageable.getPageSize())
|
||||
.offset(pageable.getOffset())
|
||||
.fetchOne();
|
||||
|
||||
//List 가져오기
|
||||
List<Item> itemList = queryFactory.selectFrom(QItem.item)
|
||||
.join(QItem.item.category).fetchJoin()
|
||||
.leftJoin(QItem.item.store)
|
||||
.on(QItem.item.store.id.eq(storeId))
|
||||
.where(
|
||||
QItem.item.name.contains(word)
|
||||
.or(QItem.item.category.name.contains(word))
|
||||
)
|
||||
.limit(pageable.getPageSize())
|
||||
.offset(pageable.getOffset())
|
||||
.fetch();
|
||||
|
||||
return PageableExecutionUtils.getPage(itemList,pageable,() -> count);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.justpickup.storeservice.domain.item.service;
|
||||
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ItemService {
|
||||
|
||||
ItemDto findItemByItemId(Long itemId);
|
||||
|
||||
Page<ItemDto> findItemList(Long storeId,String word, Pageable pageable);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
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
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@@ -16,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class ItemServiceImpl implements ItemService {
|
||||
|
||||
private final ItemRepository itemRepository;
|
||||
private final ItemRepositoryCustom itemRepositoryCustom;
|
||||
private final StoreRepository storeRepository;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -25,4 +39,15 @@ public class ItemServiceImpl implements ItemService {
|
||||
|
||||
return ItemDto.createItemDto(findItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ItemDto> findItemList( Long storeId,String word, Pageable pageable) {
|
||||
|
||||
Page<Item> itemList = itemRepositoryCustom.findItem(storeId,word,pageable);
|
||||
return PageableExecutionUtils.getPage(itemList.stream()
|
||||
.map(ItemDto::createWithCategoryItemDto)
|
||||
.collect(Collectors.toList()),pageable,itemList::getTotalElements);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.justpickup.storeservice.domain.item.web;
|
||||
|
||||
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.global.dto.Result;
|
||||
@@ -8,21 +10,85 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
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.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/item")
|
||||
public class ItemController {
|
||||
|
||||
private final ItemService itemService;
|
||||
|
||||
@GetMapping("/{itemId}")
|
||||
@GetMapping("/item")
|
||||
public ResponseEntity<Result<GetItemResponse>> getItemList( @RequestParam String word,
|
||||
@PageableDefault(page = 0, size = 10) Pageable pageable){
|
||||
|
||||
Long storeId = 1L;
|
||||
|
||||
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.findItemByItemId(itemId);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 0
|
||||
port: 12343
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
||||
Reference in New Issue
Block a user