-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersController.cs
More file actions
49 lines (42 loc) · 1.27 KB
/
UsersController.cs
File metadata and controls
49 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Timetracker.BLL.Exceptions;
using Timetracker.BLL.Services.Interfaces;
using Timetracker.Models.Data;
namespace Timetracker.Web.Controllers
{
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/[controller]")]
[ApiController]
public class UsersController : ControllerBase
{
private readonly IUserService _userService;
public UsersController(
IUserService userServivce
)
{
_userService = userServivce;
}
[HttpGet("getAll")]
public async Task<IActionResult> GetAllUsers()
{
var res = await _userService.GetAllUsers();
return Ok(res);
}
[HttpGet("get/{id}")]
public async Task<ActionResult> GetUser(int id)
{
try
{
var result = await _userService.GetUser(id);
return Ok(result);
}
catch (NoSuchEntityException exception)
{
return BadRequest(new Error(exception.Message, exception.GetType()));
}
}
}
}