-
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.
feat: advanced filters for feedbacks and chats admin api (#525)
part of #389 --------- Co-authored-by: Mini256 <[email protected]>
- Loading branch information
Showing
15 changed files
with
277 additions
and
33 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,23 @@ | ||
from typing import Optional | ||
from fastapi import APIRouter, Depends | ||
from fastapi_pagination import Page, 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/chats"], | ||
) | ||
|
||
|
||
@router.get("/origins") | ||
def list_chat_origins( | ||
db_session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
search: Optional[str] = None, | ||
params: Params = Depends(), | ||
) -> Page[ChatOrigin]: | ||
return chat_repo.list_chat_origins(db_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
from fastapi import APIRouter, Depends | ||
from typing import Annotated, Optional | ||
|
||
from fastapi import APIRouter, Depends, Query | ||
from fastapi_pagination import Params, Page | ||
from fastapi_pagination.ext.sqlmodel import paginate | ||
from sqlmodel import select | ||
|
||
from app.api.deps import SessionDep, CurrentSuperuserDep | ||
from app.models import Feedback, AdminFeedbackPublic | ||
from app.models import AdminFeedbackPublic, FeedbackFilters | ||
from app.models.feedback import FeedbackOrigin | ||
from app.repositories import feedback_repo | ||
|
||
router = APIRouter() | ||
router = APIRouter( | ||
prefix="/admin/feedbacks", | ||
tags=["admin/feedback"], | ||
) | ||
|
||
|
||
@router.get("/admin/feedbacks") | ||
@router.get("/") | ||
def list_feedbacks( | ||
session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
filters: Annotated[FeedbackFilters, Query()], | ||
params: Params = Depends(), | ||
) -> Page[AdminFeedbackPublic]: | ||
return paginate( | ||
session, | ||
select(Feedback).order_by(Feedback.created_at.desc()), | ||
params, | ||
transformer=lambda items: [ | ||
AdminFeedbackPublic( | ||
**item.model_dump(), | ||
chat_title=item.chat.title, | ||
chat_origin=item.chat.origin, | ||
chat_message_content=item.chat_message.content, | ||
user_email=item.user.email if item.user else None, | ||
) | ||
for item in items | ||
], | ||
return feedback_repo.paginate( | ||
session=session, | ||
filters=filters, | ||
params=params, | ||
) | ||
|
||
|
||
@router.get("/origins") | ||
def list_feedback_origins( | ||
session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
search: Optional[str] = None, | ||
params: Params = Depends(), | ||
) -> Page[FeedbackOrigin]: | ||
return feedback_repo.list_feedback_origins(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Optional | ||
from fastapi import APIRouter, Depends | ||
from fastapi_pagination import Page, Params | ||
|
||
from app.repositories.user import user_repo | ||
from app.api.deps import SessionDep, CurrentSuperuserDep | ||
from app.api.admin_routes.models import ( | ||
UserDescriptor, | ||
) | ||
|
||
router = APIRouter( | ||
prefix="/admin/users", | ||
tags=["admin/users"], | ||
) | ||
|
||
|
||
@router.get("/search") | ||
def search_users( | ||
db_session: SessionDep, | ||
user: CurrentSuperuserDep, | ||
search: Optional[str] = None, | ||
params: Params = Depends(), | ||
) -> Page[UserDescriptor]: | ||
return user_repo.search_users(db_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.