Initial Commit
This commit is contained in:
21
OtaFleet.Api/Data/Entities/Deployment.cs
Normal file
21
OtaFleet.Api/Data/Entities/Deployment.cs
Normal 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;
|
||||
}
|
||||
18
OtaFleet.Api/Data/Entities/FirmwareUpdate.cs
Normal file
18
OtaFleet.Api/Data/Entities/FirmwareUpdate.cs
Normal 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;
|
||||
}
|
||||
21
OtaFleet.Api/Data/Entities/Vehicle.cs
Normal file
21
OtaFleet.Api/Data/Entities/Vehicle.cs
Normal 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; }
|
||||
}
|
||||
15
OtaFleet.Api/Data/Entities/VehicleGroup.cs
Normal file
15
OtaFleet.Api/Data/Entities/VehicleGroup.cs
Normal 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();
|
||||
}
|
||||
25
OtaFleet.Api/Data/OtaDbContext.cs
Normal file
25
OtaFleet.Api/Data/OtaDbContext.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user