health-apps-backend/apis/endpoints/notifications.py

37 lines
1.5 KiB
Python

from fastapi import APIRouter
from utils.constants import DEFAULT_LIMIT, DEFAULT_PAGE
from services.notificationServices import NotificationServices
from schemas.ApiResponse import ApiResponse
from fastapi import Request
router = APIRouter()
@router.get("/")
def get_notifications(request: Request, limit: int = DEFAULT_LIMIT, page: int = DEFAULT_PAGE):
if page <0:
page = 1
offset = (page - 1) * limit
notifications = NotificationServices().getNotifications(request.state.user["id"], limit, offset)
return ApiResponse(data=notifications, message="Notifications retrieved successfully")
@router.delete("/")
def delete_notification(notification_id: int):
NotificationServices().deleteNotification(notification_id)
return ApiResponse(data="OK", message="Notification deleted successfully")
@router.put("/")
def update_notification_status(notification_id: int):
NotificationServices().updateNotificationStatus(notification_id)
return ApiResponse(data="OK", message="Notification status updated successfully")
@router.post("/")
def send_notification(title: str, message: str, sender_id: int, receiver_id: int):
NotificationServices().createNotification(title, message, sender_id, receiver_id)
return ApiResponse(data="OK", message="Notification sent successfully")
@router.post("/fcm")
def send_fcm_notification(req: Request, token: str):
NotificationServices().createOrUpdateFCMToken(req.state.user["id"], token)
return ApiResponse(data="OK", message="FCM Notification sent successfully")