takahe/api/views/announcements.py
Andrew Godwin 5d2ed9edfe
Hatchway API Rewrite (#499)
Removes django-ninja and replaces it with a new API framework, "hatchway".

I plan to move hatchway into its own project very soon.
2023-02-07 12:07:15 -07:00

23 lines
673 B
Python

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