blob: 8618c1bcaaf51a5f27263ad551df1ed0f6c67bd9 (
plain) (
blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
using System.Threading.Tasks;
using API.Database;
using API.Service;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Data.Models.DTOs;
using Microsoft.AspNetCore.Authorization;
using Data.Models.Classes;
using Microsoft.Extensions.Configuration;
namespace API.Controllers
{
[Authorize]
[ApiController]
[Route("/api/[controller]")]
public class UserController: ControllerBase
{
private readonly UserService _service;
public UserController(DevHiveContext context, IMapper mapper, IConfiguration configuration)
{
this._service = new UserService(context, mapper, configuration.GetSection("AppSettings"));
}
[AllowAnonymous]
[HttpPost]
[Route("login")]
public async Task<IActionResult> Login([FromBody] UserDTO userDTO)
{
return await this._service.LoginUser(userDTO);
}
//Create
[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> Create([FromBody] UserDTO userDTO)
{
return await this._service.CreateUser(userDTO);
}
//Read
[HttpGet]
[Authorize(Roles = UserRoles.Admin)] // Functionality, only for testing purposes
public async Task<IActionResult> GetById(int id)
{
return await this._service.GetUserById(id);
}
//Update
[HttpPut]
public async Task<IActionResult> Update(int id, [FromBody] UserDTO userDTO)
{
return await this._service.UpdateUser(id, userDTO);
}
//Delete
[HttpDelete]
public async Task<IActionResult> Delete(int id)
{
return await this._service.DeleteUser(id);
}
}
}
|