This commit is contained in:
fitel17112 2025-03-15 20:16:58 +05:30
parent fb35adcd14
commit b705500e54
3 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,7 @@ module main
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) ! {
booking := Booking{
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 {
bookings := sql app.db {
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
}
// service_cancel_booking is a function that cancels a booking.
fn (app &App) service_cancel_booking(id int) ! {
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 {
booking := sql app.db {
select from Booking where id == id

View File

@ -2,6 +2,7 @@ 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
@ -24,6 +25,7 @@ fn (app &App) service_add_flight(from string, to string, departure time.Time, pr
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

View File

@ -2,6 +2,7 @@ module main
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) ! {
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 {
mut user := sql app.db {
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]
}
// 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) ! {
if id == none {
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
}
// service_get_user is a function that retrieves a user's information.
fn (app &App) service_get_user(id int) !User {
if id == 0 {
return error('User ID is required')