mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-13 17:22:54 -05:00
Add parameter for time zone
This commit is contained in:
@@ -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")]
|
||||
|
||||
@@ -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"]
|
||||
@@ -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>
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user