From 585c5c8537eb21dfc9f16108548e63d9ced3d971 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 24 Oct 2022 12:29:23 +0800 Subject: feat: Before move to FastEndpoints --- code/api/src/Endpoints/EndpointBase.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 code/api/src/Endpoints/EndpointBase.cs (limited to 'code/api/src/Endpoints/EndpointBase.cs') diff --git a/code/api/src/Endpoints/EndpointBase.cs b/code/api/src/Endpoints/EndpointBase.cs new file mode 100644 index 0000000..c088976 --- /dev/null +++ b/code/api/src/Endpoints/EndpointBase.cs @@ -0,0 +1,27 @@ +using System.Diagnostics; + +namespace IOL.GreatOffice.Api.Endpoints; + +[ApiController] +public class EndpointBase : ControllerBase +{ + /// + /// User data for the currently logged on user. + /// + 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 errors = default) { + return new ObjectResult(new KnownProblemModel { + Title = title, + Subtitle = subtitle, + Errors = errors, + TraceId = Activity.Current?.Id, + RequestId = HttpContext.TraceIdentifier + }) { + StatusCode = (int) HttpStatusCode.BadRequest + }; + } +} \ No newline at end of file -- cgit v1.3