Some checks failed
lint / lint (push) Has been cancelled
- Tickets can be created with user_id instead of name/email
- name/email default to empty string in DB (not NULL-safe)
- New endpoints: GET /api/v1/events/public, GET /api/v1/tickets/user/{user_id}
- POST /api/v1/tickets/{event_id} accepts user_id in body
- Migration m007 adds user_id column to tickets table
- CreateTicket validates: either user_id or (name + email) required
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
97 lines
2.4 KiB
Python
97 lines
2.4 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from fastapi import Query
|
|
from pydantic import BaseModel, EmailStr, Field, root_validator, validator
|
|
|
|
|
|
class PromoCode(BaseModel):
|
|
code: str
|
|
discount_percent: float = 0.0
|
|
active: bool = True
|
|
|
|
# make the promo code uppercase
|
|
@validator("code")
|
|
def uppercase_code(cls, v):
|
|
return v.upper()
|
|
|
|
@validator("discount_percent")
|
|
def validate_discount_percent(cls, v):
|
|
assert 0 <= v <= 100, "Discount must be between 0 and 100."
|
|
return v
|
|
|
|
|
|
class EventExtra(BaseModel):
|
|
promo_codes: list[PromoCode] = Field(default_factory=list)
|
|
conditional: bool = False
|
|
min_tickets: int = 1
|
|
|
|
|
|
class CreateEvent(BaseModel):
|
|
wallet: str
|
|
name: str
|
|
info: str
|
|
closing_date: str
|
|
event_start_date: str
|
|
event_end_date: str
|
|
currency: str = "sat"
|
|
amount_tickets: int = Query(..., ge=0)
|
|
price_per_ticket: float = Query(..., ge=0)
|
|
banner: str | None = None
|
|
extra: EventExtra = Field(default_factory=EventExtra)
|
|
|
|
|
|
class Event(BaseModel):
|
|
id: str
|
|
wallet: str
|
|
name: str
|
|
info: str
|
|
closing_date: str
|
|
canceled: bool = False
|
|
event_start_date: str
|
|
event_end_date: str
|
|
currency: str
|
|
amount_tickets: int
|
|
price_per_ticket: float
|
|
time: datetime
|
|
sold: int = 0
|
|
banner: str | None = None
|
|
extra: EventExtra = Field(default_factory=EventExtra)
|
|
|
|
|
|
class TicketExtra(BaseModel):
|
|
applied_promo_code: str | None = None
|
|
sats_paid: int | None = None
|
|
refund_address: str | None = None
|
|
refunded: bool = False
|
|
|
|
|
|
class CreateTicket(BaseModel):
|
|
name: Optional[str] = None
|
|
email: Optional[str] = None
|
|
user_id: Optional[str] = None
|
|
promo_code: str | None = None
|
|
refund_address: str | None = None
|
|
|
|
@root_validator
|
|
def validate_identifiers(cls, values):
|
|
user_id = values.get("user_id")
|
|
name = values.get("name")
|
|
email = values.get("email")
|
|
if not user_id and not (name and email):
|
|
raise ValueError("Either user_id or both name and email must be provided")
|
|
return values
|
|
|
|
|
|
class Ticket(BaseModel):
|
|
id: str
|
|
wallet: str
|
|
event: str
|
|
name: str = ""
|
|
email: str = ""
|
|
user_id: Optional[str] = None
|
|
registered: bool
|
|
paid: bool
|
|
time: datetime
|
|
reg_timestamp: datetime
|
|
extra: TicketExtra = Field(default_factory=TicketExtra)
|