feat: add user_id ticket support and public events endpoint
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>
This commit is contained in:
Patrick Mulligan 2026-04-24 02:55:18 -04:00
commit 2740d73678
4 changed files with 105 additions and 9 deletions

27
crud.py
View file

@ -1,4 +1,5 @@
from datetime import datetime, timedelta, timezone
from typing import Optional
from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
@ -9,7 +10,13 @@ db = Database("ext_events")
async def create_ticket(
payment_hash: str, wallet: str, event: str, name: str, email: str, extra: dict
payment_hash: str,
wallet: str,
event: str,
name: str = "",
email: str = "",
user_id: Optional[str] = None,
extra: Optional[dict] = None,
) -> Ticket:
now = datetime.now(timezone.utc)
ticket = Ticket(
@ -18,6 +25,7 @@ async def create_ticket(
event=event,
name=name,
email=email,
user_id=user_id,
registered=False,
paid=False,
reg_timestamp=now,
@ -102,6 +110,23 @@ async def get_events(wallet_ids: str | list[str]) -> list[Event]:
)
async def get_all_events() -> list[Event]:
"""Get all events without wallet filtering (public endpoint)."""
return await db.fetchall(
"SELECT * FROM events.events ORDER BY time DESC",
model=Event,
)
async def get_tickets_by_user_id(user_id: str) -> list[Ticket]:
"""Get all tickets for a specific user by their user_id."""
return await db.fetchall(
"SELECT * FROM events.ticket WHERE user_id = :user_id ORDER BY time DESC",
{"user_id": user_id},
model=Ticket,
)
async def delete_event(event_id: str) -> None:
await db.execute("DELETE FROM events.events WHERE id = :id", {"id": event_id})