This commit is contained in:
2024-07-05 23:57:32 +05:30
commit 8dbbe65a09
29 changed files with 554 additions and 0 deletions

39
src/faculty_controller.v Normal file
View 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')
}