Fix: The route to update sort order of Menu Categories was not written.

This commit is contained in:
Amritanshu Agrawal 2021-04-27 07:22:04 +05:30
parent 59bab991fd
commit f78ad68235
3 changed files with 22 additions and 3 deletions

View File

@ -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,

View File

@ -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>;

View File

@ -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'