2024-08-17 16:38:40 +02:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
2025-06-12 18:22:37 +02:00
|
|
|
|
using Vegasco.Server.Api.Consumptions;
|
|
|
|
|
|
using Vegasco.Server.Api.Users;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
2025-06-12 18:22:37 +02:00
|
|
|
|
namespace Vegasco.Server.Api.Cars;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
|
|
|
|
|
public class Car
|
|
|
|
|
|
{
|
2024-08-17 18:00:23 +02:00
|
|
|
|
public CarId Id { get; set; } = CarId.New();
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; } = "";
|
|
|
|
|
|
|
2024-08-17 16:38:40 +02:00
|
|
|
|
public string UserId { get; set; } = "";
|
|
|
|
|
|
|
|
|
|
|
|
public virtual User User { get; set; } = null!;
|
2024-08-17 18:00:23 +02:00
|
|
|
|
|
|
|
|
|
|
public virtual ICollection<Consumption> Consumptions { get; set; } = [];
|
2024-08-17 16:38:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class CarTableConfiguration : IEntityTypeConfiguration<Car>
|
|
|
|
|
|
{
|
|
|
|
|
|
public const int NameMaxLength = 50;
|
|
|
|
|
|
|
|
|
|
|
|
public void Configure(EntityTypeBuilder<Car> builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
builder.HasKey(x => x.Id);
|
|
|
|
|
|
|
2024-08-17 18:00:23 +02:00
|
|
|
|
builder.Property(x => x.Id)
|
|
|
|
|
|
.HasConversion<CarId.EfCoreValueConverter>();
|
|
|
|
|
|
|
2024-08-17 16:38:40 +02:00
|
|
|
|
builder.Property(x => x.Name)
|
|
|
|
|
|
.IsRequired()
|
|
|
|
|
|
.HasMaxLength(NameMaxLength);
|
|
|
|
|
|
|
|
|
|
|
|
builder.Property(x => x.UserId)
|
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
|
|
builder.HasOne(x => x.User)
|
|
|
|
|
|
.WithMany(x => x.Cars);
|
|
|
|
|
|
}
|
2024-08-17 16:38:40 +02:00
|
|
|
|
}
|