From 7d8eacad7ab7694d008fad4f491df7e4f01c94d7 Mon Sep 17 00:00:00 2001 From: Felipe Cardoso Date: Wed, 19 Mar 2025 07:32:09 +0100 Subject: [PATCH] Update gift cancellation to include received status Allow cancellation of gifts with a status of either RESERVED or RECEIVED. This ensures consistency in handling gift statuses during reservation management across the application. --- backend/app/api/routes/events/gifts.py | 4 ++-- backend/app/crud/gift.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/app/api/routes/events/gifts.py b/backend/app/api/routes/events/gifts.py index b3f1d1a..586dc08 100644 --- a/backend/app/api/routes/events/gifts.py +++ b/backend/app/api/routes/events/gifts.py @@ -916,7 +916,7 @@ def cancel_gift_reservation( raise HTTPException(status_code=404, detail="Gift item not found") # Check if gift is reserved - if gift.status != GiftStatus.RESERVED: + if gift.status not in [GiftStatus.RESERVED, GiftStatus.RECEIVED]: raise HTTPException(status_code=400, detail="Gift is not currently reserved") # Check if guest exists @@ -931,7 +931,7 @@ def cancel_gift_reservation( except ValueError as e: raise HTTPException(status_code=400, detail=str(e)) - # Missing the return statement here, which is also a problem + return gift_item_crud.cancel_reservation(db, gift_id=item_id, guest_id=guest_id) # ===== GIFT PURCHASES ===== # diff --git a/backend/app/crud/gift.py b/backend/app/crud/gift.py index 9d590ae..01ab043 100644 --- a/backend/app/crud/gift.py +++ b/backend/app/crud/gift.py @@ -136,7 +136,7 @@ class CRUDGiftItem(CRUDBase[GiftItem, GiftItemCreate, GiftItemUpdate]): raise ValueError(f"Guest with ID {guest_id} not found") # Only perform the operation if the gift is reserved - if gift.status == GiftStatus.RESERVED: + if gift.status in [GiftStatus.RESERVED, GiftStatus.RECEIVED]: # Check if this guest has actually reserved this gift if guest in gift.reserved_by: gift.reserved_by.remove(guest)