aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/EndpointBase.cs
diff options
context:
space:
mode:
authorivar <i@oiee.no>2024-04-28 22:37:48 +0200
committerivar <i@oiee.no>2024-04-28 22:37:48 +0200
commitf356f15d3a7dce1669944d23ab395ec96d042293 (patch)
tree03a82934ec802e2579daa45f748e959dc6598847 /code/api/src/Endpoints/EndpointBase.cs
parentf99db65435f2cac81b5b48eb117991f4acd66a7e (diff)
downloadgreatoffice-f356f15d3a7dce1669944d23ab395ec96d042293.tar.xz
greatoffice-f356f15d3a7dce1669944d23ab395ec96d042293.zip
Misc
Diffstat (limited to 'code/api/src/Endpoints/EndpointBase.cs')
-rw-r--r--code/api/src/Endpoints/EndpointBase.cs21
1 files changed, 7 insertions, 14 deletions
diff --git a/code/api/src/Endpoints/EndpointBase.cs b/code/api/src/Endpoints/EndpointBase.cs
index e8e2494..584f43e 100644
--- a/code/api/src/Endpoints/EndpointBase.cs
+++ b/code/api/src/Endpoints/EndpointBase.cs
@@ -8,18 +8,15 @@ public class EndpointBase : ControllerBase
/// <summary>
/// User data for the currently logged on user.
/// </summary>
- protected LoggedInUserModel LoggedInUser => new()
- {
+ protected LoggedInUserModel LoggedInUser => new() {
Username = User.FindFirstValue(AppClaims.NAME),
Id = User.FindFirstValue(AppClaims.USER_ID).AsGuid(),
};
[NonAction]
- protected ActionResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default)
- {
+ protected ActionResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default) {
HttpContext.Response.Headers.Append(AppHeaders.IS_KNOWN_PROBLEM, "1");
- return BadRequest(new KnownProblemModel
- {
+ return BadRequest(new KnownProblemModel {
Title = title,
Subtitle = subtitle,
Errors = errors,
@@ -28,31 +25,27 @@ public class EndpointBase : ControllerBase
}
[NonAction]
- protected ActionResult KnownProblem(KnownProblemModel problem)
- {
+ protected ActionResult KnownProblem(KnownProblemModel problem) {
HttpContext.Response.Headers.Append(AppHeaders.IS_KNOWN_PROBLEM, "1");
problem.TraceId = HttpContext.TraceIdentifier;
return BadRequest(problem);
}
[NonAction]
- protected RequestTimeZoneInfo GetRequestTimeZone(ILogger logger = default)
- {
+ protected RequestTimeZoneInfo GetRequestTimeZone(ILogger logger = default) {
Request.Headers.TryGetValue(AppHeaders.BROWSER_TIME_ZONE, out var timeZoneHeader);
var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneHeader.ToString().HasValue() ? timeZoneHeader.ToString() : "UTC");
var offset = tz.BaseUtcOffset.Hours;
// This is fine as long as the client is not connecting from Australia: Lord Howe Island,
// according to https://en.wikipedia.org/wiki/Daylight_saving_time_by_country
- if (tz.IsDaylightSavingTime(AppDateTime.UtcNow))
- {
+ if (tz.IsDaylightSavingTime(AppDateTime.UtcNow)) {
offset++;
}
logger?.LogInformation("Request time zone (" + tz.Id + ") offset is: " + offset + " hours");
- return new RequestTimeZoneInfo()
- {
+ return new RequestTimeZoneInfo() {
TimeZoneInfo = tz,
Offset = offset,
LocalDateTime = TimeZoneInfo.ConvertTimeFromUtc(AppDateTime.UtcNow, tz)