-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
177 additions
and
126 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from fastapi import APIRouter, Depends | ||
from fastapi_pagination import Params | ||
|
||
from app.models.chat import ChatOrigin | ||
from app.api.deps import CurrentSuperuserDep, SessionDep | ||
from app.repositories import chat_repo | ||
|
||
|
||
router = APIRouter( | ||
prefix="/admin/chats", | ||
tags=["admin/chat"], | ||
) | ||
|
||
|
||
@router.get("/origins") | ||
def list_chat_origins( | ||
session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
params: Params = Depends(), | ||
) -> list[ChatOrigin]: | ||
return chat_repo.list_chat_origins(session, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
from fastapi import APIRouter, Depends | ||
from fastapi_pagination import Params | ||
from sqlmodel import select | ||
|
||
from app.api.deps import SessionDep, CurrentSuperuserDep | ||
from app.models import User | ||
|
||
from app.repositories.user import user_repo | ||
from app.api.deps import SessionDep, CurrentSuperuserDep | ||
from app.api.admin_routes.models import ( | ||
UserDescriptor, | ||
) | ||
from fuzzywuzzy import process | ||
|
||
router = APIRouter() | ||
router = APIRouter( | ||
prefix="/admin/users", | ||
tags=["admin/user"], | ||
) | ||
|
||
|
||
@router.get("/admin/users/search") | ||
@router.get("/search") | ||
def search_users( | ||
session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
search: str | None = None, | ||
params: Params = Depends(), | ||
) -> list[UserDescriptor]: | ||
users = [] | ||
for user in session.exec(select(User).order_by(User.id)): | ||
users.append(UserDescriptor(id=user.id, email=user.email)) | ||
# when search is empty, return all users | ||
if not search: | ||
return users | ||
# when search is not empty, filter users by email | ||
emails = [user.email for user in users] | ||
matches = process.extract(search, emails, limit=len(emails)) | ||
|
||
threshold = 70 | ||
matched_emails = {match[0] for match in matches if match[1] >= threshold} | ||
|
||
return [user for user in users if user.email in matched_emails] | ||
return user_repo.search_users(session, search, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.