Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added search queries functionality to fags #961

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions api/v1/routes/faq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, Depends, status, Query
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session
from typing import Optional

from api.db.database import get_db
from api.utils.pagination import paginated_response
Expand All @@ -15,10 +16,19 @@


@faq.get("", response_model=success_response, status_code=200)
async def get_all_faqs(db: Session = Depends(get_db),):
"""Endpoint to get all FAQs"""
async def get_all_faqs(
db: Session = Depends(get_db),
keyword: Optional[str] = Query(None, min_length=1)
):
"""Endpoint to get all FAQs or search by keyword in both question and answer"""

query_params = {}
if keyword:
"""Search by both question and answer fields"""
query_params["question"] = keyword
query_params["answer"] = keyword

faqs = faq_service.fetch_all(db=db)
faqs = faq_service.fetch_all(db=db, **query_params)

return success_response(
status_code=200,
Expand All @@ -27,6 +37,7 @@ async def get_all_faqs(db: Session = Depends(get_db),):
)



@faq.post("", response_model=success_response, status_code=201)
async def create_faq(
schema: CreateFAQ,
Expand Down
Loading