diff --git a/Weather/Service/Controllers/ReadingsController.cs b/Weather/Service/Controllers/ReadingsController.cs index c33f16c..ef50646 100644 --- a/Weather/Service/Controllers/ReadingsController.cs +++ b/Weather/Service/Controllers/ReadingsController.cs @@ -21,9 +21,26 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers } [HttpGet("recent")] - public async Task> GetRecent() + public async Task> 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")] diff --git a/Weather/Service/Dockerfile b/Weather/Service/Dockerfile index 81f7899..e23636d 100644 --- a/Weather/Service/Dockerfile +++ b/Weather/Service/Dockerfile @@ -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"] \ No newline at end of file diff --git a/Weather/Service/Service.csproj b/Weather/Service/Service.csproj index ded3df1..c7c4ca8 100644 --- a/Weather/Service/Service.csproj +++ b/Weather/Service/Service.csproj @@ -1,7 +1,7 @@  - net5.0 + net7.0 InProcess ChrisKaczor.HomeMonitor.Weather.Service ChrisKaczor.HomeMonitor.Weather.Service diff --git a/Weather/Service/Startup.cs b/Weather/Service/Startup.cs index 96a190a..4c261a2 100644 --- a/Weather/Service/Startup.cs +++ b/Weather/Service/Startup.cs @@ -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()); });