mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
fix(calanders): Removed/merged duplicate calender delete endpoints (#3682)
* merged two delete_calander functions performing the same thing * added proper 404 raise when nothing is found * removed 404 HTTPException and jus reverted it back to raise
This commit is contained in:
@@ -851,28 +851,27 @@ def setup_calendar_routes() -> APIRouter:
|
|||||||
from src.caldav_sync import sync_caldav
|
from src.caldav_sync import sync_caldav
|
||||||
return await sync_caldav(owner)
|
return await sync_caldav(owner)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/calendars/{cal_id}")
|
@router.delete("/calendars/{cal_id}")
|
||||||
async def delete_calendar(cal_id: str, request: Request):
|
async def delete_calendar(request: Request, cal_id: str):
|
||||||
owner = _require_user(request)
|
owner = _require_user(request)
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
cal = db.query(CalendarCal).filter(
|
cal = _get_or_404_calendar(db, cal_id, owner)
|
||||||
CalendarCal.id == cal_id,
|
db.query(CalendarEvent).filter(CalendarEvent.calendar_id == cal_id).delete()
|
||||||
CalendarCal.owner == owner,
|
|
||||||
).first()
|
|
||||||
if not cal:
|
|
||||||
raise HTTPException(404, "Calendar not found")
|
|
||||||
db.delete(cal)
|
db.delete(cal)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
db.rollback()
|
||||||
logger.error("Failed to delete calendar %s: %s", cal_id, e)
|
logger.error("Failed to delete calendar %s: %s", cal_id, e)
|
||||||
raise HTTPException(500, "Failed to delete calendar")
|
raise HTTPException(500, "Failed to delete calendar")
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/calendars")
|
@router.get("/calendars")
|
||||||
async def list_calendars(request: Request):
|
async def list_calendars(request: Request):
|
||||||
owner = _require_user(request)
|
owner = _require_user(request)
|
||||||
@@ -1152,23 +1151,6 @@ def setup_calendar_routes() -> APIRouter:
|
|||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
@router.delete("/calendars/{cal_id}")
|
|
||||||
async def delete_calendar(request: Request, cal_id: str):
|
|
||||||
owner = _require_user(request)
|
|
||||||
db = SessionLocal()
|
|
||||||
try:
|
|
||||||
cal = _get_or_404_calendar(db, cal_id, owner)
|
|
||||||
db.query(CalendarEvent).filter(CalendarEvent.calendar_id == cal_id).delete()
|
|
||||||
db.delete(cal)
|
|
||||||
db.commit()
|
|
||||||
return {"ok": True}
|
|
||||||
except HTTPException:
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
|
||||||
db.rollback()
|
|
||||||
return {"error": str(e)}
|
|
||||||
finally:
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
# Hard cap on ICS upload (ICS_MAX_BYTES, default 10 MB). Loading the whole
|
# Hard cap on ICS upload (ICS_MAX_BYTES, default 10 MB). Loading the whole
|
||||||
# file into memory is unavoidable with python-icalendar, so an unbounded
|
# file into memory is unavoidable with python-icalendar, so an unbounded
|
||||||
|
|||||||
Reference in New Issue
Block a user