add drf_spectacular, type and serialize channel app

This commit is contained in:
Simon
2025-02-09 17:41:12 +07:00
parent 93406ee0a4
commit df5a5cf449
9 changed files with 305 additions and 63 deletions

View File

@@ -0,0 +1,29 @@
"""common serializers"""
# pylint: disable=abstract-method
from rest_framework import serializers
class ErrorResponseSerializer(serializers.Serializer):
"""error message"""
error = serializers.CharField()
class PaginationSerializer(serializers.Serializer):
"""serialize paginate response"""
page_size = serializers.IntegerField()
page_from = serializers.IntegerField()
prev_pages = serializers.ListField(
child=serializers.IntegerField(), allow_null=True
)
current_page = serializers.IntegerField()
max_hits = serializers.BooleanField()
params = serializers.CharField()
last_page = serializers.BooleanField()
next_pages = serializers.ListField(
child=serializers.IntegerField(), allow_null=True
)
total_hits = serializers.IntegerField()

View File

@@ -106,7 +106,7 @@ class Pagination:
page_get = self.page_get
page_from = 0
if page_get in [0, 1]:
prev_pages = False
prev_pages = None
elif page_get > 1:
page_from = (page_get - 1) * self.page_size
prev_pages = [

View File

@@ -1,7 +1,5 @@
"""base classes to inherit from"""
from appsettings.src.config import AppConfig
from common.src.env_settings import EnvironmentSettings
from common.src.es_connect import ElasticWrap
from common.src.index_generic import Pagination
from common.src.search_processor import SearchProcess, process_aggs
@@ -45,13 +43,7 @@ class ApiBaseView(APIView):
def __init__(self):
super().__init__()
self.response = {
"data": False,
"config": {
"enable_cast": EnvironmentSettings.ENABLE_CAST,
"downloads": AppConfig().config["downloads"],
},
}
self.response = {}
self.data = {"query": {"match_all": {}}}
self.status_code = False
self.context = False
@@ -62,12 +54,12 @@ class ApiBaseView(APIView):
path = f"{self.search_base}{document_id}"
response, status_code = ElasticWrap(path).get()
try:
self.response["data"] = SearchProcess(
self.response = SearchProcess(
response, match_video_user_progress=progress_match
).process()
except KeyError:
print(f"item not found: {document_id}")
self.response["data"] = False
self.status_code = status_code
def initiate_pagination(self, request):