Adds public events endpoint and user tickets
Some checks are pending
lint / lint (push) Waiting to run
Some checks are pending
lint / lint (push) Waiting to run
Adds a public events endpoint that allows read-only access to all events. Improves ticket management by adding support for user IDs as an identifier, alongside name and email. This simplifies ticket creation for authenticated users and enhances security. Also introduces an API endpoint to fetch tickets by user ID.
This commit is contained in:
parent
c729ef17a6
commit
c669da5822
7 changed files with 377 additions and 20 deletions
25
models.py
25
models.py
|
|
@ -2,7 +2,7 @@ from datetime import datetime
|
|||
from typing import Optional
|
||||
|
||||
from fastapi import Query
|
||||
from pydantic import BaseModel, EmailStr
|
||||
from pydantic import BaseModel, EmailStr, root_validator
|
||||
|
||||
|
||||
class CreateEvent(BaseModel):
|
||||
|
|
@ -19,8 +19,22 @@ class CreateEvent(BaseModel):
|
|||
|
||||
|
||||
class CreateTicket(BaseModel):
|
||||
name: str
|
||||
email: EmailStr
|
||||
name: Optional[str] = None
|
||||
email: Optional[EmailStr] = None
|
||||
user_id: Optional[str] = None
|
||||
|
||||
@root_validator
|
||||
def validate_identifiers(cls, values):
|
||||
# Ensure either (name AND email) OR user_id is provided
|
||||
name = values.get('name')
|
||||
email = values.get('email')
|
||||
user_id = values.get('user_id')
|
||||
|
||||
if not user_id and not (name and email):
|
||||
raise ValueError("Either user_id or both name and email must be provided")
|
||||
if user_id and (name or email):
|
||||
raise ValueError("Cannot provide both user_id and name/email")
|
||||
return values
|
||||
|
||||
|
||||
class Event(BaseModel):
|
||||
|
|
@ -43,8 +57,9 @@ class Ticket(BaseModel):
|
|||
id: str
|
||||
wallet: str
|
||||
event: str
|
||||
name: str
|
||||
email: str
|
||||
name: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
user_id: Optional[str] = None
|
||||
registered: bool
|
||||
paid: bool
|
||||
time: datetime
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue