mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-11 13:56:17 +00:00
feat: Add announcements endpoints (#91)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alexandre Teles (afterSt0rm) <alexandre.teles@ufba.br>
This commit is contained in:
37
api/models/announcements.py
Normal file
37
api/models/announcements.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from data.models import AnnouncementDbModel
|
||||
|
||||
|
||||
class ContentFields(dict):
|
||||
message: str | None
|
||||
attachment_urls: list[str] | None
|
||||
|
||||
|
||||
class AnnouncementResponseModel(dict):
|
||||
id: int
|
||||
author: str | None
|
||||
title: str
|
||||
content: ContentFields | None
|
||||
channel: str
|
||||
created_at: str
|
||||
level: int | None
|
||||
|
||||
@staticmethod
|
||||
def to_response(announcement: AnnouncementDbModel):
|
||||
response = AnnouncementResponseModel(
|
||||
id=announcement.id,
|
||||
author=announcement.author,
|
||||
title=announcement.title,
|
||||
content=ContentFields(
|
||||
message=announcement.message,
|
||||
attachment_urls=[
|
||||
attachment.attachment_url for attachment in announcement.attachments
|
||||
],
|
||||
)
|
||||
if announcement.message or announcement.attachments
|
||||
else None,
|
||||
channel=announcement.channel,
|
||||
created_at=str(announcement.created_at),
|
||||
level=announcement.level,
|
||||
)
|
||||
|
||||
return response
|
||||
Reference in New Issue
Block a user