mirror of
https://github.com/lorsanstand/Aether.git
synced 2026-06-19 12:05:16 +03:00
Add searching users
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Dict
|
||||
from typing import Dict, List
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Response, Depends, UploadFile, File
|
||||
@@ -24,6 +24,15 @@ async def get_users(offset: int, limit: int, user: UserModel = Depends(get_curre
|
||||
log.info("Getting users list", extra={"offset": offset, "limit": limit})
|
||||
return await UserService.get_users_list(offset=offset, limit=limit)
|
||||
|
||||
@router.get("/search")
|
||||
async def search_users(
|
||||
username: str,
|
||||
offset: int = 0,
|
||||
limit: int = 30,
|
||||
user: UserModel = Depends(get_current_verified_user)
|
||||
) -> List[User]:
|
||||
return await UserService.search_users(username, offset, limit)
|
||||
|
||||
@router.get("/{user_id}")
|
||||
async def get_user(user_id: int, user: UserModel = Depends(get_current_verified_user)):
|
||||
return await UserService.get_user(user_id)
|
||||
|
||||
@@ -280,4 +280,13 @@ class UserService:
|
||||
obj_in={"avatar_url": None}
|
||||
)
|
||||
log.info("Avatar successfully deleted", extra={"user_id": user.id})
|
||||
await session.commit()
|
||||
await session.commit()
|
||||
|
||||
|
||||
@classmethod
|
||||
async def search_users(cls, username: str, offset: int = 0, limit: int = 30):
|
||||
async with async_session_maker() as session:
|
||||
|
||||
users = await UserDAO.find_all(session, offset, limit, UserModel.username.ilike(f"%{username}%"))
|
||||
log.debug("Search users")
|
||||
return users
|
||||
Reference in New Issue
Block a user