mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-18 06:42:51 +08:00

* WIP: add rbac authorization * Perform pre-commit fixes * add rbac route whitelist * add init test data user role associations * Restore database table id naming to fix generic crud base * Add database section value uniqueness settings * Update the test directory to tests * Update route_name file name to health_check * Split user auth and user action interfaces * Fix conflict between merge and current branch * Add pymysql dependencies * Fix RBAC authentication method * Add the select serialisation tool * Fix missing return messages due to global exception handler slicing * Update the user interface with associated relationships * Add items to be completed * Perform pre-commit fixes * Add pre-made routers * Paging data return structure optimisation * Split user auth and user interface tests * Fix user register test data structure error * Fix duplicate named test classes
44 lines
1010 B
Python
44 lines
1010 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from curses.ascii import isupper
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field, validator
|
|
|
|
from backend.app.common.enums import MethodType
|
|
|
|
|
|
class ApiBase(BaseModel):
|
|
name: str
|
|
method: str = Field(default=MethodType.GET, description='请求方法')
|
|
path: str = Field(..., description='api路径')
|
|
remark: str | None = None
|
|
|
|
@validator('method')
|
|
def check_method(cls, v):
|
|
if not isupper(v):
|
|
raise ValueError('请求方式必须大写')
|
|
allow_method = MethodType.get_member_values()
|
|
if v not in allow_method:
|
|
raise ValueError(f'请求方式不合法, 仅支持: {allow_method}')
|
|
return v
|
|
|
|
|
|
class CreateApi(ApiBase):
|
|
pass
|
|
|
|
|
|
class UpdateApi(ApiBase):
|
|
pass
|
|
|
|
|
|
class GetAllApi(ApiBase):
|
|
id: int
|
|
create_user: int
|
|
update_user: int = None
|
|
created_time: datetime
|
|
updated_time: datetime | None = None
|
|
|
|
class Config:
|
|
orm_mode = True
|