aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Endpoints/EndpointBase.cs
blob: 320ce8dfc44b0c5bbaf3fbe8a8d909c94a674885 (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
namespace I2R.Storage.Api.Endpoints;

[ApiController]
[Authorize]
public class EndpointBase : ControllerBase
{
    protected LoggedInUserModel LoggedInUser => new(User);

    [NonAction]
    protected ActionResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default) {
        HttpContext.Response.Headers.Add(AppHeaders.IS_KNOWN_PROBLEM, "1");
        return BadRequest(new KnownProblemModel {
            Title = title,
            Subtitle = subtitle,
            Errors = errors,
            TraceId = HttpContext.TraceIdentifier
        });
    }

    [NonAction]
    protected ActionResult KnownProblem(KnownProblemModel problem) {
        HttpContext.Response.Headers.Add(AppHeaders.IS_KNOWN_PROBLEM, "1");
        problem.TraceId = HttpContext.TraceIdentifier;
        return BadRequest(problem);
    }
}