Add endpoint to query the system's current time
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2025-10-16 17:23:47 +02:00
parent ad77c2fe2b
commit db791a1183
4 changed files with 55 additions and 1 deletions

View File

@@ -41,5 +41,6 @@ public static class EndpointExtensions
.RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy); .RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy);
GetServerInfo.MapEndpoint(versionedApis); GetServerInfo.MapEndpoint(versionedApis);
GetCurrentTime.MapEndpoint(versionedApis);
} }
} }

View File

@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Http.HttpResults;
namespace Vegasco.Server.Api.Info;
public static class GetCurrentTime
{
public record Response(DateTimeOffset CurrentTime);
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
{
return builder
.MapGet("info/time", Endpoint)
.WithTags("Info");
}
private static Ok<Response> Endpoint(
TimeProvider timeProvider)
{
return TypedResults.Ok(new Response(timeProvider.GetUtcNow()));
}
}

View File

@@ -2,7 +2,7 @@
namespace Vegasco.Server.Api.Info; namespace Vegasco.Server.Api.Info;
public class GetServerInfo public static class GetServerInfo
{ {
public record Response( public record Response(
string FullVersion, string FullVersion,

View File

@@ -0,0 +1,32 @@
using FluentAssertions;
using FluentAssertions.Extensions;
using System.Net.Http.Json;
using Vegasco.Server.Api.Info;
namespace Vegasco.Server.Api.Tests.Integration.Info;
[Collection(SharedTestCollection.Name)]
public sealed class GetCurrentTimeTests
{
private readonly WebAppFactory _factory;
public GetCurrentTimeTests(WebAppFactory factory)
{
_factory = factory;
}
[Fact]
public async Task GetServerInfo_ShouldReturnServerInfo_WhenCalled()
{
// Arrange
// Act
using HttpResponseMessage response = await _factory.HttpClient.GetAsync("/v1/info/time");
// Assert
response.IsSuccessStatusCode.Should().BeTrue();
GetCurrentTime.Response? timeInfo = await response.Content.ReadFromJsonAsync<GetCurrentTime.Response>();
timeInfo.Should().NotBeNull();
timeInfo.CurrentTime.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromSeconds(10));
}
}