Skip to content

Commit

Permalink
Fix: 검색어 쿼리 형태로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
arcstone09 committed Jan 19, 2025
1 parent 601964d commit 57dc5a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 4 additions & 6 deletions watchapedia/app/search/dto/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
from watchapedia.common.errors import InvalidFieldFormatError
from typing import Annotated
from pydantic.functional_validators import AfterValidator
from fastapi import Query

def validate_search_query(value: str | None) -> str:
if len(value) > 100:
def validate_search_query(search_q: str = Query(...)) -> str:
if len(search_q) > 100:
raise InvalidFieldFormatError("search query")
return value

class SearchRequest(BaseModel):
search_query: Annotated[str | None, AfterValidator(validate_search_query)] = None
return search_q
11 changes: 6 additions & 5 deletions watchapedia/app/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
from fastapi import APIRouter, Depends

from watchapedia.app.search.service import SearchService
from watchapedia.app.search.dto.requests import SearchRequest
from watchapedia.app.search.dto.responses import SearchResponse
from watchapedia.app.search.dto.requests import validate_search_query

search_router = APIRouter()

@search_router.get("/", status_code=200, summary="검색", description="검색어와 일치하는 movie, user, participant, collection id 반환")
def search(search_request: SearchRequest,
search_service: Annotated[SearchService, Depends()]
@search_router.get("", status_code=200, summary="검색", description="검색어와 일치하는 movie, user, participant, collection id 반환")
def search(
search_service: Annotated[SearchService, Depends()],
search_q: str = Depends(validate_search_query)
) -> SearchResponse:
search_q = search_request.search_query
search_service.search(search_q)
return search_service.process_search_response()

0 comments on commit 57dc5a9

Please sign in to comment.