|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from typing import Annotated |
| 4 | + |
| 5 | +from fastapi import APIRouter, Depends, Path, Query |
| 6 | + |
| 7 | +from backend.app.admin.schema.notice import CreateNoticeParam, GetNoticeListDetails, UpdateNoticeParam |
| 8 | +from backend.app.admin.service.notice_service import notice_service |
| 9 | +from backend.common.pagination import DependsPagination, paging_data |
| 10 | +from backend.common.response.response_schema import ResponseModel, response_base |
| 11 | +from backend.common.security.jwt import DependsJwtAuth |
| 12 | +from backend.common.security.permission import RequestPermission |
| 13 | +from backend.common.security.rbac import DependsRBAC |
| 14 | +from backend.database.db import CurrentSession |
| 15 | + |
| 16 | +router = APIRouter() |
| 17 | + |
| 18 | + |
| 19 | +@router.get('/{pk}', summary='获取通知公告详情', dependencies=[DependsJwtAuth]) |
| 20 | +async def get_notice(pk: Annotated[int, Path(...)]) -> ResponseModel: |
| 21 | + notice = await notice_service.get(pk=pk) |
| 22 | + return response_base.success(data=notice) |
| 23 | + |
| 24 | + |
| 25 | +@router.get( |
| 26 | + '', |
| 27 | + summary='(模糊条件)分页获取所有通知公告', |
| 28 | + dependencies=[ |
| 29 | + DependsJwtAuth, |
| 30 | + DependsPagination, |
| 31 | + ], |
| 32 | +) |
| 33 | +async def get_pagination_notice(db: CurrentSession) -> ResponseModel: |
| 34 | + notice_select = await notice_service.get_select() |
| 35 | + page_data = await paging_data(db, notice_select, GetNoticeListDetails) |
| 36 | + return response_base.success(data=page_data) |
| 37 | + |
| 38 | + |
| 39 | +@router.post( |
| 40 | + '', |
| 41 | + summary='创建通知公告', |
| 42 | + dependencies=[ |
| 43 | + Depends(RequestPermission('sys:notice:add')), |
| 44 | + DependsRBAC, |
| 45 | + ], |
| 46 | +) |
| 47 | +async def create_notice(obj: CreateNoticeParam) -> ResponseModel: |
| 48 | + await notice_service.create(obj=obj) |
| 49 | + return response_base.success() |
| 50 | + |
| 51 | + |
| 52 | +@router.put( |
| 53 | + '/{pk}', |
| 54 | + summary='更新通知公告', |
| 55 | + dependencies=[ |
| 56 | + Depends(RequestPermission('sys:notice:edit')), |
| 57 | + DependsRBAC, |
| 58 | + ], |
| 59 | +) |
| 60 | +async def update_notice(pk: Annotated[int, Path(...)], obj: UpdateNoticeParam) -> ResponseModel: |
| 61 | + count = await notice_service.update(pk=pk, obj=obj) |
| 62 | + if count > 0: |
| 63 | + return response_base.success() |
| 64 | + return response_base.fail() |
| 65 | + |
| 66 | + |
| 67 | +@router.delete( |
| 68 | + '', |
| 69 | + summary='(批量)删除通知公告', |
| 70 | + dependencies=[ |
| 71 | + Depends(RequestPermission('sys:notice:del')), |
| 72 | + DependsRBAC, |
| 73 | + ], |
| 74 | +) |
| 75 | +async def delete_notice(pk: Annotated[list[int], Query(...)]) -> ResponseModel: |
| 76 | + count = await notice_service.delete(pk=pk) |
| 77 | + if count > 0: |
| 78 | + return response_base.success() |
| 79 | + return response_base.fail() |
0 commit comments