11import logging
2+ import pytz
23from typing import List , Dict , Any
34from fastapi import Depends
45from fastapi import HTTPException , status
@@ -66,13 +67,6 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
6667 detail = f"Ticket type with ID { ticket_type_id } not found" ,
6768 )
6869
69- # Verify that the ticket type is available for sale
70- if ticket_type .available_from is not None and ticket_type .available_from > datetime .now ():
71- raise HTTPException (
72- status_code = status .HTTP_400_BAD_REQUEST ,
73- detail = f"Ticket type with ID { ticket_type_id } is not available for sale yet" ,
74- )
75-
7670 # This case should ideally not happen
7771 if not ticket_type .event :
7872 raise HTTPException (
@@ -87,8 +81,24 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
8781 detail = f"Event '{ ticket_type .event .name } ' is not yet active." ,
8882 )
8983
84+ # Get current time in Warsaw timezone
85+ warsaw_tz = pytz .timezone ('Europe/Warsaw' )
86+ now_warsaw_aware = datetime .now (warsaw_tz )
87+
88+ # Verify that the ticket type is available for sale
89+ if ticket_type .available_from is not None :
90+ # Convert available_from to Warsaw timezone
91+ available_from_warsaw_aware = warsaw_tz .localize (ticket_type .available_from )
92+
93+ if available_from_warsaw_aware > now_warsaw_aware :
94+ raise HTTPException (
95+ status_code = status .HTTP_400_BAD_REQUEST ,
96+ detail = f"Ticket type with ID { ticket_type_id } is not available for sale yet" ,
97+ )
98+
9099 # Verify that the event has not passed
91- if ticket_type .event .end_date < datetime .now ():
100+ event_end_date_warsaw_aware = warsaw_tz .localize (ticket_type .event .end_date )
101+ if event_end_date_warsaw_aware < now_warsaw_aware :
92102 raise HTTPException (
93103 status_code = status .HTTP_400_BAD_REQUEST ,
94104 detail = f"Event '{ ticket_type .event .name } ' has already ended." ,
@@ -105,7 +115,8 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
105115 # If the item already exists in the cart, update the quantity
106116 if existing_cart_item :
107117 existing_cart_item .quantity += quantity
108- logger .info (f"Updated quantity for ticket_type_id { ticket_type_id } in cart_id { cart .cart_id } . New quantity: { existing_cart_item .quantity } " )
118+ logger .info (
119+ f"Updated quantity for ticket_type_id { ticket_type_id } in cart_id { cart .cart_id } . New quantity: { existing_cart_item .quantity } " )
109120 else :
110121 existing_cart_item = CartItemModel (
111122 cart_id = cart .cart_id ,
0 commit comments