| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | import json |
| 5 | |
| 6 | @['/auth/login'; post] |
| 7 | pub fn (mut app App) controller_auth(mut ctx Context) veb.Result { |
| 8 | body := json.decode(AuthRequestDto, ctx.req.data) or { |
| 9 | ctx.res.set_status(.bad_request) |
| 10 | return ctx.text('Failed to decode json, error: ${err}') |
| 11 | } |
| 12 | |
| 13 | response := app.service_auth(body.username, body.password) or { |
| 14 | ctx.res.set_status(.bad_request) |
| 15 | return ctx.text('error: ${err}') |
| 16 | } |
| 17 | |
| 18 | return ctx.json(response) |
| 19 | } |
| 20 |