Compare commits
17 Commits
ad77c2fe2b
...
production
| Author | SHA1 | Date | |
|---|---|---|---|
| d4ae137115 | |||
| 9f51f508ce | |||
| 62824549fc | |||
| 0cb5e44f7a | |||
| 7d7f5750e3 | |||
| 789ba35c60 | |||
| 1226c42f19 | |||
| 5e083aeaf6 | |||
| 31efd6b4ad | |||
| 69bb19e4eb | |||
| db791a1183 | |||
| f248be4e1f | |||
| 67d29333d9 | |||
| c57972d9a6 | |||
| ea019ebfa6 | |||
| 66c23ffb4f | |||
| 00e0869a13 |
@@ -42,9 +42,11 @@ steps:
|
||||
- name: docker build and push
|
||||
image: docker:24.0.7
|
||||
commands:
|
||||
- docker build . -t $docker_registry$docker_repo:$DRONE_BRANCH
|
||||
- dockerImageWithTag="$docker_registry$docker_repo:$DRONE_BRANCH"
|
||||
- docker build . -t $dockerImageWithTag
|
||||
- echo $docker_password | docker login --username $docker_username --password-stdin $docker_registry
|
||||
- docker push $docker_registry$docker_repo:$DRONE_BRANCH
|
||||
- docker push $dockerImageWithTag
|
||||
- echo "Built and pushed $dockerImageWithTag"
|
||||
environment:
|
||||
docker_username:
|
||||
from_secret: docker_username
|
||||
|
||||
@@ -26,13 +26,13 @@ public static class CreateConsumption
|
||||
{
|
||||
public Validator(TimeProvider timeProvider)
|
||||
{
|
||||
DateTime todayEndOfDay = timeProvider.GetUtcNow()
|
||||
Func<DateTimeOffset> getTodayEndOfDay = () => timeProvider.GetUtcNow()
|
||||
.Date
|
||||
.AddDays(1)
|
||||
.AddTicks(-1);
|
||||
|
||||
RuleFor(x => x.DateTime.ToUniversalTime())
|
||||
.LessThanOrEqualTo(todayEndOfDay)
|
||||
.LessThanOrEqualTo(_ => getTodayEndOfDay())
|
||||
.WithName(nameof(Request.DateTime));
|
||||
|
||||
RuleFor(x => x.Distance)
|
||||
|
||||
@@ -26,13 +26,13 @@ public static class UpdateConsumption
|
||||
{
|
||||
public Validator(TimeProvider timeProvider)
|
||||
{
|
||||
DateTime todayEndOfDay = timeProvider.GetUtcNow()
|
||||
Func<DateTimeOffset> getTodayEndOfDay = () => timeProvider.GetUtcNow()
|
||||
.Date
|
||||
.AddDays(1)
|
||||
.AddTicks(-1);
|
||||
|
||||
RuleFor(x => x.DateTime.ToUniversalTime())
|
||||
.LessThanOrEqualTo(todayEndOfDay)
|
||||
.LessThanOrEqualTo(_ => getTodayEndOfDay())
|
||||
.WithName(nameof(Request.DateTime));
|
||||
|
||||
RuleFor(x => x.Distance)
|
||||
|
||||
@@ -41,5 +41,6 @@ public static class EndpointExtensions
|
||||
.RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy);
|
||||
|
||||
GetServerInfo.MapEndpoint(versionedApis);
|
||||
GetCurrentTime.MapEndpoint(versionedApis);
|
||||
}
|
||||
}
|
||||
|
||||
21
src/Vegasco.Server.Api/Info/GetCurrentTime.cs
Normal file
21
src/Vegasco.Server.Api/Info/GetCurrentTime.cs
Normal 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()));
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Vegasco.Server.Api.Info;
|
||||
|
||||
public class GetServerInfo
|
||||
public static class GetServerInfo
|
||||
{
|
||||
public record Response(
|
||||
string FullVersion,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user