016
This commit is contained in:
@@ -111,3 +111,33 @@ pub fn (app &App) controller_get_user_bookings(mut ctx Context) veb.Result {
|
||||
|
||||
return ctx.html(html)
|
||||
}
|
||||
|
||||
@['/controller/booking/user/cancel'; post]
|
||||
pub fn (app &App) controller_cancel_booking(mut ctx Context, id int) veb.Result {
|
||||
user_token := ctx.get_cookie('token') or { '' }
|
||||
token := app.auth.find_token(user_token) or {
|
||||
return ctx.html('<div class="alert alert-danger">User not logged in. Please <a href="/login">login</a> to continue.</div>')
|
||||
}
|
||||
|
||||
if token.user_id == 0 {
|
||||
return ctx.html('<div class="alert alert-danger">User not logged in. Please <a href="/login">login</a> to continue.</div>')
|
||||
}
|
||||
|
||||
if id == 0 {
|
||||
return ctx.html('<div class="alert alert-danger">Invalid booking ID</div>')
|
||||
}
|
||||
|
||||
booking := app.service_get_booking(id) or {
|
||||
return ctx.html('<div class="alert alert-danger">Booking not found</div>')
|
||||
}
|
||||
|
||||
if booking.user_id != token.user_id {
|
||||
return ctx.html('<div class="alert alert-danger">Unauthorized</div>')
|
||||
}
|
||||
|
||||
app.service_cancel_booking(id) or {
|
||||
return ctx.html('<div class="alert alert-danger">Error canceling booking: ${err}</div>')
|
||||
}
|
||||
|
||||
return ctx.html('<div class="alert alert-success">Booking canceled successfully!</div>')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user