add notification api endpoint

This commit is contained in:
simon 2023-03-14 15:00:39 +07:00
parent 20f8a5a501
commit 259008df50
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 24 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from api.views import (
DownloadApiListView,
DownloadApiView,
LoginApiView,
NotificationView,
PingView,
PlaylistApiListView,
PlaylistApiVideoView,
@ -135,4 +136,9 @@ urlpatterns = [
SearchView.as_view(),
name="api-search",
),
path(
"notification/",
NotificationView.as_view(),
name="api-notification",
),
]

View File

@ -761,3 +761,21 @@ class SearchView(ApiBaseView):
search_results = SearchForm().multi_search(search_query)
return Response(search_results)
class NotificationView(ApiBaseView):
"""resolves to /api/notification/
GET: returns a list of notifications
filter query to filter messages by group
"""
valid_filters = ["download", "settings", "channel"]
def get(self, request):
"""get all notifications"""
query = "message"
filter_by = request.GET.get("filter", None)
if filter_by in self.valid_filters:
query = f"{query}:{filter_by}"
return Response(RedisArchivist().list_items(query))