refactor(api): standardizate API Router
This commit is contained in:
@@ -14,10 +14,7 @@ from .router import router
|
||||
from fastapi import Depends, File, Security
|
||||
|
||||
|
||||
@router.post(
|
||||
"/avatar/upload",
|
||||
name="上传头像",
|
||||
)
|
||||
@router.post("/avatar/upload", name="上传头像", tags=["用户", "g0v0 API"])
|
||||
async def upload_avatar(
|
||||
session: Database,
|
||||
content: bytes = File(...),
|
||||
|
||||
@@ -14,7 +14,12 @@ from fastapi import Body, HTTPException, Security
|
||||
from sqlmodel import col, exists, select
|
||||
|
||||
|
||||
@router.get("/beatmapsets/{beatmapset_id}/can_rate", name="判断用户能否为谱面集打分", response_model=bool)
|
||||
@router.get(
|
||||
"/beatmapsets/{beatmapset_id}/can_rate",
|
||||
name="判断用户能否为谱面集打分",
|
||||
response_model=bool,
|
||||
tags=["谱面集", "g0v0 API"],
|
||||
)
|
||||
async def can_rate_beatmapset(
|
||||
beatmapset_id: int,
|
||||
session: Database,
|
||||
@@ -44,7 +49,9 @@ async def can_rate_beatmapset(
|
||||
return (await session.exec(query)).first() or False
|
||||
|
||||
|
||||
@router.post("/beatmapsets/{beatmapset_id}/ratings", name="上传对谱面集的打分", status_code=201)
|
||||
@router.post(
|
||||
"/beatmapsets/{beatmapset_id}/ratings", name="上传对谱面集的打分", status_code=201, tags=["谱面集", "g0v0 API"]
|
||||
)
|
||||
async def rate_beatmaps(
|
||||
beatmapset_id: int,
|
||||
session: Database,
|
||||
|
||||
@@ -14,10 +14,7 @@ from .router import router
|
||||
from fastapi import Depends, File, Security
|
||||
|
||||
|
||||
@router.post(
|
||||
"/cover/upload",
|
||||
name="上传头图",
|
||||
)
|
||||
@router.post("/cover/upload", name="上传头图", tags=["用户", "g0v0 API"])
|
||||
async def upload_cover(
|
||||
session: Database,
|
||||
content: bytes = File(...),
|
||||
|
||||
@@ -18,6 +18,7 @@ from sqlmodel import select, text
|
||||
"/oauth-app/create",
|
||||
name="创建 OAuth 应用",
|
||||
description="创建一个新的 OAuth 应用程序,并生成客户端 ID 和密钥",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def create_oauth_app(
|
||||
session: Database,
|
||||
@@ -58,6 +59,7 @@ async def create_oauth_app(
|
||||
"/oauth-apps/{client_id}",
|
||||
name="获取 OAuth 应用信息",
|
||||
description="通过客户端 ID 获取 OAuth 应用的详细信息",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def get_oauth_app(
|
||||
session: Database,
|
||||
@@ -79,6 +81,7 @@ async def get_oauth_app(
|
||||
"/oauth-apps",
|
||||
name="获取用户的 OAuth 应用列表",
|
||||
description="获取当前用户创建的所有 OAuth 应用程序",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def get_user_oauth_apps(
|
||||
session: Database,
|
||||
@@ -101,6 +104,7 @@ async def get_user_oauth_apps(
|
||||
status_code=204,
|
||||
name="删除 OAuth 应用",
|
||||
description="删除指定的 OAuth 应用程序及其关联的所有令牌",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def delete_oauth_app(
|
||||
session: Database,
|
||||
@@ -125,6 +129,7 @@ async def delete_oauth_app(
|
||||
"/oauth-app/{client_id}",
|
||||
name="更新 OAuth 应用",
|
||||
description="更新指定 OAuth 应用的名称、描述和重定向 URI",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def update_oauth_app(
|
||||
session: Database,
|
||||
@@ -158,6 +163,7 @@ async def update_oauth_app(
|
||||
"/oauth-app/{client_id}/refresh",
|
||||
name="刷新 OAuth 密钥",
|
||||
description="为指定的 OAuth 应用生成新的客户端密钥,并使所有现有的令牌失效",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def refresh_secret(
|
||||
session: Database,
|
||||
@@ -189,6 +195,7 @@ async def refresh_secret(
|
||||
"/oauth-app/{client_id}/code",
|
||||
name="生成 OAuth 授权码",
|
||||
description="为特定用户和 OAuth 应用生成授权码,用于授权码授权流程",
|
||||
tags=["osu! OAuth 认证", "g0v0 API"],
|
||||
)
|
||||
async def generate_oauth_code(
|
||||
session: Database,
|
||||
|
||||
@@ -23,6 +23,7 @@ class CheckResponse(BaseModel):
|
||||
name="检查关系状态",
|
||||
description="检查当前用户与指定用户的关系状态",
|
||||
response_model=CheckResponse,
|
||||
tags=["用户关系", "g0v0 API"],
|
||||
)
|
||||
async def check_user_relationship(
|
||||
db: Database,
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.config import settings
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/api/private",
|
||||
include_in_schema=settings.debug,
|
||||
tags=["私有 API"],
|
||||
)
|
||||
router = APIRouter(prefix="/api/private")
|
||||
|
||||
@@ -23,7 +23,7 @@ from pydantic import BaseModel
|
||||
from sqlmodel import exists, select
|
||||
|
||||
|
||||
@router.post("/team", name="创建战队", response_model=Team)
|
||||
@router.post("/team", name="创建战队", response_model=Team, tags=["战队", "g0v0 API"])
|
||||
async def create_team(
|
||||
session: Database,
|
||||
storage: StorageService = Depends(get_storage_service),
|
||||
@@ -78,7 +78,7 @@ async def create_team(
|
||||
return team
|
||||
|
||||
|
||||
@router.patch("/team/{team_id}", name="修改战队", response_model=Team)
|
||||
@router.patch("/team/{team_id}", name="修改战队", response_model=Team, tags=["战队", "g0v0 API"])
|
||||
async def update_team(
|
||||
team_id: int,
|
||||
session: Database,
|
||||
@@ -152,7 +152,7 @@ async def update_team(
|
||||
return team
|
||||
|
||||
|
||||
@router.delete("/team/{team_id}", name="删除战队", status_code=204)
|
||||
@router.delete("/team/{team_id}", name="删除战队", status_code=204, tags=["战队", "g0v0 API"])
|
||||
async def delete_team(
|
||||
session: Database,
|
||||
team_id: int = Path(..., description="战队 ID"),
|
||||
@@ -178,7 +178,7 @@ class TeamQueryResp(BaseModel):
|
||||
members: list[UserResp]
|
||||
|
||||
|
||||
@router.get("/team/{team_id}", name="查询战队", response_model=TeamQueryResp)
|
||||
@router.get("/team/{team_id}", name="查询战队", response_model=TeamQueryResp, tags=["用户", "g0v0 API"])
|
||||
async def get_team(
|
||||
session: Database,
|
||||
team_id: int = Path(..., description="战队 ID"),
|
||||
@@ -190,7 +190,7 @@ async def get_team(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/team/{team_id}/request", name="请求加入战队", status_code=204)
|
||||
@router.post("/team/{team_id}/request", name="请求加入战队", status_code=204, tags=["战队", "g0v0 API"])
|
||||
async def request_join_team(
|
||||
session: Database,
|
||||
team_id: int = Path(..., description="战队 ID"),
|
||||
@@ -216,8 +216,8 @@ async def request_join_team(
|
||||
await server.new_private_notification(TeamApplicationStore.init(team_request))
|
||||
|
||||
|
||||
@router.post("/team/{team_id}/{user_id}/request", name="接受加入请求", status_code=204)
|
||||
@router.delete("/team/{team_id}/{user_id}/request", name="拒绝加入请求", status_code=204)
|
||||
@router.post("/team/{team_id}/{user_id}/request", name="接受加入请求", status_code=204, tags=["战队", "g0v0 API"])
|
||||
@router.delete("/team/{team_id}/{user_id}/request", name="拒绝加入请求", status_code=204, tags=["战队", "g0v0 API"])
|
||||
async def handle_request(
|
||||
req: Request,
|
||||
session: Database,
|
||||
@@ -255,7 +255,7 @@ async def handle_request(
|
||||
await session.commit()
|
||||
|
||||
|
||||
@router.delete("/team/{team_id}/{user_id}", name="踢出成员 / 退出战队", status_code=204)
|
||||
@router.delete("/team/{team_id}/{user_id}", name="踢出成员 / 退出战队", status_code=204, tags=["战队", "g0v0 API"])
|
||||
async def kick_member(
|
||||
session: Database,
|
||||
team_id: int = Path(..., description="战队 ID"),
|
||||
|
||||
@@ -14,10 +14,7 @@ from fastapi import Body, HTTPException, Security
|
||||
from sqlmodel import exists, select
|
||||
|
||||
|
||||
@router.post(
|
||||
"/rename",
|
||||
name="修改用户名",
|
||||
)
|
||||
@router.post("/rename", name="修改用户名", tags=["用户", "g0v0 API"])
|
||||
async def user_rename(
|
||||
session: Database,
|
||||
new_name: str = Body(..., description="新的用户名"),
|
||||
|
||||
Reference in New Issue
Block a user