add event editing
This commit is contained in:
@@ -161,6 +161,18 @@ class TripEventCreate(BaseModel):
|
||||
tags: List[str] = [] # tag labels applied to this event
|
||||
|
||||
|
||||
class TripEventUpdate(BaseModel):
|
||||
title: Optional[str] = None
|
||||
date: Optional[str] = None
|
||||
start_time: Optional[str] = None
|
||||
end_time: Optional[str] = None
|
||||
location: Optional[str] = None
|
||||
maps_link: Optional[str] = None
|
||||
place_id: Optional[str] = None
|
||||
notes: Optional[str] = None
|
||||
tags: Optional[List[str]] = None
|
||||
|
||||
|
||||
class AttendeeAction(BaseModel):
|
||||
discord_user_id: str
|
||||
discord_username: Optional[str] = None
|
||||
|
||||
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from pydantic import BaseModel
|
||||
from app.models import TripCreate, TripEventCreate, AttendeeAction
|
||||
from app.models import TripCreate, TripEventCreate, TripEventUpdate, AttendeeAction
|
||||
from app.internal import firestore as fstore
|
||||
from app.config import settings
|
||||
from app.internal.logger import logger
|
||||
@@ -319,6 +319,45 @@ async def create_event(trip_id: str, body: TripEventCreate):
|
||||
return doc
|
||||
|
||||
|
||||
@router.patch("/{trip_id}/events/{event_id}")
|
||||
async def update_event(trip_id: str, event_id: str, body: TripEventUpdate):
|
||||
event = await fstore.doc_get("trip_events", event_id)
|
||||
if not event or event.get("trip_id") != trip_id:
|
||||
raise HTTPException(404, f"Event '{event_id}' not found in trip '{trip_id}'.")
|
||||
|
||||
trip = await fstore.doc_get("trips", trip_id)
|
||||
if not trip:
|
||||
raise HTTPException(404, f"Trip '{trip_id}' not found.")
|
||||
|
||||
updates: dict = {}
|
||||
if body.title is not None:
|
||||
updates["title"] = body.title
|
||||
if body.date is not None:
|
||||
if not (trip["start_date"] <= body.date <= trip["end_date"]):
|
||||
raise HTTPException(400, f"Event date {body.date} is outside the trip range.")
|
||||
updates["date"] = body.date
|
||||
if body.start_time is not None:
|
||||
updates["start_time"] = body.start_time or None
|
||||
if body.end_time is not None:
|
||||
updates["end_time"] = body.end_time or None
|
||||
if body.location is not None:
|
||||
updates["location"] = body.location
|
||||
updates["location_inherited"] = False
|
||||
if body.maps_link is not None:
|
||||
updates["maps_link"] = body.maps_link or None
|
||||
if body.place_id is not None:
|
||||
updates["place_id"] = body.place_id or None
|
||||
if body.notes is not None:
|
||||
updates["notes"] = body.notes or None
|
||||
if body.tags is not None:
|
||||
updates["tags"] = body.tags
|
||||
|
||||
if updates:
|
||||
await fstore.doc_update("trip_events", event_id, updates)
|
||||
|
||||
return {**event, **updates}
|
||||
|
||||
|
||||
@router.delete("/{trip_id}/events/{event_id}")
|
||||
async def delete_event(
|
||||
trip_id: str,
|
||||
|
||||
Reference in New Issue
Block a user