takahe/api/views/announcements.py

24 lines
673 B
Python
Raw Normal View History

2023-01-13 15:09:26 -08:00
from django.shortcuts import get_object_or_404
from hatchway import api_view
2023-01-13 15:09:26 -08:00
from api import schemas
from api.decorators import identity_required
from users.models import Announcement
from users.services import AnnouncementService
@identity_required
@api_view.get
def announcement_list(request) -> list[schemas.Announcement]:
2023-01-13 15:09:26 -08:00
return [
schemas.Announcement.from_announcement(a, request.user)
2023-01-13 15:09:26 -08:00
for a in AnnouncementService(request.user).visible()
]
@identity_required
@api_view.post
2023-01-13 15:09:26 -08:00
def announcement_dismiss(request, pk: str):
announcement = get_object_or_404(Announcement, pk=pk)
AnnouncementService(request.user).mark_seen(announcement)