36 lines
838 B
V
36 lines
838 B
V
module main
|
|
|
|
import time
|
|
|
|
// service_add_flight is a function that adds a new flight to the database.
|
|
fn (app &App) service_add_flight(from string, to string, departure time.Time, price int) !Flight {
|
|
flight_model := Flight{
|
|
from: from
|
|
to: to
|
|
departure: departure
|
|
price: price
|
|
created_at: time.now()
|
|
}
|
|
|
|
sql app.db {
|
|
insert flight_model into Flight
|
|
}!
|
|
|
|
flight := sql app.db {
|
|
select from Flight where from == flight_model.from && to == flight_model.to
|
|
&& departure == flight_model.departure && price == flight_model.price
|
|
&& created_at == flight_model.created_at
|
|
}!
|
|
|
|
return flight[0]
|
|
}
|
|
|
|
// service_get_flight is a function that retrieves a flight by its ID.
|
|
fn (app &App) service_get_flight(id int) !Flight {
|
|
flight := sql app.db {
|
|
select from Flight where id == id
|
|
}!
|
|
|
|
return flight[0]
|
|
}
|