### List User Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of a GET request to list users with pagination and search parameters. ```bash GET /api/v1/user/list?page=1&page_size=10&username=admin ``` -------------------------------- ### Install Dependencies and Run Frontend Development Server Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/00-目录和导航.md Steps to set up the frontend development environment. This involves navigating to the web directory, installing Node.js dependencies using pnpm, and starting the development server. ```bash cd web pnpm install pnpm dev ``` -------------------------------- ### Install Docker CE Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Installs Docker CE on a system using yum package manager and starts the Docker service. ```sh yum install -y docker-ce systemctl start docker ``` -------------------------------- ### Get User Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of a GET request to retrieve a single user by ID. ```bash GET /api/v1/user/get?user_id=1 ``` -------------------------------- ### Start Backend Service Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Starts the backend service using the 'run.py' script. ```sh python run.py ``` -------------------------------- ### Start Frontend Development Server Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Starts the frontend development server using pnpm. ```sh pnpm dev ``` -------------------------------- ### Create User Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of a POST request to create a new user with provided credentials. ```bash POST /api/v1/user/create Content-Type: application/json { "email": "user@example.com", "username": "user123", "password": "pass123" } ``` -------------------------------- ### Pagination Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of how to use pagination parameters to retrieve specific pages and record counts. ```bash GET /api/v1/user/list?page=2&page_size=20 # 获取第 2 页,每页 20 条记录 ``` -------------------------------- ### Complete FastAPI Route Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/06-API管理.md A comprehensive example of defining FastAPI routes with authentication, summary, and tags. This includes both GET and POST methods for user management. ```python from fastapi import APIRouter from app.core.dependency import DependAuth router = APIRouter() @router.get( "/list", summary="查看用户列表", tags=["用户管理"], dependencies=[DependAuth] ) async def list_users(): """获取所有用户列表,支持分页和搜索""" pass @router.post( "/create", summary="创建用户", tags=["用户管理"], dependencies=[DependAuth] ) async def create_user(): """创建新用户账号""" pass ``` -------------------------------- ### Install Frontend Dependencies with pnpm Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Installs pnpm globally if not already installed, then installs frontend project dependencies using pnpm. ```sh npm i -g pnpm # If pnpm is already installed, skip this step pnpm i # Or use npm i ``` -------------------------------- ### Install Frontend Dependencies with pnpm Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README.md Installs frontend dependencies using pnpm. It's recommended to install pnpm globally first if not already present. Navigate to the 'web' directory before running. ```sh npm i -g pnpm pnpm i ``` -------------------------------- ### Install Dependencies and Run Backend Server Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/00-目录和导航.md Steps to set up the backend development environment. This includes creating a virtual environment, installing Python dependencies, and running the FastAPI server. Access the API documentation at http://localhost:9999/docs. ```bash cd vue-fastapi-admin python3 -m venv venv source venv/bin/activate # Linux/Mac # 或 .\.venv\Scripts\activate # Windows pip install -r requirements.txt python run.py # 访问 http://localhost:9999 # API 文档:http://localhost:9999/docs ``` -------------------------------- ### Install uv and Create Virtual Environment Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Installs the 'uv' package manager and creates a virtual environment named '.venv'. ```sh pip install uv uv venv ``` -------------------------------- ### Update User Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of a POST request to update an existing user's information. ```bash POST /api/v1/user/update Content-Type: application/json { "id": 1, "email": "newemail@example.com", "username": "newname" } ``` -------------------------------- ### Install uv and Create Virtual Environment Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README.md Installs the 'uv' package manager and creates a virtual environment named '.venv'. This is the recommended method for managing backend dependencies. ```sh pip install uv uv venv source .venv/bin/activate ``` -------------------------------- ### Install Backend Dependencies with Pip Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Installs backend project dependencies from the requirements.txt file using pip. ```sh pip install -r requirements.txt ``` -------------------------------- ### Create Top-Level Menu (CATALOG) Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of creating a top-level menu of type CATALOG using curl. Ensure the token is valid and the request body matches the schema. ```bash curl -X POST http://localhost:9999/api/v1/menu/create \ -H "Content-Type: application/json" \ -H "token: {access_token}" \ -d '{ "name": "业务管理", "path": "/business", "menu_type": "CATALOG", "icon": "carbon:business", "order": 3, "parent_id": 0, "is_hidden": false, "component": "Layout", "keepalive": false, "redirect": "/business/order" }' ``` -------------------------------- ### 获取所有 GET 类型的 API Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 用于查询系统中所有支持 GET 请求的 API 列表,常用于权限分配前的准备工作。 ```bash # 获取所有 GET 类型的 API curl -X GET "http://localhost:9999/api/v1/api/list" \ -H "token: {admin_token}" ``` -------------------------------- ### Get Menu Detail Response Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of a successful response for retrieving a single menu's details. The response includes all properties of the specified menu item. ```json { "code": 200, "msg": "OK", "data": { "id": 2, "name": "用户管理", "path": "user", "menu_type": "MENU", "icon": "material-symbols:person-outline-rounded", "order": 1, "parent_id": 1, "is_hidden": false, "component": "/system/user", "keepalive": false, "redirect": null, "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } } ``` -------------------------------- ### Install Backend Dependencies with Pip Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README.md Installs project dependencies from 'requirements.txt' using pip, specifying a Tsinghua mirror for faster downloads. Ensure the virtual environment is activated. ```sh pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple ``` -------------------------------- ### Create Sub-Menu (MENU) Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of creating a sub-menu of type MENU using curl. The parent_id should reference an existing menu. ```bash curl -X POST http://localhost:9999/api/v1/menu/create \ -H "Content-Type: application/json" \ -H "token: {access_token}" \ -d '{ "name": "订单管理", "path": "order", "menu_type": "MENU", "icon": "mdi:shopping-outline", "order": 1, "parent_id": 7, "is_hidden": false, "component": "/business/order", "keepalive": false, "redirect": null }' ``` -------------------------------- ### Delete User Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Example of a DELETE request to remove a user by ID. ```bash DELETE /api/v1/user/delete?user_id=1 ``` -------------------------------- ### Update Menu Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of updating a menu item using curl. The 'id' field must correspond to an existing menu. ```bash curl -X POST http://localhost:9999/api/v1/menu/update \ -H "Content-Type: application/json" \ -H "token: {access_token}" \ -d '{ "id": 2, "name": "用户管理", "path": "user", "menu_type": "MENU", "icon": "mdi:account-multiple", "order": 2, "parent_id": 1, "is_hidden": false, "component": "/system/user", "keepalive": true, "redirect": null }' ``` -------------------------------- ### Development Mode Token Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/02-认证授权API.md Example using curl to bypass JWT authentication in development by sending 'dev' as the token. ```bash curl -X GET http://localhost:9999/api/v1/base/userinfo \ -H "token: dev" ``` -------------------------------- ### 查看角色列表 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 获取所有角色列表,支持分页和名称搜索。使用 GET 请求 `/api/v1/role/list`。 ```bash curl -X GET "http://localhost:9999/api/v1/role/list?page=1&page_size=20&role_name=管理" \ -H "token: {access_token}" ``` -------------------------------- ### GET /menu/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View a single menu. ```APIDOC ## GET /menu/get ### Description View a single menu. ### Method GET ### Endpoint /api/v1/menu/get ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /api/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View a single API. ```APIDOC ## GET /api/get ### Description View a single API. ### Method GET ### Endpoint /api/v1/api/get ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### Install Backend Dependencies with uv Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/README-en.md Adds project dependencies defined in pyproject.toml using the 'uv' package manager. ```sh uv add pyproject.toml ``` -------------------------------- ### 查看角色详情 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 获取单个角色的详细信息。使用 GET 请求 `/api/v1/role/get`,需要提供 `role_id`。 ```bash curl -X GET "http://localhost:9999/api/v1/role/get?role_id=1" \ -H "token: {access_token}" ``` -------------------------------- ### GET /api/v1/role/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 获取单个角色的详细信息。 ```APIDOC ## GET /api/v1/role/get ### Description 获取单个角色的详细信息。 ### Method GET ### Endpoint /api/v1/role/get #### Query Parameters - **role_id** (int) - Required - 角色 ID ### Request Example ```bash curl -X GET "http://localhost:9999/api/v1/role/get?role_id=1" \ -H "token: {access_token}" ``` ### Response #### Success Response (200) - **code** (int) - **msg** (string) - **data** (object) #### Response Example ```json { "code": 200, "msg": "OK", "data": { "id": 1, "name": "管理员", "desc": "管理员角色,拥有所有权限", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } } ``` ``` -------------------------------- ### Create API Success Response Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/06-API管理.md Example JSON response for a successful API creation. ```json { "code": 200, "msg": "Created Successfully", "data": null } ``` -------------------------------- ### 查看部门列表 API 请求示例 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/08-部门和审计日志API.md 使用 GET 请求获取部门列表,支持分页和按名称搜索。需要提供访问令牌。 ```bash curl -X GET "http://localhost:9999/api/v1/dept/list?page=1&page_size=20&name=技术" \ -H "token: {access_token}" ``` -------------------------------- ### List Response Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md JSON structure for a successful API response when returning a list of items, including pagination details. ```json { "code": 200, "msg": null, "data": [], "total": 0, "page": 1, "page_size": 20 } ``` -------------------------------- ### Get User Details Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/03-用户管理API.md Fetches detailed information for a specific user by their ID. Requires authentication. Returns a 404 if the user is not found. ```bash curl -X GET "http://localhost:9999/api/v1/user/get?user_id=1" \ -H "token: {access_token}" ``` -------------------------------- ### Get Menu List Response Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of a successful response for the menu list endpoint, showing a hierarchical structure with nested children. Note the 'total', 'page', and 'page_size' fields for pagination information. ```json { "code": 200, "msg": null, "data": [ { "id": 1, "name": "系统管理", "path": "/system", "menu_type": "CATALOG", "icon": "carbon:gui-management", "order": 1, "parent_id": 0, "is_hidden": false, "component": "Layout", "keepalive": false, "redirect": "/system/user", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00", "children": [ { "id": 2, "name": "用户管理", "path": "user", "menu_type": "MENU", "icon": "material-symbols:person-outline-rounded", "order": 1, "parent_id": 1, "is_hidden": false, "component": "/system/user", "keepalive": false, "redirect": null, "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00", "children": [] }, { "id": 3, "name": "角色管理", "path": "role", "menu_type": "MENU", "icon": "carbon:user-role", "order": 2, "parent_id": 1, "is_hidden": false, "component": "/system/role", "keepalive": false, "redirect": null, "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00", "children": [] } ] } ], "total": 2, "page": 1, "page_size": 20 } ``` -------------------------------- ### Dependency Injection Usage Examples Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/07-核心类和工具.md Illustrates how to use authentication and permission dependencies in FastAPI routes, including scenarios with single dependencies, combined dependencies, and multiple dependencies. ```APIDOC ## Dependency Injection Usage Examples ### Authentication Only Use `DependAuth` to verify user identity without checking specific permissions. ```python from app.core.dependency import DependAuth @router.get("/userinfo", dependencies=[DependAuth]) async def get_userinfo(): # Verifies user identity but does not check permissions user_id = CTX_USER_ID.get() pass ``` ### Authentication + Permission Use `DependPermission` to verify identity and check for necessary permissions. ```python from app.core.dependency import DependPermission @router.post("/create", dependencies=[DependPermission]) async def create_item(): # Verifies identity and checks permissions pass ``` ### Multiple Dependencies Combine multiple dependencies, such as `DependPermission` and `OtherDependency`, for more complex requirements. ```python @router.delete( "/delete", dependencies=[DependPermission, OtherDependency] ) async def delete_item(): pass ``` ``` -------------------------------- ### Using Multiple Dependencies in FastAPI Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/07-核心类和工具.md This example illustrates how to apply multiple dependencies, such as permission checks and other custom dependencies, to a FastAPI route. ```python @router.delete( "/delete", dependencies=[DependPermission, OtherDependency] ) async def delete_item(): pass ``` -------------------------------- ### Get User Menu API Request Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/00-目录和导航.md Retrieve the user's menu by sending a GET request with the user token. ```bash curl -X GET http://localhost:9999/api/v1/base/usermenu \ -H "token: {user_token}" ``` -------------------------------- ### Delete Menu Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Example of deleting a menu item using curl. The 'id' query parameter specifies the menu to be deleted. ```bash curl -X DELETE "http://localhost:9999/api/v1/menu/delete?id=8" \ -H "token: {access_token}" ``` -------------------------------- ### POST /menu/create Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Create a menu. ```APIDOC ## POST /menu/create ### Description Create a menu. ### Method POST ### Endpoint /api/v1/menu/create ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### Using Dependency Injection for Auth and Permissions Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/02-认证授权API.md Examples demonstrating how to use dependency injection for authentication (DependAuth) and permission checks (DependPermission) in FastAPI routes. ```python from app.core.dependency import DependAuth, DependPermission # 仅验证身份,不检查权限 @router.get("/endpoint", dependencies=[DependAuth]) async def some_endpoint(): pass # 验证身份并检查权限 @router.post("/endpoint", dependencies=[DependPermission]) async def protected_endpoint(): pass ``` -------------------------------- ### 创建角色 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 创建新角色。使用 POST 请求 `/api/v1/role/create`,请求体包含角色名称和描述。角色名必须唯一。 ```python class RoleCreate(BaseModel): name: str = Field(example="管理员") desc: str = Field("", example="管理员角色") ``` ```bash curl -X POST http://localhost:9999/api/v1/role/create \ -H "Content-Type: application/json" \ -H "token: {access_token}" \ -d '{ "name": "编辑", "desc": "编辑角色,可编辑内容" }' ``` -------------------------------- ### Create User with Multiple Roles Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/03-用户管理API.md This snippet shows how to create a regular user and assign them multiple roles. It also demonstrates assigning a department. ```bash curl -X POST http://localhost:9999/api/v1/user/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "email": "user@example.com", "username": "user123", "password": "userpass456", "is_active": true, "role_ids": [2, 3], "dept_id": 1 }' ``` -------------------------------- ### Using Dependency Injection Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/02-认证授权API.md Demonstrates how to integrate authentication and permission checks into FastAPI route handlers using dependency injection. ```APIDOC ## Dependency Injection for Auth and Permissions ### Description Illustrates the usage of `DependAuth` and `DependPermission` in FastAPI route definitions to enforce authentication and authorization. ### Usage ```python from app.core.dependency import DependAuth, DependPermission # Endpoint that only requires authentication @router.get("/endpoint", dependencies=[DependAuth]) async def some_endpoint(): pass # Endpoint that requires both authentication and permission checks @router.post("/endpoint", dependencies=[DependPermission]) async def protected_endpoint(): pass ``` ``` -------------------------------- ### Create New User and Assign Role Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Use this snippet to create a new user with specified credentials and assign them to a role. It includes a verification step to confirm the user creation. ```bash # 1. 创建用户 curl -X POST http://localhost:9999/api/v1/user/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "email": "newuser@example.com", "username": "newuser", "password": "pass123", "role_ids": [2] }' # 2. 获取该用户(确认创建成功) curl -X GET "http://localhost:9999/api/v1/user/list?username=newuser" \ -H "token: {admin_token}" ``` -------------------------------- ### POST /user/create Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Create a user. ```APIDOC ## POST /user/create ### Description Create a user. ### Method POST ### Endpoint /api/v1/user/create ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /api/v1/role/list Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 获取所有角色列表,支持分页和名称搜索。 ```APIDOC ## GET /api/v1/role/list ### Description 获取所有角色列表,支持分页和名称搜索。 ### Method GET ### Endpoint /api/v1/role/list #### Query Parameters - **page** (int) - Optional - 页码 - **page_size** (int) - Optional - 每页数量 - **role_name** (str) - Optional - 角色名称搜索(模糊匹配) ### Request Example ```bash curl -X GET "http://localhost:9999/api/v1/role/list?page=1&page_size=20&role_name=管理" \ -H "token: {access_token}" ``` ### Response #### Success Response (200) - **code** (int) - **msg** (null) - **data** (array) - List of role objects - **total** (int) - **page** (int) - **page_size** (int) #### Response Example ```json { "code": 200, "msg": null, "data": [ { "id": 1, "name": "管理员", "desc": "管理员角色,拥有所有权限", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" }, { "id": 2, "name": "普通用户", "desc": "普通用户角色,权限受限", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } ], "total": 2, "page": 1, "page_size": 20 } ``` ``` -------------------------------- ### Create Top-Level Menu Catalog Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Use this command to create a new top-level menu catalog. Ensure you provide all required fields like name, path, menu_type, and parent_id. ```bash curl -X POST http://localhost:9999/api/v1/menu/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "name": "报表管理", "path": "/report", "menu_type": "CATALOG", "icon": "mdi:chart-box-outline", "order": 4, "parent_id": 0, "is_hidden": false, "component": "Layout", "keepalive": false, "redirect": "/report/sales" }' ``` -------------------------------- ### GET /api/list Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View the list of APIs. ```APIDOC ## GET /api/list ### Description View the list of APIs. ### Method GET ### Endpoint /api/v1/api/list ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### Create New Menu and Configure Role Permissions Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md This snippet demonstrates creating a new menu item, refreshing the API list, and then assigning this new menu to a specific role. Ensure the role ID and menu IDs are correctly specified. ```bash # 1. 创建菜单 curl -X POST http://localhost:9999/api/v1/menu/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "name": "报表管理", "path": "/report", "menu_type": "CATALOG", "order": 4, "parent_id": 0, "component": "Layout" }' # 2. 刷新 API 列表 curl -X POST http://localhost:9999/api/v1/api/refresh \ -H "token: {admin_token}" # 3. 为角色分配菜单权限 curl -X POST http://localhost:9999/api/v1/role/authorized \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "id": 2, "menu_ids": [1, 2, 3, 7], "api_infos": [] }' ``` -------------------------------- ### GET /role/authorized Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View role permissions. ```APIDOC ## GET /role/authorized ### Description View role permissions. ### Method GET ### Endpoint /api/v1/role/authorized ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /role/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View a single role. ```APIDOC ## GET /role/get ### Description View a single role. ### Method GET ### Endpoint /api/v1/role/get ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### 临时撤销角色所有权限 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 撤销指定角色的所有菜单和 API 权限,使其无法访问任何功能。此操作用于临时禁用角色。 ```bash # 撤销所有权限(用户仍属于该角色,但无法访问任何功能) curl -X POST http://localhost:9999/api/v1/role/authorized \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "id": 4, "menu_ids": [], "api_infos": [] }' ``` -------------------------------- ### Create User Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/03-用户管理API.md Creates a new user account. Requires authentication. Handles email/username uniqueness and password hashing. Role assignment and department ID are optional. ```bash curl -X POST http://localhost:9999/api/v1/user/create \ -H "Content-Type: application/json" \ -H "token: {access_token}" \ -d '{ "email": "user@example.com", "username": "newuser", "password": "password123", "is_active": true, "is_superuser": false, "role_ids": [2], "dept_id": 1 }' ``` ```python class UserCreate(BaseModel): email: EmailStr = Field(example="admin@qq.com") username: str = Field(example="admin") password: str = Field(example="123456") is_active: Optional[bool] = True is_superuser: Optional[bool] = False role_ids: Optional[List[int]] = [] dept_id: Optional[int] = Field(0, description="部门ID") ``` ```python @router.post("/create", summary="创建用户") async def create_user(user_in: UserCreate): # 检查邮箱是否已存在 user = await user_controller.get_by_email(user_in.email) if user: return Fail(code=400, msg="The user with this email already exists in the system.") # 创建用户(密码自动哈希) new_user = await user_controller.create_user(obj_in=user_in) # 分配角色 await user_controller.update_roles(new_user, user_in.role_ids) return Success(msg="Created Successfully") ``` -------------------------------- ### GET /role/list Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View the list of roles. ```APIDOC ## GET /role/list ### Description View the list of roles. ### Method GET ### Endpoint /api/v1/role/list ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /user/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View a single user. ```APIDOC ## GET /user/get ### Description View a single user. ### Method GET ### Endpoint /api/v1/user/get ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### Using DependPermission for Authentication and Authorization Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/07-核心类和工具.md This example demonstrates using DependPermission in a FastAPI route to both authenticate users and check their permissions before allowing access. ```python from app.core.dependency import DependPermission @router.post("/create", dependencies=[DependPermission]) async def create_item(): # 验证身份并检查权限 pass ``` -------------------------------- ### 创建只读角色 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 创建一个新的角色,并为其指定名称和描述。此操作是分配权限的前提。 ```bash # 创建只读角色 curl -X POST http://localhost:9999/api/v1/role/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "name": "查看员", "desc": "仅可查看,不可编辑" }' ``` -------------------------------- ### GET /user/list Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View the list of users. ```APIDOC ## GET /user/list ### Description View the list of users. ### Method GET ### Endpoint /api/v1/user/list ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### 创建内容管理员角色 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 创建一个新的角色,用于管理内容。此操作是后续权限分配的基础。 ```bash # 先创建权限有限的新角色 curl -X POST http://localhost:9999/api/v1/role/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "name": "内容管理员", "desc": "可管理内容" }' ``` -------------------------------- ### GET /base/userinfo Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Retrieve current user information. ```APIDOC ## GET /base/userinfo ### Description Retrieve current user information. ### Method GET ### Endpoint /api/v1/base/userinfo ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### POST /role/create Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Create a role. ```APIDOC ## POST /role/create ### Description Create a role. ### Method POST ### Endpoint /api/v1/role/create ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### Create Admin User Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/03-用户管理API.md Use this endpoint to create a new administrator user with superuser privileges. Ensure you provide a valid admin token. ```bash curl -X POST http://localhost:9999/api/v1/user/create \ -H "Content-Type: application/json" \ -H "token: {admin_token}" \ -d '{ "email": "admin2@example.com", "username": "admin2", "password": "securepass123", "is_superuser": true, "role_ids": [1] }' ``` -------------------------------- ### GET /menu/list Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md View the list of menus (tree structure). ```APIDOC ## GET /menu/list ### Description View the list of menus (tree structure). ### Method GET ### Endpoint /api/v1/menu/list ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /base/userapi Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Retrieve the list of APIs callable by the user. ```APIDOC ## GET /base/userapi ### Description Retrieve the list of APIs callable by the user. ### Method GET ### Endpoint /api/v1/base/userapi ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### POST /api/create Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Create an API record. ```APIDOC ## POST /api/create ### Description Create an API record. ### Method POST ### Endpoint /api/v1/api/create ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### GET /base/usermenu Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Retrieve the list of menus accessible by the user. ```APIDOC ## GET /base/usermenu ### Description Retrieve the list of menus accessible by the user. ### Method GET ### Endpoint /api/v1/base/usermenu ### Parameters #### Query Parameters - None #### Request Body - None ### Response #### Success Response (200) - None specified in source #### Response Example - None specified in source ``` -------------------------------- ### 查看角色权限 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md 获取指定角色的菜单和API权限列表。需要提供角色ID作为查询参数。 ```bash curl -X GET "http://localhost:9999/api/v1/role/authorized?id=1" \ -H "token: {access_token}" ``` -------------------------------- ### 查看部门详情 API 请求示例 Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/08-部门和审计日志API.md 使用 GET 请求获取指定部门 ID 的详细信息。需要提供访问令牌。 ```bash curl -X GET "http://localhost:9999/api/v1/dept/get?dept_id=1" \ -H "token: {access_token}" ``` -------------------------------- ### GET /api/v1/role/authorized Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/04-角色与权限API.md Retrieves the menu and API permissions assigned to a specific role. ```APIDOC ## GET /api/v1/role/authorized ### Description Retrieves the menu and API permissions assigned to a specific role. ### Method GET ### Endpoint /api/v1/role/authorized ### Parameters #### Query Parameters - **id** (int) - Required - Role ID ### Request Example ```bash curl -X GET "http://localhost:9999/api/v1/role/authorized?id=1" \ -H "token: {access_token}" ``` ### Response #### Success Response (200) - **code** (int) - - **msg** (string) - - **data** (object) - - **id** (int) - - **name** (string) - - **desc** (string) - - **created_at** (string) - - **updated_at** (string) - - **menus** (array) - List of menus assigned to the role. - **id** (int) - - **name** (string) - - **path** (string) - - **menu_type** (string) - - **icon** (string) - - **order** (int) - - **parent_id** (int) - - **is_hidden** (boolean) - - **component** (string) - - **keepalive** (boolean) - - **redirect** (string) - - **created_at** (string) - - **updated_at** (string) - - **apis** (array) - List of APIs assigned to the role. - **id** (int) - - **path** (string) - - **method** (string) - - **summary** (string) - - **tags** (string) - - **created_at** (string) - - **updated_at** (string) - #### Response Example ```json { "code": 200, "msg": "OK", "data": { "id": 1, "name": "管理员", "desc": "管理员角色", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00", "menus": [ { "id": 1, "name": "系统管理", "path": "/system", "menu_type": "CATALOG", "icon": "carbon:gui-management", "order": 1, "parent_id": 0, "is_hidden": false, "component": "Layout", "keepalive": false, "redirect": "/system/user", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } ], "apis": [ { "id": 1, "path": "/api/v1/user/list", "method": "GET", "summary": "查看用户列表", "tags": "用户管理", "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } ] } } ``` ``` -------------------------------- ### API Path with Dynamic Parameters Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/06-API管理.md Illustrates how FastAPI automatically handles dynamic path parameters, converting them into placeholders in the database. The example shows a Python route definition and its corresponding database representation. ```python @router.get("/user/{user_id}") # 在代码中 ``` ```text /api/v1/user/{user_id} # 在数据库中 ``` -------------------------------- ### Error Response Example Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/10-API路由完整清单.md Standard JSON structure for an API error response. ```json { "code": 400, "msg": "错误信息", "data": null } ``` -------------------------------- ### GET /api/v1/menu/get Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/05-菜单API.md Retrieves the detailed information for a specific menu item based on its ID. ```APIDOC ## GET /api/v1/menu/get ### Description Retrieves the detailed information for a specific menu item based on its ID. ### Method GET ### Endpoint /api/v1/menu/get #### Query Parameters - **menu_id** (int) - Required - The ID of the menu to retrieve. ### Request Example ```bash curl -X GET "http://localhost:9999/api/v1/menu/get?menu_id=2" \ -H "token: {access_token}" ``` ### Response #### Success Response (200) - **code** (int) - Response code - **msg** (string) - Success message - **data** (object) - Object containing the menu details. - **id** (int) - Menu ID - **name** (string) - Menu name - **path** (string) - Menu path - **menu_type** (string) - Type of menu (e.g., MENU) - **icon** (string) - Icon associated with the menu - **order** (int) - Order of the menu in the list - **parent_id** (int) - ID of the parent menu - **is_hidden** (boolean) - Whether the menu is hidden - **component** (string) - The component associated with the menu - **keepalive** (boolean) - Whether to keep the component alive - **redirect** (string) - Redirect path - **created_at** (string) - Creation timestamp - **updated_at** (string) - Update timestamp #### Response Example ```json { "code": 200, "msg": "OK", "data": { "id": 2, "name": "用户管理", "path": "user", "menu_type": "MENU", "icon": "material-symbols:person-outline-rounded", "order": 1, "parent_id": 1, "is_hidden": false, "component": "/system/user", "keepalive": false, "redirect": null, "created_at": "2024-01-01 08:00:00", "updated_at": "2024-01-01 08:00:00" } } ``` ``` -------------------------------- ### Delete API Success Response Source: https://github.com/mizhexiaoxiao/vue-fastapi-admin/blob/main/_autodocs/06-API管理.md Example JSON response for a successful API deletion. ```json { "code": 200, "msg": "Deleted Success", "data": null } ```