aggiunti trasferte, export excel, miglioramenti generali
This commit is contained in:
@@ -125,6 +125,11 @@ def create_office(data: ValidOfficeCreate, db: Session = Depends(get_db), user=D
|
||||
)
|
||||
db.add(office)
|
||||
db.commit()
|
||||
|
||||
# Sync spots
|
||||
from services.offices import sync_office_spots
|
||||
sync_office_spots(office.id, office.parking_quota, office.spot_prefix, db)
|
||||
|
||||
return office
|
||||
|
||||
@router.get("/{office_id}")
|
||||
@@ -186,6 +191,10 @@ def update_office_settings(office_id: str, data: OfficeSettingsUpdate, db: Sessi
|
||||
office.updated_at = datetime.utcnow()
|
||||
db.commit()
|
||||
|
||||
# Sync spots
|
||||
from services.offices import sync_office_spots
|
||||
sync_office_spots(office.id, office.parking_quota, office.spot_prefix, db)
|
||||
|
||||
return {
|
||||
"id": office.id,
|
||||
"name": office.name,
|
||||
@@ -459,16 +468,20 @@ def add_office_exclusion(office_id: str, data: ExclusionCreate, db: Session = De
|
||||
if not db.query(User).filter(User.id == data.user_id).first():
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
existing = db.query(ParkingExclusion).filter(
|
||||
ParkingExclusion.office_id == office_id,
|
||||
ParkingExclusion.user_id == data.user_id
|
||||
).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="User already has a parking exclusion")
|
||||
# Relaxed unique check - user can have multiple exclusions (different periods)
|
||||
# existing = db.query(ParkingExclusion).filter(
|
||||
# ParkingExclusion.office_id == office_id,
|
||||
# ParkingExclusion.user_id == data.user_id
|
||||
# ).first()
|
||||
# if existing:
|
||||
# raise HTTPException(status_code=400, detail="User already has a parking exclusion")
|
||||
|
||||
if data.start_date and data.end_date and data.end_date < data.start_date:
|
||||
raise HTTPException(status_code=400, detail="End date must be after start date")
|
||||
|
||||
if data.end_date and not data.start_date:
|
||||
raise HTTPException(status_code=400, detail="Start date is required if an end date is specified")
|
||||
|
||||
exclusion = ParkingExclusion(
|
||||
id=generate_uuid(),
|
||||
office_id=office_id,
|
||||
|
||||
Reference in New Issue
Block a user