Skip to content

Commit

Permalink
Frontend support for querying flights sorted by column
Browse files Browse the repository at this point in the history
  • Loading branch information
pbogre committed Sep 9, 2024
1 parent 4a62d28 commit 0d34cc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions client/pages/AllFlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface FlightsFilters {
limit?: number;
offset?: number;
order?: "DESC"|"ASC";
sort?: "date"|"seat"|"ticket_class"|"duration"|"distance";
start?: string;
end?: string;
}
Expand Down Expand Up @@ -62,6 +63,17 @@ export default function AllFlights() {
{ text: "Ascending", value: "ASC" }
]}/>
<br />
<Label text="Sort By" />
<Select name="sort"
options={[
{ text: "Choose", value: "" },
{ text: "Date", value: "date" },
{ text: "Seat", value: "seat" },
{ text: "Ticket Class", value: "ticket_class" },
{ text: "Duration", value: "duration" },
{ text: "Distance", value: "distance" }
]}/>
<br />
<Label text="Start Date" />
<Input type="date" name="start" />
<br />
Expand Down
6 changes: 3 additions & 3 deletions server/routers/flights.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Order(str, Enum):
ASCENDING = "ASC"
DESCENDING = "DESC"

class SortBy(str, Enum):
class Sort(str, Enum):
DATE = "date"
SEAT = "seat"
TICKET_CLASS = "ticket_class"
Expand Down Expand Up @@ -141,7 +141,7 @@ async def get_flights(id: int|None = None,
limit: int = 50,
offset: int = 0,
order: Order = Order.DESCENDING,
sort_by: SortBy = SortBy.DATE,
sort: Sort = Sort.DATE,
start: datetime.date|None = None,
end: datetime.date|None = None) -> list[FlightModel]|FlightModel:

Expand All @@ -164,7 +164,7 @@ async def get_flights(id: int|None = None,
JOIN airports d ON LOWER(f.destination) = LOWER(d.icao)
{id_filter}
{date_filter_start} {date_filter}
ORDER BY f.{sort_by.value} {order.value}
ORDER BY f.{sort.value} {order.value}
LIMIT {limit}
OFFSET {offset};"""

Expand Down

0 comments on commit 0d34cc6

Please sign in to comment.