Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1c1bbfdf

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Added GET /users/me endpoint

Zobrazit rozdíly:

Backend/Backend/Controllers/UserController.cs
45 45
            {
46 46
                throw new InternalErrorException(e.Message);
47 47
            }
48
        }
48 49

  
50
        [HttpGet("/users/me")]
51
        [Authorize]
52
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserMeResponse))]
53
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
54
        public ActionResult<UserMeResponse> Me([FromServices] ClientInfo clientInfo)
55
        {
56
            if (clientInfo.LoggedUser == null)
57
            {
58
                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /users");
59
                return Problem();
60
            }
49 61

  
62
            return new UserMeResponse()
63
            {
64
                Name = clientInfo.LoggedUser.Name,
65
                Role = clientInfo.LoggedUser.Role
66
            };
50 67
        }
51 68

  
52 69
        [HttpGet("/user/annotations")]
Backend/Models/Users/UserMeResponse.cs
1
using Models.Enums;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Models.Users
9
{
10
    public class UserMeResponse
11
    {
12
        public string Name { get; set; }
13
        public ERole Role { get; set; }
14
    }
15
}

Také k dispozici: Unified diff