2023-01-13 23:09:26 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
2023-02-14 04:17:26 +00:00
|
|
|
from hatchway import api_view
|
2023-01-13 23:09:26 +00:00
|
|
|
|
|
|
|
from api import schemas
|
2023-02-19 18:37:02 +00:00
|
|
|
from api.decorators import scope_required
|
2023-01-13 23:09:26 +00:00
|
|
|
from users.models import Announcement
|
|
|
|
from users.services import AnnouncementService
|
|
|
|
|
|
|
|
|
2023-02-19 18:37:02 +00:00
|
|
|
@scope_required("read:notifications")
|
2023-02-07 19:07:15 +00:00
|
|
|
@api_view.get
|
|
|
|
def announcement_list(request) -> list[schemas.Announcement]:
|
2023-01-13 23:09:26 +00:00
|
|
|
return [
|
2023-02-07 19:07:15 +00:00
|
|
|
schemas.Announcement.from_announcement(a, request.user)
|
2023-01-13 23:09:26 +00:00
|
|
|
for a in AnnouncementService(request.user).visible()
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2023-02-19 18:37:02 +00:00
|
|
|
@scope_required("write:notifications")
|
2023-02-07 19:07:15 +00:00
|
|
|
@api_view.post
|
2023-01-13 23:09:26 +00:00
|
|
|
def announcement_dismiss(request, pk: str):
|
|
|
|
announcement = get_object_or_404(Announcement, pk=pk)
|
|
|
|
AnnouncementService(request.user).mark_seen(announcement)
|