Add editor config and apply code cleanup
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -11,7 +11,7 @@ public static class GetCars
|
||||
{
|
||||
public IEnumerable<ResponseDto> Cars { get; set; } = [];
|
||||
}
|
||||
|
||||
|
||||
public record ResponseDto(Guid Id, string Name);
|
||||
|
||||
public class Request
|
||||
|
||||
@@ -3,9 +3,7 @@ using FluentValidation;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Vegasco.Server.Api.Authentication;
|
||||
using Vegasco.Server.Api.Common;
|
||||
using Vegasco.Server.Api.Persistence;
|
||||
@@ -51,7 +49,7 @@ public static class DependencyInjectionExtensions
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddHostedService<ApplyMigrationsService>();
|
||||
|
||||
|
||||
services.AddRequestLocalization(o =>
|
||||
{
|
||||
string[] cultures =
|
||||
@@ -61,7 +59,7 @@ public static class DependencyInjectionExtensions
|
||||
"de-DE",
|
||||
"de"
|
||||
];
|
||||
|
||||
|
||||
o.SetDefaultCulture(cultures[0])
|
||||
.AddSupportedCultures(cultures)
|
||||
.AddSupportedUICultures(cultures);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using System.Globalization;
|
||||
using Vegasco.Server.Api.Endpoints;
|
||||
using Vegasco.Server.Api.Endpoints;
|
||||
using Vegasco.Server.ServiceDefaults;
|
||||
|
||||
namespace Vegasco.Server.Api.Common;
|
||||
|
||||
@@ -7,47 +7,47 @@ namespace Vegasco.Server.Api.Consumptions;
|
||||
|
||||
public static class GetConsumptions
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public IEnumerable<ResponseDto> Consumptions { get; set; } = [];
|
||||
}
|
||||
public class ApiResponse
|
||||
{
|
||||
public IEnumerable<ResponseDto> Consumptions { get; set; } = [];
|
||||
}
|
||||
|
||||
public record ResponseDto(
|
||||
Guid Id,
|
||||
DateTimeOffset DateTime,
|
||||
double Distance,
|
||||
double Amount,
|
||||
bool IgnoreInCalculation,
|
||||
Guid CarId);
|
||||
public record ResponseDto(
|
||||
Guid Id,
|
||||
DateTimeOffset DateTime,
|
||||
double Distance,
|
||||
double Amount,
|
||||
bool IgnoreInCalculation,
|
||||
Guid CarId);
|
||||
|
||||
public class Request
|
||||
{
|
||||
[FromQuery(Name = "page")] public int? Page { get; set; }
|
||||
[FromQuery(Name = "pageSize")] public int? PageSize { get; set; }
|
||||
}
|
||||
public class Request
|
||||
{
|
||||
[FromQuery(Name = "page")] public int? Page { get; set; }
|
||||
[FromQuery(Name = "pageSize")] public int? PageSize { get; set; }
|
||||
}
|
||||
|
||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.MapGet("consumptions", Endpoint)
|
||||
.WithDescription("Returns all consumption entries")
|
||||
.WithTags("Consumptions");
|
||||
}
|
||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.MapGet("consumptions", Endpoint)
|
||||
.WithDescription("Returns all consumption entries")
|
||||
.WithTags("Consumptions");
|
||||
}
|
||||
|
||||
private static async Task<Ok<ApiResponse>> Endpoint(
|
||||
[AsParameters] Request request,
|
||||
ApplicationDbContext dbContext,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
List<ResponseDto> consumptions = await dbContext.Consumptions
|
||||
.Select(x =>
|
||||
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
||||
.ToListAsync(cancellationToken);
|
||||
private static async Task<Ok<ApiResponse>> Endpoint(
|
||||
[AsParameters] Request request,
|
||||
ApplicationDbContext dbContext,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
List<ResponseDto> consumptions = await dbContext.Consumptions
|
||||
.Select(x =>
|
||||
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var apiResponse = new ApiResponse
|
||||
{
|
||||
Consumptions = consumptions
|
||||
};
|
||||
return TypedResults.Ok(apiResponse);
|
||||
}
|
||||
var apiResponse = new ApiResponse
|
||||
{
|
||||
Consumptions = consumptions
|
||||
};
|
||||
return TypedResults.Ok(apiResponse);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public static class EndpointExtensions
|
||||
|
||||
RouteGroupBuilder versionedApis = builder.MapGroup("/v{apiVersion:apiVersion}")
|
||||
.WithApiVersionSet(apiVersionSet);
|
||||
|
||||
|
||||
GetCar.MapEndpoint(versionedApis)
|
||||
.RequireAuthorization(Constants.Authorization.RequireAuthenticatedUserPolicy);
|
||||
GetCars.MapEndpoint(versionedApis)
|
||||
|
||||
@@ -4,26 +4,26 @@ namespace Vegasco.Server.Api.Info;
|
||||
|
||||
public class GetServerInfo
|
||||
{
|
||||
public record Response(
|
||||
string FullVersion,
|
||||
string CommitId,
|
||||
DateTimeOffset CommitDate,
|
||||
string Environment);
|
||||
public record Response(
|
||||
string FullVersion,
|
||||
string CommitId,
|
||||
DateTimeOffset CommitDate,
|
||||
string Environment);
|
||||
|
||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.MapGet("info/server", Endpoint)
|
||||
.WithTags("Info");
|
||||
}
|
||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
return builder
|
||||
.MapGet("info/server", Endpoint)
|
||||
.WithTags("Info");
|
||||
}
|
||||
|
||||
private static Ok<Response> Endpoint(
|
||||
IHostEnvironment environment)
|
||||
{
|
||||
return TypedResults.Ok(new Response(
|
||||
ThisAssembly.AssemblyInformationalVersion,
|
||||
ThisAssembly.GitCommitId,
|
||||
new DateTimeOffset(ThisAssembly.GitCommitDate, TimeSpan.Zero),
|
||||
environment.EnvironmentName));
|
||||
}
|
||||
private static Ok<Response> Endpoint(
|
||||
IHostEnvironment environment)
|
||||
{
|
||||
return TypedResults.Ok(new Response(
|
||||
ThisAssembly.AssemblyInformationalVersion,
|
||||
ThisAssembly.GitCommitId,
|
||||
new DateTimeOffset(ThisAssembly.GitCommitDate, TimeSpan.Zero),
|
||||
environment.EnvironmentName));
|
||||
}
|
||||
}
|
||||
@@ -4,86 +4,86 @@
|
||||
|
||||
namespace Vegasco.Server.Api.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cars",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
UserId = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cars", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Cars_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cars",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
UserId = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cars", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Cars_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Consumptions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DateTime = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Distance = table.Column<double>(type: "double precision", nullable: false),
|
||||
Amount = table.Column<double>(type: "double precision", nullable: false),
|
||||
IgnoreInCalculation = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CarId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Consumptions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Consumptions_Cars_CarId",
|
||||
column: x => x.CarId,
|
||||
principalTable: "Cars",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Consumptions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DateTime = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
Distance = table.Column<double>(type: "double precision", nullable: false),
|
||||
Amount = table.Column<double>(type: "double precision", nullable: false),
|
||||
IgnoreInCalculation = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CarId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Consumptions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Consumptions_Cars_CarId",
|
||||
column: x => x.CarId,
|
||||
principalTable: "Cars",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Cars_UserId",
|
||||
table: "Cars",
|
||||
column: "UserId");
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Cars_UserId",
|
||||
table: "Cars",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Consumptions_CarId",
|
||||
table: "Consumptions",
|
||||
column: "CarId");
|
||||
}
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Consumptions_CarId",
|
||||
table: "Consumptions",
|
||||
column: "CarId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Consumptions");
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Consumptions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cars");
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cars");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user