Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified backend/myproject/announcements/__pycache__/api.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/announcements/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/announcements/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 63 additions & 5 deletions backend/myproject/announcements/api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from django.shortcuts import get_object_or_404
from django.middleware.csrf import get_token
from ninja_extra import NinjaExtraAPI, ControllerBase, api_controller, route
from .models import PostModel
from django.middleware.csrf import get_token
from django.core.paginator import Paginator
from .models import PostModel, NotificationModel
from . import schemas
from .schemas import PostSchema
from .services import AnnouncementService

@api_controller("/posts", tags="Posts")
class PostAPIController(ControllerBase):
def __init__(self) -> None:
self.post_service = AnnouncementService()

def _check_admin(self, request):
# Check if the user is authenticated and has an admin role.
if not request.user.is_authenticated or request.user.role != 'admin':
return JsonResponse({"detail": "Admin privileges required"}, status=403)
return None

def _check_user(self, request):
if not request.user.is_authenticated or request.user.role !='member':
return JsonResponse({"detail": "User privileges required"}, status=403)
return None

# API endpoint to create a new post (admin only).
@route.post("/add", url_name="Add Post")
Expand All @@ -27,9 +38,56 @@ def create_post(self, request, payload: schemas.PostCreateSchema):

# API endpoint to list all posts.
@route.get("/", url_name="List Posts")
def list_posts(self, request):
return self.post_service.list_posts()
def list_posts(self, request, page: int=1, per_page: int=10):
posts = PostModel.objects.all().order_by("created_at")
paginator=Paginator(posts,per_page)
page_obj=paginator.get_page(page)

return{
"total_pages": paginator.num_pages, "current_page": page, "data": [
{
"id": post.id,
"title": post.title,
"description": post.description,
"created_at": post.created_at.isoformat(),
"created_by": post.created_by.id,
}
for post in page_obj
],
}

@route.post("/notifications/", url_name="Notifications")
def user_notifications(self, request, unread:bool=False, page: int = 1, per_page: int = 10):
user=request.user
result=self._check_user(request)
if result is not None:
return result

notifications = NotificationModel.objects.filter(user=user, notification_type__in=["SC", "DE"])

if unread:
notifications = notifications.filter(is_read=False)
else:
notifications.update(is_read=True)

notifications = notifications.order_by("-is_read", "-created_at")

paginator=Paginator(notifications, per_page)
page_obj=paginator.get_page(page)

return {
"total_pages": paginator.num_pages,"current_page": page,
"notifications": [
{
"id": notif.id,
"message": notif.message,
"is_read": notif.is_read,
"created_at": notif.created_at.isoformat(),
}
for notif in page_obj
]
}

@route.put("/{post_id}", url_name="Update Post", response=PostSchema)
def update_post(self, request, post_id: int, payload: schemas.PostUpdateSchema):
self.post_service._check_admin(request)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed backend/myproject/db.sqlite3
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/admin.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/api.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/api.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/managers.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/models.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/schemas.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/members/__pycache__/schemas.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/settings.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/urls.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/myproject/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/api.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/api.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/schemas.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/schemas.cpython-313.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/services.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/projects/__pycache__/services.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified backend/myproject/registrations/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified backend/myproject/registrations/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 13 additions & 13 deletions frontend/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.8"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -532,7 +532,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -545,10 +545,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.1"
stream_channel:
dependency: transitive
description:
Expand All @@ -561,10 +561,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.4.1"
term_glyph:
dependency: transitive
description:
Expand All @@ -577,10 +577,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.4"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -665,10 +665,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.3.1"
web:
dependency: transitive
description:
Expand Down