Last change
on this file since b66b3ac was b66b3ac, checked in by Danilo <danilo.najkov@…>, 2 years ago |
Add project files.
|
-
Property mode
set to
100644
|
File size:
841 bytes
|
Rev | Line | |
---|
[b66b3ac] | 1 | namespace backend.Controllers;
|
---|
| 2 |
|
---|
| 3 | using backend.Helpers;
|
---|
| 4 | using backend.Models;
|
---|
| 5 | using backend.Services;
|
---|
| 6 | using Microsoft.AspNetCore.Mvc;
|
---|
| 7 |
|
---|
| 8 | [ApiController]
|
---|
| 9 | [Route("[controller]")]
|
---|
| 10 | public class UsersController : ControllerBase
|
---|
| 11 | {
|
---|
| 12 | private IUserService _userService;
|
---|
| 13 |
|
---|
| 14 | public UsersController(IUserService userService)
|
---|
| 15 | {
|
---|
| 16 | _userService = userService;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | [HttpPost("authenticate")]
|
---|
| 20 | public IActionResult Authenticate(AuthenticateRequest model)
|
---|
| 21 | {
|
---|
| 22 | var response = _userService.Authenticate(model);
|
---|
| 23 |
|
---|
| 24 | if (response == null)
|
---|
| 25 | return BadRequest(new { message = "Username or password is incorrect" });
|
---|
| 26 |
|
---|
| 27 | return Ok(response);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | [Authorize]
|
---|
| 31 | [HttpGet]
|
---|
| 32 | public IActionResult GetUserById(int id)
|
---|
| 33 | {
|
---|
| 34 | var users = _userService.GetById(id);
|
---|
| 35 | return Ok(users);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.