Calendar + NLP modules implemented
This commit is contained in:
45
backend/modules/calendar/service.py
Normal file
45
backend/modules/calendar/service.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# modules/calendar/service.py
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from modules.calendar.models import CalendarEvent
|
||||
from core.exceptions import not_found_exception
|
||||
|
||||
def create_calendar_event(db: Session, user_id: int, event_data):
|
||||
event = CalendarEvent(**event_data.dict(), user_id=user_id)
|
||||
db.add(event)
|
||||
db.commit()
|
||||
db.refresh(event)
|
||||
return event
|
||||
|
||||
def get_calendar_events(db: Session, user_id: int, start: datetime, end: datetime):
|
||||
query = db.query(CalendarEvent).filter(
|
||||
CalendarEvent.user_id == user_id
|
||||
)
|
||||
if start:
|
||||
query = query.filter(CalendarEvent.start_time >= start)
|
||||
if end:
|
||||
query = query.filter(CalendarEvent.end_time <= end)
|
||||
return query.all()
|
||||
|
||||
def update_calendar_event(db: Session, user_id: int, event_id: int, event_data):
|
||||
event = db.query(CalendarEvent).filter(
|
||||
CalendarEvent.id == event_id,
|
||||
CalendarEvent.user_id == user_id
|
||||
).first()
|
||||
if not event:
|
||||
raise not_found_exception()
|
||||
for key, value in event_data.dict().items():
|
||||
setattr(event, key, value)
|
||||
db.commit()
|
||||
db.refresh(event)
|
||||
return event
|
||||
|
||||
def delete_calendar_event(db: Session, user_id: int, event_id: int):
|
||||
event = db.query(CalendarEvent).filter(
|
||||
CalendarEvent.id == event_id,
|
||||
CalendarEvent.user_id == user_id
|
||||
).first()
|
||||
if not event:
|
||||
raise not_found_exception()
|
||||
db.delete(event)
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user