aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/EndpointBase.cs
blob: c088976ae21fb717c8a9d8b89b626baa20d10167 (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
using System.Diagnostics;

namespace IOL.GreatOffice.Api.Endpoints;

[ApiController]
public class EndpointBase : ControllerBase
{
    /// <summary>
    /// User data for the currently logged on user.
    /// </summary>
    protected LoggedInUserModel LoggedInUser => new() {
        Username = User.FindFirstValue(AppClaims.NAME),
        Id = User.FindFirstValue(AppClaims.USER_ID).AsGuid(),
    };

    public ObjectResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string> errors = default) {
        return new ObjectResult(new KnownProblemModel {
            Title = title,
            Subtitle = subtitle,
            Errors = errors,
            TraceId = Activity.Current?.Id,
            RequestId = HttpContext.TraceIdentifier
        }) {
            StatusCode = (int) HttpStatusCode.BadRequest
        };
    }
}