[V1.0] Working application, added notifications.
Ready to upload to store.
This commit is contained in:
@@ -7,7 +7,13 @@ from core.exceptions import not_found_exception
|
||||
from modules.calendar.schemas import (
|
||||
CalendarEventCreate,
|
||||
CalendarEventUpdate,
|
||||
) # Import schemas
|
||||
)
|
||||
|
||||
# Import the celery app instance instead of the task functions directly
|
||||
from core.celery_app import celery_app
|
||||
|
||||
# Keep task imports if cancel_event_notifications is still called directly and synchronously
|
||||
from modules.calendar.tasks import cancel_event_notifications
|
||||
|
||||
|
||||
def create_calendar_event(db: Session, user_id: int, event_data: CalendarEventCreate):
|
||||
@@ -23,6 +29,11 @@ def create_calendar_event(db: Session, user_id: int, event_data: CalendarEventCr
|
||||
db.add(event)
|
||||
db.commit()
|
||||
db.refresh(event)
|
||||
# Schedule notifications using send_task
|
||||
celery_app.send_task(
|
||||
"modules.calendar.tasks.schedule_event_notifications", # Task name as string
|
||||
args=[event.id],
|
||||
)
|
||||
return event
|
||||
|
||||
|
||||
@@ -114,10 +125,17 @@ def update_calendar_event(
|
||||
|
||||
db.commit()
|
||||
db.refresh(event)
|
||||
# Re-schedule notifications using send_task
|
||||
celery_app.send_task(
|
||||
"modules.calendar.tasks.schedule_event_notifications", args=[event.id]
|
||||
)
|
||||
return event
|
||||
|
||||
|
||||
def delete_calendar_event(db: Session, user_id: int, event_id: int):
|
||||
event = get_calendar_event_by_id(db, user_id, event_id) # Reuse get_by_id for check
|
||||
# Cancel any scheduled notifications before deleting
|
||||
# Run synchronously here or make cancel_event_notifications an async task
|
||||
cancel_event_notifications(event_id)
|
||||
db.delete(event)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user