Drop IgnoreInCalculation property
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:
@@ -14,8 +14,6 @@ public class Consumption
|
|||||||
|
|
||||||
public double Amount { get; set; }
|
public double Amount { get; set; }
|
||||||
|
|
||||||
public bool IgnoreInCalculation { get; set; }
|
|
||||||
|
|
||||||
public CarId CarId { get; set; }
|
public CarId CarId { get; set; }
|
||||||
|
|
||||||
public virtual Car Car { get; set; } = null!;
|
public virtual Car Car { get; set; } = null!;
|
||||||
@@ -39,9 +37,6 @@ public class ConsumptionTableConfiguration : IEntityTypeConfiguration<Consumptio
|
|||||||
builder.Property(x => x.Amount)
|
builder.Property(x => x.Amount)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
builder.Property(x => x.IgnoreInCalculation)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
builder.Property(x => x.CarId)
|
builder.Property(x => x.CarId)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasConversion<CarId.EfCoreValueConverter>();
|
.HasConversion<CarId.EfCoreValueConverter>();
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace Vegasco.Server.Api.Consumptions;
|
|||||||
|
|
||||||
public static class CreateConsumption
|
public static class CreateConsumption
|
||||||
{
|
{
|
||||||
public record Request(DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation, Guid CarId);
|
public record Request(DateTimeOffset DateTime, double Distance, double Amount, Guid CarId);
|
||||||
|
|
||||||
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation, Guid CarId);
|
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, Guid CarId);
|
||||||
|
|
||||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
@@ -58,12 +58,11 @@ public static class CreateConsumption
|
|||||||
return TypedResults.NotFound();
|
return TypedResults.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var consumption = new Consumption
|
Consumption consumption = new()
|
||||||
{
|
{
|
||||||
DateTime = request.DateTime.ToUniversalTime(),
|
DateTime = request.DateTime.ToUniversalTime(),
|
||||||
Distance = request.Distance,
|
Distance = request.Distance,
|
||||||
Amount = request.Amount,
|
Amount = request.Amount,
|
||||||
IgnoreInCalculation = request.IgnoreInCalculation,
|
|
||||||
CarId = new CarId(request.CarId)
|
CarId = new CarId(request.CarId)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,6 +70,6 @@ public static class CreateConsumption
|
|||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return TypedResults.Created($"consumptions/{consumption.Id.Value}",
|
return TypedResults.Created($"consumptions/{consumption.Id.Value}",
|
||||||
new Response(consumption.Id.Value, consumption.DateTime, consumption.Distance, consumption.Amount, consumption.IgnoreInCalculation, consumption.CarId.Value));
|
new Response(consumption.Id.Value, consumption.DateTime, consumption.Distance, consumption.Amount, consumption.CarId.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace Vegasco.Server.Api.Consumptions;
|
|||||||
|
|
||||||
public static class GetConsumption
|
public static class GetConsumption
|
||||||
{
|
{
|
||||||
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation, Guid CarId);
|
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, Guid CarId);
|
||||||
|
|
||||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
@@ -28,8 +28,12 @@ public static class GetConsumption
|
|||||||
return TypedResults.NotFound();
|
return TypedResults.NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new Response(consumption.Id.Value, consumption.DateTime, consumption.Distance,
|
Response response = new(
|
||||||
consumption.Amount, consumption.IgnoreInCalculation, consumption.CarId.Value);
|
consumption.Id.Value,
|
||||||
|
consumption.DateTime,
|
||||||
|
consumption.Distance,
|
||||||
|
consumption.Amount,
|
||||||
|
consumption.CarId.Value);
|
||||||
return TypedResults.Ok(response);
|
return TypedResults.Ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,6 @@ public static class GetConsumptions
|
|||||||
DateTimeOffset DateTime,
|
DateTimeOffset DateTime,
|
||||||
double Distance,
|
double Distance,
|
||||||
double Amount,
|
double Amount,
|
||||||
bool IgnoreInCalculation,
|
|
||||||
Guid CarId);
|
Guid CarId);
|
||||||
|
|
||||||
public class Request
|
public class Request
|
||||||
@@ -43,7 +42,7 @@ public static class GetConsumptions
|
|||||||
List<ResponseDto> consumptions = await dbContext.Consumptions
|
List<ResponseDto> consumptions = await dbContext.Consumptions
|
||||||
.OrderByDescending(x => x.DateTime)
|
.OrderByDescending(x => x.DateTime)
|
||||||
.Select(x =>
|
.Select(x =>
|
||||||
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.IgnoreInCalculation, x.CarId.Value))
|
new ResponseDto(x.Id.Value, x.DateTime, x.Distance, x.Amount, x.CarId.Value))
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
ApiResponse apiResponse = new()
|
ApiResponse apiResponse = new()
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ namespace Vegasco.Server.Api.Consumptions;
|
|||||||
|
|
||||||
public static class UpdateConsumption
|
public static class UpdateConsumption
|
||||||
{
|
{
|
||||||
public record Request(DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation);
|
public record Request(DateTimeOffset DateTime, double Distance, double Amount);
|
||||||
|
|
||||||
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, bool IgnoreInCalculation, Guid CarId);
|
public record Response(Guid Id, DateTimeOffset DateTime, double Distance, double Amount, Guid CarId);
|
||||||
|
|
||||||
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
@@ -60,10 +60,9 @@ public static class UpdateConsumption
|
|||||||
consumption.DateTime = request.DateTime.ToUniversalTime();
|
consumption.DateTime = request.DateTime.ToUniversalTime();
|
||||||
consumption.Distance = request.Distance;
|
consumption.Distance = request.Distance;
|
||||||
consumption.Amount = request.Amount;
|
consumption.Amount = request.Amount;
|
||||||
consumption.IgnoreInCalculation = request.IgnoreInCalculation;
|
|
||||||
|
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return TypedResults.Ok(new Response(consumption.Id.Value, consumption.DateTime, consumption.Distance, consumption.Amount, consumption.IgnoreInCalculation, consumption.CarId.Value));
|
return TypedResults.Ok(new Response(consumption.Id.Value, consumption.DateTime, consumption.Distance, consumption.Amount, consumption.CarId.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
117
src/Vegasco.Server.Api/Persistence/Migrations/20250622085121_DropIgnoreInCalculation.Designer.cs
generated
Normal file
117
src/Vegasco.Server.Api/Persistence/Migrations/20250622085121_DropIgnoreInCalculation.Designer.cs
generated
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using Vegasco.Server.Api.Persistence;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Vegasco.Server.Api.Persistence.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
|
[Migration("20250622085121_DropIgnoreInCalculation")]
|
||||||
|
partial class DropIgnoreInCalculation
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.5")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Cars.Car", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Cars");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Consumptions.Consumption", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<double>("Amount")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.Property<Guid>("CarId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("DateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<double>("Distance")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CarId");
|
||||||
|
|
||||||
|
b.ToTable("Consumptions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Users.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Cars.Car", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Vegasco.Server.Api.Users.User", "User")
|
||||||
|
.WithMany("Cars")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Consumptions.Consumption", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Vegasco.Server.Api.Cars.Car", "Car")
|
||||||
|
.WithMany("Consumptions")
|
||||||
|
.HasForeignKey("CarId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Car");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Cars.Car", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Consumptions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Vegasco.Server.Api.Users.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Cars");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Vegasco.Server.Api.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class DropIgnoreInCalculation : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IgnoreInCalculation",
|
||||||
|
table: "Consumptions");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IgnoreInCalculation",
|
||||||
|
table: "Consumptions",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
using Vegasco.Server.Api.Persistence;
|
using Vegasco.Server.Api.Persistence;
|
||||||
|
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace Vegasco.Server.Api.Persistence.Migrations
|
namespace Vegasco.Server.Api.Persistence.Migrations
|
||||||
@@ -18,7 +17,7 @@ namespace Vegasco.Server.Api.Persistence.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "8.0.8")
|
.HasAnnotation("ProductVersion", "9.0.5")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
@@ -61,9 +60,6 @@ namespace Vegasco.Server.Api.Persistence.Migrations
|
|||||||
b.Property<double>("Distance")
|
b.Property<double>("Distance")
|
||||||
.HasColumnType("double precision");
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
b.Property<bool>("IgnoreInCalculation")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CarId");
|
b.HasIndex("CarId");
|
||||||
|
|||||||
@@ -66,5 +66,20 @@ BEGIN
|
|||||||
VALUES ('20240818105918_Initial', '9.0.5');
|
VALUES ('20240818105918_Initial', '9.0.5');
|
||||||
END IF;
|
END IF;
|
||||||
END $EF$;
|
END $EF$;
|
||||||
|
|
||||||
|
DO $EF$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20250622085121_DropIgnoreInCalculation') THEN
|
||||||
|
ALTER TABLE "Consumptions" DROP COLUMN "IgnoreInCalculation";
|
||||||
|
END IF;
|
||||||
|
END $EF$;
|
||||||
|
|
||||||
|
DO $EF$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20250622085121_DropIgnoreInCalculation') THEN
|
||||||
|
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
|
||||||
|
VALUES ('20250622085121_DropIgnoreInCalculation', '9.0.5');
|
||||||
|
END IF;
|
||||||
|
END $EF$;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ internal class ConsumptionFaker
|
|||||||
_faker.Date.RecentOffset(),
|
_faker.Date.RecentOffset(),
|
||||||
_faker.Random.Int(1, 1_000),
|
_faker.Random.Int(1, 1_000),
|
||||||
_faker.Random.Int(20, 70),
|
_faker.Random.Int(20, 70),
|
||||||
_faker.Random.Bool(),
|
|
||||||
carId);
|
carId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ internal class ConsumptionFaker
|
|||||||
return new UpdateConsumption.Request(
|
return new UpdateConsumption.Request(
|
||||||
createRequest.DateTime,
|
createRequest.DateTime,
|
||||||
createRequest.Distance,
|
createRequest.Distance,
|
||||||
createRequest.Amount,
|
createRequest.Amount);
|
||||||
createRequest.IgnoreInCalculation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@ public class CreateConsumptionRequestValidatorTests
|
|||||||
_utcNow.AddDays(-1),
|
_utcNow.AddDays(-1),
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
false,
|
|
||||||
Guid.NewGuid());
|
Guid.NewGuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ public class UpdateConsumptionRequestValidatorTests
|
|||||||
_validRequest = new UpdateConsumption.Request(
|
_validRequest = new UpdateConsumption.Request(
|
||||||
_utcNow.AddDays(-1),
|
_utcNow.AddDays(-1),
|
||||||
1,
|
1,
|
||||||
1,
|
1);
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user