From d8ec15125ca81d4530eb27c8d2f5d941f3e70377 Mon Sep 17 00:00:00 2001 From: Foucauld Bellanger <63885990+Foukki@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:35:33 +0100 Subject: [PATCH] Fix : Cancel notification with notif manager --- app/modules/cinema/endpoints_cinema.py | 5 ++++- app/modules/loan/endpoints_loan.py | 13 +++++++++---- app/utils/communication/notifications.py | 7 +++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/modules/cinema/endpoints_cinema.py b/app/modules/cinema/endpoints_cinema.py index cc239263d..e6464ffed 100644 --- a/app/modules/cinema/endpoints_cinema.py +++ b/app/modules/cinema/endpoints_cinema.py @@ -149,7 +149,10 @@ async def create_session( action_module="cinema", ) - await scheduler.cancel_job(job_id=f"cinema_weekly_{sunday}") + await notification_tool.cancel_notification( + scheduler=scheduler, + job_id=f"cinema_weekly_{sunday}", + ) await notification_tool.send_notification_to_topic( custom_topic=CustomTopic(topic=Topic.cinema), diff --git a/app/modules/loan/endpoints_loan.py b/app/modules/loan/endpoints_loan.py index 53fd632a1..d60bda7f5 100644 --- a/app/modules/loan/endpoints_loan.py +++ b/app/modules/loan/endpoints_loan.py @@ -828,6 +828,7 @@ async def return_loan( db: AsyncSession = Depends(get_db), user: models_core.CoreUser = Depends(is_user_a_member), scheduler: Scheduler = Depends(get_scheduler), + notification_tool: NotificationTool = Depends(get_notification_tool), ): """ Mark a loan as returned. This will update items availability. @@ -872,7 +873,10 @@ async def return_loan( returned=True, returned_date=datetime.now(UTC), ) - await scheduler.cancel_job(f"loan_end_{loan.id}") + await notification_tool.cancel_notification( + scheduler=scheduler, + job_id=f"loan_end_{loan.id}", + ) @module.router.post( @@ -927,9 +931,10 @@ async def extend_loan( loan_update=loan_update, db=db, ) - # TODO - - await scheduler.cancel_job(f"loan_end_{loan.id}") + await notification_tool.cancel_notification( + scheduler=scheduler, + job_id=f"loan_end_{loan.id}", + ) message = Message( title="📦 Prêt prolongé", diff --git a/app/utils/communication/notifications.py b/app/utils/communication/notifications.py index a6950eb83..8b5c5b72f 100644 --- a/app/utils/communication/notifications.py +++ b/app/utils/communication/notifications.py @@ -471,3 +471,10 @@ async def send_future_notification_to_topic_time_defer( job_id=job_id, defer_seconds=defer_seconds, ) + + async def cancel_notification( + self, + scheduler: Scheduler, + job_id: str, + ): + await scheduler.cancel_job(job_id=job_id)