diff --git a/watchapedia/app/search/dto/requests.py b/watchapedia/app/search/dto/requests.py index fbc7225..89594cd 100644 --- a/watchapedia/app/search/dto/requests.py +++ b/watchapedia/app/search/dto/requests.py @@ -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 diff --git a/watchapedia/app/search/views.py b/watchapedia/app/search/views.py index f05f1f6..ac171d1 100644 --- a/watchapedia/app/search/views.py +++ b/watchapedia/app/search/views.py @@ -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() +