Files
4/src/faculty_controller.v
2024-07-18 01:08:21 +05:30

50 lines
1.2 KiB
V

module main
import vweb
@['/controller/faculty'; post]
pub fn (mut app App) controller_get_faculty() vweb.Result {
email := app.query['em']
password := app.query['pw']
response := app.service_get_faculty(email, password) or {
app.set_status(400, '')
return app.text('${err}')
}
app.set_status(201, '')
return app.json(response)
}
@['/controller/faculty/create'; post]
pub fn (mut app App) controller_create_faculty() vweb.Result {
firstname := app.query['fn']
lastname := app.query['ln']
email := app.query['em']
password := app.query['pw']
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.json(Status {
ok: true,
msg: 'faculty created successfully',
})
}