mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2024-11-25 10:43:44 +03:00
add hint schema
This commit is contained in:
parent
dbd347d71e
commit
17e1c066a4
|
@ -1,7 +1,8 @@
|
|||
from django.urls import path
|
||||
|
||||
from search.api.views import SearchApi
|
||||
from search.api.views import SearchApi, HintApi
|
||||
|
||||
urlpatterns = [
|
||||
path("search", SearchApi.as_view(), name="search_api")
|
||||
path("search", SearchApi.as_view(), name="search_api"),
|
||||
path("hint", HintApi.as_view(), name="hint api")
|
||||
]
|
||||
|
|
|
@ -19,3 +19,15 @@ class ResponseSerializer(serializers.Serializer):
|
|||
|
||||
def update(self, instance, validated_data):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
class HintRequestSerializer(serializers.Serializer):
|
||||
content = serializers.CharField()
|
||||
|
||||
def create(self, validated_data):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
class HintResponseSerializer(serializers.Serializer):
|
||||
type = serializers.CharField()
|
||||
content = serializers.CharField()
|
||||
|
|
|
@ -3,12 +3,13 @@ from drf_yasg.utils import swagger_auto_schema
|
|||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from search.api.serializers import HintRequestSerializer
|
||||
|
||||
from search.api.serializers import SearchSerializer, ResponseSerializer
|
||||
from search.api.serializers import SearchSerializer, ResponseSerializer, HintResponseSerializer
|
||||
from search.services.search import process_string
|
||||
|
||||
user_response = openapi.Response("search results", ResponseSerializer)
|
||||
|
||||
hint_response = openapi.Response("hints", HintResponseSerializer)
|
||||
|
||||
class SearchApi(APIView):
|
||||
@swagger_auto_schema(request_body=SearchSerializer, responses={200: user_response})
|
||||
|
@ -18,3 +19,17 @@ class SearchApi(APIView):
|
|||
return Response(
|
||||
process_string(serializer.data["body"]), status=status.HTTP_200_OK
|
||||
)
|
||||
|
||||
|
||||
class HintApi(APIView):
|
||||
@swagger_auto_schema(request_body=HintRequestSerializer, responses={200: hint_response})
|
||||
def post(self, request, format=None):
|
||||
serializer = HintRequestSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return Response(
|
||||
{
|
||||
'type': 'category',
|
||||
'value': serializer.data['content']
|
||||
},
|
||||
status=status.HTTP_200_OK
|
||||
)
|
|
@ -1,5 +1,6 @@
|
|||
from search.models import Product
|
||||
from typing import List
|
||||
|
||||
|
||||
def process_string(text: str) -> [dict]:
|
||||
def process_string(text: str) -> List[dict]:
|
||||
return [x.serialize_self() for x in Product.objects.filter(name__contains=text)[5:]]
|
||||
|
|
|
@ -2,7 +2,7 @@ djangorestframework==3.14.0
|
|||
Django==4.0.8
|
||||
django-cors-headers==3.13.0
|
||||
django-environ==0.9.0
|
||||
"drf-yasg[validation]"
|
||||
drf-yasg[validation]
|
||||
typing-extensions
|
||||
Pillow==9.2.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user