This commit is contained in:
2024-06-12 15:54:56 +03:00
parent 3fb38cac3a
commit 2951a559bc
13 changed files with 245 additions and 61 deletions

View File

@ -86,6 +86,13 @@ async def get_anon_user(
return anon_user
@router.patch("/anon")
async def get_anon_user(
anon_user: Annotated[schemas.AnonUser, Depends(services.patch_anon_name)]
) -> schemas.AnonUser:
return anon_user
@router.get(
"/captcha/{captcha_id}",
responses={200: {"content": {"image/png": {}}}},

View File

@ -48,3 +48,7 @@ class AnonUser(BaseModel):
class Config:
from_attributes = True
class AnonUserPatch(BaseModel):
name: str

View File

@ -147,6 +147,27 @@ def get_anon_user(
return create_anon_user(db)
def patch_anon_name(
data: schemas.AnonUserPatch,
db: Annotated[Session, Depends(get_db)],
x_client_id: Annotated[Union[str, None], Header()] = None,
) -> schemas.AnonUser:
if x_client_id:
anon = (
db.query(models.AnonymousUser)
.filter(models.AnonymousUser.id == x_client_id)
.first()
)
if anon:
setattr(anon, "name", data.name)
db.commit()
return anon
raise HTTPException(
status_code=status.HTTP_418_IM_A_TEAPOT,
)
return create_anon_user(db)
def get_captcha(
captcha_id: uuid.UUID, db: Annotated[Session, Depends(get_db)]
) -> BytesIO: