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
@@ -0,0 +1,28 @@
"""add column order on ticket

Revision ID: 620f0b3ec868
Revises: 10419d21e3d0
Create Date: 2026-06-05 21:56:37.519244

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = "620f0b3ec868"
down_revision: Union[str, None] = "10419d21e3d0"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Upgrade schema."""
op.add_column("ticket", sa.Column("order", sa.Integer(), nullable=True))


def downgrade() -> None:
"""Downgrade schema."""
op.drop_column("ticket", "order")
1 change: 1 addition & 0 deletions models/Ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ class Ticket(Base):
is_sold_out: Mapped[bool] = mapped_column("is_sold_out", Boolean, default=False)
is_active: Mapped[bool] = mapped_column("is_active", Boolean, default=True)
description: Mapped[str] = mapped_column("description", String, nullable=True)
order: Mapped[int] = mapped_column("order", Integer, nullable=True)
2 changes: 1 addition & 1 deletion repository/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def get_active_tickets(db: Session):
return db.query(Ticket).filter(Ticket.is_active).all()
return db.query(Ticket).filter(Ticket.is_active).order_by(Ticket.order.asc()).all()


def get_active_ticket_by_id(db: Session, ticket_id: str):
Expand Down
9 changes: 4 additions & 5 deletions routes/tests/test_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ def test_list_ticket(self):
assert response.status_code == 200
data = response.json()
assert "results" in data
assert any(
t["name"] == "Test Ticket"
and t.get("description") == "Ini deskripsi test ticket"
for t in data["results"]
)
ordered_ticket = self.session.query(Ticket).order_by(Ticket.order.asc()).all()
ordered_ticket = [x.name for x in ordered_ticket]
ordered_result = [x["name"] for x in data["results"]]
self.assertListEqual(ordered_result, ordered_ticket)

def test_get_my_ticket_without_payment(self):
response = self.client.get(
Expand Down
Loading