Projekt

Obecné

Profil

Stáhnout (2.12 KB) Statistiky
| Větev: | Tag: | Revize:
1
using Core.Services;
2
using Core.Services.AnnotationService;
3
using Microsoft.AspNetCore.Mvc;
4
using Models.Users;
5
using RestAPI.Authentication;
6
using RestAPI.Controllers.Common;
7
using RestAPI.Exceptions;
8
using RestAPI.Utils;
9
using System.Net;
10

    
11
namespace RestAPI.Controllers
12
{
13
    public class UserController : CommonControllerBase
14
    {
15
        private readonly Serilog.ILogger logger;
16
        private readonly IUserService userService;
17
        private readonly IAnnotationService annotationService;
18

    
19
        public UserController(Serilog.ILogger logger, IUserService userService, IAnnotationService annotationService)
20
        {
21
            this.logger = logger;
22
            this.userService = userService;
23
            this.annotationService = annotationService;
24
        }
25

    
26
        [HttpGet("/users")]
27
        [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
28
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserList))]
29
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
30
        public ActionResult<UserList> GetUsers([FromServices] ClientInfo clientInfo)
31
        {
32
            if (clientInfo.LoggedUser == null)
33
            {
34
                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /users");
35
                return Problem();
36
            }
37

    
38
            try
39
            {
40
                var userList = userService.GetUsers();
41
                return Ok(userList);
42
            }
43
            catch (Exception e)
44
            {
45
                throw new InternalErrorException(e.Message);
46
            }
47

    
48

    
49
        }
50

    
51
        [HttpGet("/user/annotations")]
52
        [ProducesResponseType((int)HttpStatusCode.OK)]
53
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
54
        public ActionResult GetUserAnnotations([FromServices] ClientInfo clientInfo)
55
        {
56
            if (clientInfo.LoggedUser == null)
57
            {
58
                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
59
                return Problem();
60
            }
61

    
62
            var res = annotationService.GetUserAnnotations(clientInfo.LoggedUser.Id);
63
            return Ok(res);
64
        }
65
    }
66
}
(5-5/5)