refactor(api): use Annotated-style dependency injection

This commit is contained in:
MingxuanGame
2025-10-03 05:41:31 +00:00
parent 37b4eadf79
commit 346c2557cf
45 changed files with 623 additions and 577 deletions

View File

@@ -1,13 +1,15 @@
from __future__ import annotations
from app.database import Relationship, User
from typing import Annotated
from app.database import Relationship
from app.database.relationship import RelationshipType
from app.dependencies.database import Database
from app.dependencies.user import get_client_user
from app.dependencies.user import ClientUser
from .router import router
from fastapi import HTTPException, Path, Security
from fastapi import HTTPException, Path
from pydantic import BaseModel, Field
from sqlmodel import select
@@ -27,8 +29,8 @@ class CheckResponse(BaseModel):
)
async def check_user_relationship(
db: Database,
user_id: int = Path(..., description="目标用户的 ID"),
current_user: User = Security(get_client_user),
user_id: Annotated[int, Path(..., description="目标用户的 ID")],
current_user: ClientUser,
):
if user_id == current_user.id:
raise HTTPException(422, "Cannot check relationship with yourself")