016
This commit is contained in:
@@ -2,6 +2,7 @@ module main
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
// service_add_booking is a function that adds a new booking to the database.
|
||||||
fn (app &App) service_add_booking(name string, user_id int, flight_id int) ! {
|
fn (app &App) service_add_booking(name string, user_id int, flight_id int) ! {
|
||||||
booking := Booking{
|
booking := Booking{
|
||||||
name: name
|
name: name
|
||||||
@@ -16,6 +17,7 @@ fn (app &App) service_add_booking(name string, user_id int, flight_id int) ! {
|
|||||||
}!
|
}!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_get_user_bookings is a function that retrieves all bookings for a given user.
|
||||||
fn (app &App) service_get_user_bookings(user_id int) ![]Booking {
|
fn (app &App) service_get_user_bookings(user_id int) ![]Booking {
|
||||||
bookings := sql app.db {
|
bookings := sql app.db {
|
||||||
select from Booking where user_id == user_id order by created_at desc
|
select from Booking where user_id == user_id order by created_at desc
|
||||||
@@ -24,6 +26,7 @@ fn (app &App) service_get_user_bookings(user_id int) ![]Booking {
|
|||||||
return bookings
|
return bookings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_cancel_booking is a function that cancels a booking.
|
||||||
fn (app &App) service_cancel_booking(id int) ! {
|
fn (app &App) service_cancel_booking(id int) ! {
|
||||||
booking := app.service_get_booking(id) or { return error('Booking not found') }
|
booking := app.service_get_booking(id) or { return error('Booking not found') }
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ fn (app &App) service_cancel_booking(id int) ! {
|
|||||||
}!
|
}!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_get_booking is a function that retrieves a booking by its ID.
|
||||||
fn (app &App) service_get_booking(id int) !Booking {
|
fn (app &App) service_get_booking(id int) !Booking {
|
||||||
booking := sql app.db {
|
booking := sql app.db {
|
||||||
select from Booking where id == id
|
select from Booking where id == id
|
||||||
|
@@ -2,6 +2,7 @@ module main
|
|||||||
|
|
||||||
import time
|
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 {
|
fn (app &App) service_add_flight(from string, to string, departure time.Time, price int) !Flight {
|
||||||
flight_model := Flight{
|
flight_model := Flight{
|
||||||
from: from
|
from: from
|
||||||
@@ -24,6 +25,7 @@ fn (app &App) service_add_flight(from string, to string, departure time.Time, pr
|
|||||||
return flight[0]
|
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 {
|
fn (app &App) service_get_flight(id int) !Flight {
|
||||||
flight := sql app.db {
|
flight := sql app.db {
|
||||||
select from Flight where id == id
|
select from Flight where id == id
|
||||||
|
@@ -2,6 +2,7 @@ module main
|
|||||||
|
|
||||||
import veb.auth
|
import veb.auth
|
||||||
|
|
||||||
|
// service_add_user is a function that adds a new user to the database.
|
||||||
fn (app &App) service_add_user(first_name string, last_name string, email string, password string, gender string) ! {
|
fn (app &App) service_add_user(first_name string, last_name string, email string, password string, gender string) ! {
|
||||||
salt := auth.generate_salt()
|
salt := auth.generate_salt()
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ fn (app &App) service_add_user(first_name string, last_name string, email string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_find_user_by_email is a function that finds a user by their email address.
|
||||||
fn (app &App) service_find_user_by_email(email string, password string) !User {
|
fn (app &App) service_find_user_by_email(email string, password string) !User {
|
||||||
mut user := sql app.db {
|
mut user := sql app.db {
|
||||||
select from User where email == email
|
select from User where email == email
|
||||||
@@ -36,6 +38,7 @@ fn (app &App) service_find_user_by_email(email string, password string) !User {
|
|||||||
return user[0]
|
return user[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_update_user is a function that updates a user's information.
|
||||||
fn (app &App) service_update_user(id ?string, first_name string, last_name string, password string) ! {
|
fn (app &App) service_update_user(id ?string, first_name string, last_name string, password string) ! {
|
||||||
if id == none {
|
if id == none {
|
||||||
return error('User ID is required')
|
return error('User ID is required')
|
||||||
@@ -75,6 +78,7 @@ fn (app &App) service_update_user(id ?string, first_name string, last_name strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// service_get_user is a function that retrieves a user's information.
|
||||||
fn (app &App) service_get_user(id int) !User {
|
fn (app &App) service_get_user(id int) !User {
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
return error('User ID is required')
|
return error('User ID is required')
|
||||||
|
Reference in New Issue
Block a user