1
This commit is contained in:
39
src/faculty_controller.v
Normal file
39
src/faculty_controller.v
Normal file
@@ -0,0 +1,39 @@
|
||||
module main
|
||||
|
||||
import vweb
|
||||
|
||||
|
||||
@['/controller/faculty'; post]
|
||||
pub fn (mut app App) controller_get_faculty(email string, password string) vweb.Result {
|
||||
response := app.service_get_faculty(email, password) or {
|
||||
app.set_status(400, '')
|
||||
return app.text('${err}')
|
||||
}
|
||||
return app.json(response)
|
||||
}
|
||||
|
||||
@['/controller/faculty/create'; post]
|
||||
pub fn (mut app App) controller_create_faculty(firstname string, lastname string, email string, password string) vweb.Result {
|
||||
if firstname == '' {
|
||||
app.set_status(400, '')
|
||||
return app.text('firstname cannot be empty')
|
||||
}
|
||||
if lastname == '' {
|
||||
app.set_status(400, '')
|
||||
return app.text('lastname cannot be empty')
|
||||
}
|
||||
if email == '' {
|
||||
app.set_status(400, '')
|
||||
return app.text('username cannot be empty')
|
||||
}
|
||||
if password == '' {
|
||||
app.set_status(400, '')
|
||||
return app.text('password cannot be empty')
|
||||
}
|
||||
app.service_add_faculty(firstname, lastname, email, password) or {
|
||||
app.set_status(400, '')
|
||||
return app.text('error: ${err}')
|
||||
}
|
||||
app.set_status(201, '')
|
||||
return app.redirect('/faculty')
|
||||
}
|
||||
Reference in New Issue
Block a user