Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import pytz
from typing import List, Dict, Any
from fastapi import Depends
from fastapi import HTTPException, status
Expand Down Expand Up @@ -66,13 +67,6 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
detail=f"Ticket type with ID {ticket_type_id} not found",
)

# Verify that the ticket type is available for sale
if ticket_type.available_from is not None and ticket_type.available_from > datetime.now():
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Ticket type with ID {ticket_type_id} is not available for sale yet",
)

# This case should ideally not happen
if not ticket_type.event:
raise HTTPException(
Expand All @@ -87,8 +81,24 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
detail=f"Event '{ticket_type.event.name}' is not yet active.",
)

# Get current time in Warsaw timezone
warsaw_tz = pytz.timezone('Europe/Warsaw')
now_warsaw_aware = datetime.now(warsaw_tz)

# Verify that the ticket type is available for sale
if ticket_type.available_from is not None:
# Convert available_from to Warsaw timezone
available_from_warsaw_aware = warsaw_tz.localize(ticket_type.available_from)

if available_from_warsaw_aware > now_warsaw_aware:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Ticket type with ID {ticket_type_id} is not available for sale yet",
)

# Verify that the event has not passed
if ticket_type.event.end_date < datetime.now():
event_end_date_warsaw_aware = warsaw_tz.localize(ticket_type.event.end_date)
if event_end_date_warsaw_aware < now_warsaw_aware:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Event '{ticket_type.event.name}' has already ended.",
Expand All @@ -105,7 +115,8 @@ def add_item_from_detailed_sell(self, customer_id: int, ticket_type_id: int, qua
# If the item already exists in the cart, update the quantity
if existing_cart_item:
existing_cart_item.quantity += quantity
logger.info(f"Updated quantity for ticket_type_id {ticket_type_id} in cart_id {cart.cart_id}. New quantity: {existing_cart_item.quantity}")
logger.info(
f"Updated quantity for ticket_type_id {ticket_type_id} in cart_id {cart.cart_id}. New quantity: {existing_cart_item.quantity}")
else:
existing_cart_item = CartItemModel(
cart_id=cart.cart_id,
Expand Down
1 change: 1 addition & 0 deletions backend/event_ticketing_service/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ sendgrid==6.12.2
sqlalchemy==2.0.40
uvicorn==0.34.0
boto3
pytz
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ python_dotenv==1.1.0
python_multipart==0.0.20
sqlalchemy==2.0.40
uvicorn==0.34.0
pytz