File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 180180from PyMatcha .routes .api .search import search_bp
181181from PyMatcha .routes .api .profile .block import profile_block_bp
182182from PyMatcha .routes .api .history import history_bp
183+ from PyMatcha .routes .api .notifications import notifications_bp
183184
184185logging .debug ("Registering Flask blueprints" )
185186application .register_blueprint (user_bp )
199200application .register_blueprint (search_bp )
200201application .register_blueprint (profile_block_bp )
201202application .register_blueprint (history_bp )
203+ application .register_blueprint (notifications_bp )
202204
203205if application .debug :
204206 logging .debug ("Registering debug route" )
Original file line number Diff line number Diff line change 1+ from flask import Blueprint
2+ from flask_jwt_extended import current_user
3+ from flask_jwt_extended import jwt_required
4+ from PyMatcha .models .notification import Notification
5+ from PyMatcha .utils .errors import BadRequestError
6+ from PyMatcha .utils .errors import NotFoundError
7+ from PyMatcha .utils .success import Success
8+ from PyMatcha .utils .success import SuccessOutput
9+
10+ notifications_bp = Blueprint ("notifications" , __name__ )
11+
12+
13+ @notifications_bp .route ("/notifications" , methods = ["GET" ])
14+ @jwt_required
15+ def get_all_notifications ():
16+ return SuccessOutput ("notifications" , current_user .get_all_notifications ())
17+
18+
19+ @notifications_bp .route ("/notifications/unread" , methods = ["GET" ])
20+ @jwt_required
21+ def get_unread_notifications ():
22+ return SuccessOutput ("notifications" , current_user .get_unread_notifications ())
23+
24+
25+ @notifications_bp .route ("/notifications/read/<n_id>" , methods = ["POST" ])
26+ @jwt_required
27+ def mark_notification_as_read (n_id ):
28+ notif = Notification .get (id = n_id )
29+ if not notif :
30+ raise NotFoundError (f"Notification id { n_id } not found." )
31+ if notif .user_id != current_user .id :
32+ raise BadRequestError ("Cannot mark notification as read if it isn't yours." )
33+ notif .is_seen = True
34+ notif .save ()
35+ return Success ("Mark as read." )
You can’t perform that action at this time.
0 commit comments