-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement announcment endpoints in info api
- Loading branch information
1 parent
c5c53eb
commit b9c9e88
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from ninja import Router | ||
from api.info_schema import AnnouncementSchema, SingleAnnouncementSchema | ||
from announcement.models import Announcement | ||
from api.utils import api_response | ||
|
||
# ============================ | ||
# Info Endpoints | ||
# ============================ | ||
router = Router(tags=["info"]) | ||
|
||
|
||
@router.get("/get_announcement", response=SingleAnnouncementSchema) | ||
def get_announcement(request): | ||
try: | ||
announcement = Announcement.objects.last() | ||
announcement_data = AnnouncementSchema.from_orm(announcement) | ||
|
||
return api_response( | ||
success=True, | ||
message="last announcement fetched successfully", | ||
payload=announcement_data.dict(), | ||
) | ||
except Exception as e: | ||
return api_response( | ||
success=False, message="Error occurd", error=e, status_code=503 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from ninja import ModelSchema | ||
from announcement.models import Announcement | ||
from api.schema import ApiResponseSchema, DataSchema | ||
|
||
|
||
class AnnouncementSchema(ModelSchema): | ||
class Meta: | ||
model = Announcement | ||
fields = [ | ||
"id", | ||
"title", | ||
"content", | ||
] | ||
|
||
|
||
class SingleAnnouncementDataSchema(DataSchema): | ||
payload: AnnouncementSchema | ||
|
||
|
||
class SingleAnnouncementSchema(ApiResponseSchema): | ||
data: SingleAnnouncementDataSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters