Add parameter for time zone

This commit is contained in:
2023-03-21 10:36:02 -04:00
parent 96db1d3517
commit 9b0710b9d8
4 changed files with 24 additions and 6 deletions

View File

@@ -21,9 +21,26 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers
}
[HttpGet("recent")]
public async Task<ActionResult<WeatherReading>> GetRecent()
public async Task<ActionResult<WeatherReading>> GetRecent([FromQuery] string tz)
{
return await _database.GetRecentReading();
var recentReading = await _database.GetRecentReading();
if (string.IsNullOrWhiteSpace(tz))
return recentReading;
try
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tz);
recentReading.Timestamp = recentReading.Timestamp.ToOffset(timeZoneInfo.GetUtcOffset(recentReading.Timestamp));
recentReading.GpsTimestamp = recentReading.GpsTimestamp.ToOffset(timeZoneInfo.GetUtcOffset(recentReading.GpsTimestamp));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
return recentReading;
}
[HttpGet("history")]

View File

@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
WORKDIR /src
COPY ["./Service.csproj", "./"]
RUN dotnet restore "Service.csproj"
@@ -11,6 +11,7 @@ WORKDIR "/src"
RUN dotnet publish "Service.csproj" -c Release -o /app
FROM base AS final
RUN apk add --no-cache tzdata
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "ChrisKaczor.HomeMonitor.Weather.Service.dll"]

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<AssemblyName>ChrisKaczor.HomeMonitor.Weather.Service</AssemblyName>
<RootNamespace>ChrisKaczor.HomeMonitor.Weather.Service</RootNamespace>

View File

@@ -28,7 +28,7 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service
services.AddCors(o => o.AddPolicy("CorsPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().WithOrigins("http://localhost:4200")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddJsonOptions(configure =>
services.AddMvc().AddJsonOptions(configure =>
{
configure.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});