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
16 changes: 16 additions & 0 deletions app/core/tickets/cruds_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
from app.core.users import schemas_users


async def get_all_events(db: AsyncSession) -> Sequence[schemas_tickets.EventSimple]:
"""Return all events from database"""
result = await db.execute(select(models_tickets.TicketEvent))
return [
schemas_tickets.EventSimple(
id=association.id,
name=association.name,
store_id=association.store_id,
open_datetime=association.open_datetime,
close_datetime=association.close_datetime,
disabled=association.disabled,
)
for association in result.scalars().all()
]


async def get_open_and_enabled_events(
db: AsyncSession,
) -> Sequence[schemas_tickets.EventSimple]:
Expand Down
69 changes: 66 additions & 3 deletions app/core/tickets/factory_tickets.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,79 @@
import uuid
from datetime import UTC, datetime, timedelta

from sqlalchemy.ext.asyncio import AsyncSession

from app.core.mypayment.factory_mypayment import MyPaymentFactory
from app.core.tickets import cruds_tickets, schemas_tickets, types_tickets
from app.core.utils.config import Settings
from app.types.factory import Factory


class TicketsFactory(Factory):
depends_on = []
depends_on = [MyPaymentFactory]

@classmethod
async def run(cls, db: AsyncSession, settings: Settings) -> None:
pass
for store_ids in MyPaymentFactory.other_stores_id:
for store_id in store_ids:
await cruds_tickets.create_event(
event_id=uuid.uuid4(),
event=schemas_tickets.EventCreate(
store_id=store_id,
name=f"Test Event for store {store_id}",
quota=100,
open_datetime=datetime.now(UTC),
close_datetime=datetime.now(UTC) + timedelta(days=7),
sessions=[
schemas_tickets.SessionCreate(
name="Session 1",
start_datetime=datetime.now(UTC) + timedelta(days=10),
quota=10,
),
schemas_tickets.SessionCreate(
name="Session 2",
start_datetime=datetime.now(UTC) + timedelta(days=5),
quota=None,
),
],
categories=[
schemas_tickets.CategoryCreate(
name="Category 1",
price=100,
required_membership=None,
quota=10,
),
schemas_tickets.CategoryCreate(
name="Category 2",
price=0,
required_membership=None,
quota=None,
),
],
questions=[
schemas_tickets.QuestionCreate(
question="Question 1",
answer_type=types_tickets.AnswerType.TEXT,
required=True,
price=10,
),
schemas_tickets.QuestionCreate(
question="Question 2",
answer_type=types_tickets.AnswerType.BOOLEAN,
required=False,
price=0,
),
schemas_tickets.QuestionCreate(
question="Question 2",
answer_type=types_tickets.AnswerType.NUMBER,
required=False,
price=0,
),
],
),
db=db,
)

@classmethod
async def should_run(cls, db: AsyncSession):
pass
return len(await cruds_tickets.get_all_events(db)) == 0
Loading