mini-rbac/backend/controller/menu.py

32 lines
933 B
Python
Raw Normal View History

2022-09-12 15:22:18 +00:00
from fastapi import Query
2022-09-13 08:53:31 +00:00
from dbhelper.menu import del_menu, get_menus, insert_menu, put_menu
2022-09-12 15:22:18 +00:00
from schemas import ListAll, MenuIn, MenuRead, Response
2022-09-11 10:34:18 +00:00
async def menu_add(data: MenuIn) -> Response[MenuRead]:
2022-09-12 07:11:12 +00:00
return Response(data=await insert_menu(data))
2022-09-12 15:22:18 +00:00
async def menu_arr(
offset: int = Query(default=1, description="偏移量"),
limit: int = Query(default=10, description="数量"),
) -> Response[ListAll[list[MenuRead]]]:
skip = (offset - 1) * limit
menus, count = await get_menus(skip, limit)
return Response(data=ListAll(total=count, items=menus))
async def menu_del(pk: int) -> Response:
if await del_menu(pk) == 0:
return Response(code=400, msg="菜单不存在")
return Response()
2022-09-13 08:53:31 +00:00
async def menu_put(pk: int, data: MenuIn) -> Response:
"""更新菜单"""
if await put_menu(pk, data) == 0:
return Response(code=400, msg="菜单不存在")
return Response()