Initial Commit

This commit is contained in:
Denis Urs Rudolph
2025-12-11 21:38:33 +01:00
commit 3d4dec79a9
19 changed files with 1121 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace OtaFleet.Api.Data.Entities;
public class Deployment
{
public int Id { get; set; }
public int UpdateId { get; set; }
[ForeignKey("UpdateId")]
public FirmwareUpdate Update { get; set; } = null!;
public string? TargetVin { get; set; }
public int? TargetGroupId { get; set; }
public string Status { get; set; } = "Pending"; // Pending, InProgress, Completed, Failed
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace OtaFleet.Api.Data.Entities;
public class FirmwareUpdate
{
public int Id { get; set; }
[Required]
public string Version { get; set; } = string.Empty;
public string? Description { get; set; }
[Required]
public string FilePath { get; set; } = string.Empty;
public DateTime UploadedAt { get; set; } = DateTime.UtcNow;
}

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace OtaFleet.Api.Data.Entities;
public class Vehicle
{
[Key]
public string Vin { get; set; } = string.Empty;
public string Status { get; set; } = "Offline"; // Online, Offline, Updating
public string CurrentVersion { get; set; } = "1.0.0";
public DateTime LastHeartbeat { get; set; }
public int? GroupId { get; set; }
[ForeignKey("GroupId")]
public VehicleGroup? Group { get; set; }
}

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace OtaFleet.Api.Data.Entities;
public class VehicleGroup
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public List<Vehicle> Vehicles { get; set; } = new();
}

View File

@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using OtaFleet.Api.Data.Entities;
namespace OtaFleet.Api.Data;
public class OtaDbContext : DbContext
{
public OtaDbContext(DbContextOptions<OtaDbContext> options) : base(options) { }
public DbSet<Vehicle> Vehicles => Set<Vehicle>();
public DbSet<VehicleGroup> VehicleGroups => Set<VehicleGroup>();
public DbSet<FirmwareUpdate> FirmwareUpdates => Set<FirmwareUpdate>();
public DbSet<Deployment> Deployments => Set<Deployment>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Vehicle>()
.HasOne(v => v.Group)
.WithMany(g => g.Vehicles)
.HasForeignKey(v => v.GroupId)
.OnDelete(DeleteBehavior.SetNull);
}
}