validate playlist_type

This commit is contained in:
Simon 2024-02-17 15:02:42 +01:00
parent 8dadaa4979
commit c91a31c9e3
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 14 additions and 6 deletions

View File

@ -462,17 +462,25 @@ class PlaylistApiListView(ApiBaseView):
search_base = "ta_playlist/_search/"
permission_classes = [AdminWriteOnly]
valid_playlist_type = ["regular", "custom"]
def get(self, request):
"""handle get request"""
playlist_type = request.GET.get("playlist_type", None)
query = {"sort": [{"playlist_name.keyword": {"order": "asc"}}]}
if playlist_type is not None:
query = {
"query": {"term": {"playlist_type": {"value": playlist_type}}},
"sort": [{"playlist_name.keyword": {"order": "asc"}}],
}
else:
query = {"sort": [{"playlist_name.keyword": {"order": "asc"}}]}
if playlist_type not in self.valid_playlist_type:
message = f"invalid playlist_type {playlist_type}"
return Response({"message": message}, status=400)
query.update(
{
"query": {
"term": {"playlist_type": {"value": playlist_type}}
},
}
)
self.data.update(query)
self.get_document_list(request)
return Response(self.response)