[API] add filter subscribed to channel list

This commit is contained in:
simon 2023-02-14 11:12:58 +07:00
parent 6641db3e7e
commit 5ec0636807
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 17 additions and 1 deletions

View File

@ -155,6 +155,9 @@ Timestamps either *int* or *float*, end time can't be before start time.
## Channel List View
/api/channel/
Parameter:
- filter: subscribed
### Subscribe to a list of channels
POST /api/channel/
```json

View File

@ -289,14 +289,27 @@ class ChannelApiListView(ApiBaseView):
"""
search_base = "ta_channel/_search/"
valid_filter = ["subscribed"]
def get(self, request):
"""get request"""
self.get_document_list(request)
self.data.update(
{"sort": [{"channel_name.keyword": {"order": "asc"}}]}
)
query_filter = request.GET.get("filter", False)
must_list = []
if query_filter:
if query_filter not in self.valid_filter:
message = f"invalid url query filder: {query_filter}"
print(message)
return Response({"message": message}, status=400)
must_list.append({"term": {"channel_subscribed": {"value": True}}})
self.data["query"] = {"bool": {"must": must_list}}
self.get_document_list(request)
return Response(self.response)
@staticmethod