Fix: The route to update sort order of Menu Categories was not written.
This commit is contained in:
parent
59bab991fd
commit
f78ad68235
@ -7,7 +7,7 @@ from typing import List, Optional
|
|||||||
import barker.schemas.menu_category as schemas
|
import barker.schemas.menu_category as schemas
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||||
from sqlalchemy import distinct, select
|
from sqlalchemy import distinct, select, update
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
|
||||||
from ..core.security import get_current_active_user as get_user
|
from ..core.security import get_current_active_user as get_user
|
||||||
@ -21,6 +21,25 @@ from . import effective_date
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/list", response_model=List[schemas.MenuCategory])
|
||||||
|
def sort_order(
|
||||||
|
data: List[schemas.MenuCategory],
|
||||||
|
user: UserToken = Security(get_user, scopes=["sections"]),
|
||||||
|
) -> List[schemas.MenuCategory]:
|
||||||
|
try:
|
||||||
|
with SessionFuture() as db:
|
||||||
|
for index, item in enumerate(data):
|
||||||
|
db.execute(update(MenuCategory).where(MenuCategory.id == item.id_).values(sort_order=index))
|
||||||
|
db.commit()
|
||||||
|
query = select(MenuCategory).order_by(MenuCategory.sort_order).order_by(MenuCategory.name)
|
||||||
|
return [menu_category_info(item) for item in db.execute(query).scalars().all()]
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=str(e),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.post("", response_model=schemas.MenuCategory)
|
@router.post("", response_model=schemas.MenuCategory)
|
||||||
def save(
|
def save(
|
||||||
data: schemas.MenuCategoryIn,
|
data: schemas.MenuCategoryIn,
|
||||||
|
@ -52,7 +52,7 @@ export class MenuCategoryService {
|
|||||||
|
|
||||||
updateSortOrder(list: MenuCategory[]): Observable<boolean> {
|
updateSortOrder(list: MenuCategory[]): Observable<boolean> {
|
||||||
return this.http
|
return this.http
|
||||||
.post<MenuCategory[]>(url, list, httpOptions)
|
.post<MenuCategory[]>(`${url}/list`, list, httpOptions)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'updateSortOrder')),
|
catchError(this.log.handleError(serviceName, 'updateSortOrder')),
|
||||||
) as Observable<boolean>;
|
) as Observable<boolean>;
|
||||||
|
@ -16,7 +16,7 @@ echo "No version bump"
|
|||||||
git push --tags
|
git push --tags
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd docker/app || exit
|
cd "$parent_path/docker/app" || exit
|
||||||
docker build --tag barker:latest .
|
docker build --tag barker:latest .
|
||||||
cd "$parent_path/docker" || exit
|
cd "$parent_path/docker" || exit
|
||||||
docker save barker:latest | bzip2 | pv | ssh tanshu@knox.tanshu.com 'bunzip2 | sudo docker load'
|
docker save barker:latest | bzip2 | pv | ssh tanshu@knox.tanshu.com 'bunzip2 | sudo docker load'
|
||||||
|
Loading…
Reference in New Issue
Block a user