diff --git a/backend/Api/DBAccess/DBAccess.cs b/backend/Api/DBAccess/DBAccess.cs
index 3e9dd6a..39f5068 100644
--- a/backend/Api/DBAccess/DBAccess.cs
+++ b/backend/Api/DBAccess/DBAccess.cs
@@ -315,11 +315,7 @@ namespace Api.DBAccess
///
public async Task> ReadLogs(int deviceId, DateTimeRange range)
{
- return _context.TemperatureLogs
- .Where(log => log.DeviceId == deviceId)
- .Where(log => log.Date > range.DateTimeStart)
- .Where(log => log.Date < range.DateTimeEnd)
- .ToList();
+ return _context.Devices.Include(d => d.Logs.Where(l => l.Date > range.DateTimeStart && l.Date < range.DateTimeEnd)).Where(d => d.Id == deviceId).FirstOrDefault().Logs;
}
///
diff --git a/backend/Api/DBAccess/DBContext.cs b/backend/Api/DBAccess/DBContext.cs
index df6600e..993a779 100644
--- a/backend/Api/DBAccess/DBContext.cs
+++ b/backend/Api/DBAccess/DBContext.cs
@@ -11,8 +11,6 @@ namespace Api
public DbSet Devices { get; set; }
- public DbSet TemperatureLogs { get; set; }
-
public DBContext(DbContextOptions options) : base(options) { }
}
}
diff --git a/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.Designer.cs b/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.Designer.cs
new file mode 100644
index 0000000..90225f9
--- /dev/null
+++ b/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.Designer.cs
@@ -0,0 +1,138 @@
+//
+using System;
+using Api;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Api.Migrations
+{
+ [DbContext(typeof(DBContext))]
+ [Migration("20250403070932_RemovedLogsFromDbset")]
+ partial class RemovedLogsFromDbset
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
+
+ modelBuilder.Entity("Api.Models.Devices.Device", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("ReferenceId")
+ .HasColumnType("TEXT");
+
+ b.Property("TempHigh")
+ .HasColumnType("REAL");
+
+ b.Property("TempLow")
+ .HasColumnType("REAL");
+
+ b.Property("UserId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Devices");
+ });
+
+ modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Date")
+ .HasColumnType("TEXT");
+
+ b.Property("DeviceId")
+ .HasColumnType("INTEGER");
+
+ b.Property("TempHigh")
+ .HasColumnType("REAL");
+
+ b.Property("TempLow")
+ .HasColumnType("REAL");
+
+ b.Property("Temperature")
+ .HasColumnType("REAL");
+
+ b.HasKey("Id");
+
+ b.HasIndex("DeviceId");
+
+ b.ToTable("TemperatureLogs");
+ });
+
+ modelBuilder.Entity("Api.Models.Users.User", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("RefreshToken")
+ .HasColumnType("TEXT");
+
+ b.Property("RefreshTokenExpiresAt")
+ .HasColumnType("TEXT");
+
+ b.Property("Salt")
+ .HasColumnType("TEXT");
+
+ b.Property("UserName")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("Api.Models.Devices.Device", b =>
+ {
+ b.HasOne("Api.Models.Users.User", null)
+ .WithMany("Devices")
+ .HasForeignKey("UserId");
+ });
+
+ modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
+ {
+ b.HasOne("Api.Models.Devices.Device", null)
+ .WithMany("Logs")
+ .HasForeignKey("DeviceId");
+ });
+
+ modelBuilder.Entity("Api.Models.Devices.Device", b =>
+ {
+ b.Navigation("Logs");
+ });
+
+ modelBuilder.Entity("Api.Models.Users.User", b =>
+ {
+ b.Navigation("Devices");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.cs b/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.cs
new file mode 100644
index 0000000..17c98c1
--- /dev/null
+++ b/backend/Api/Migrations/20250403070932_RemovedLogsFromDbset.cs
@@ -0,0 +1,59 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Api.Migrations
+{
+ ///
+ public partial class RemovedLogsFromDbset : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_TemperatureLogs_Devices_DeviceId",
+ table: "TemperatureLogs");
+
+ migrationBuilder.AlterColumn(
+ name: "DeviceId",
+ table: "TemperatureLogs",
+ type: "INTEGER",
+ nullable: true,
+ oldClrType: typeof(int),
+ oldType: "INTEGER");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_TemperatureLogs_Devices_DeviceId",
+ table: "TemperatureLogs",
+ column: "DeviceId",
+ principalTable: "Devices",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_TemperatureLogs_Devices_DeviceId",
+ table: "TemperatureLogs");
+
+ migrationBuilder.AlterColumn(
+ name: "DeviceId",
+ table: "TemperatureLogs",
+ type: "INTEGER",
+ nullable: false,
+ defaultValue: 0,
+ oldClrType: typeof(int),
+ oldType: "INTEGER",
+ oldNullable: true);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_TemperatureLogs_Devices_DeviceId",
+ table: "TemperatureLogs",
+ column: "DeviceId",
+ principalTable: "Devices",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}
diff --git a/backend/Api/Migrations/DBContextModelSnapshot.cs b/backend/Api/Migrations/DBContextModelSnapshot.cs
index ebab47a..f48f59b 100644
--- a/backend/Api/Migrations/DBContextModelSnapshot.cs
+++ b/backend/Api/Migrations/DBContextModelSnapshot.cs
@@ -55,7 +55,7 @@ namespace Api.Migrations
b.Property("Date")
.HasColumnType("TEXT");
- b.Property("DeviceId")
+ b.Property("DeviceId")
.HasColumnType("INTEGER");
b.Property("TempHigh")
@@ -117,9 +117,7 @@ namespace Api.Migrations
{
b.HasOne("Api.Models.Devices.Device", null)
.WithMany("Logs")
- .HasForeignKey("DeviceId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
+ .HasForeignKey("DeviceId");
});
modelBuilder.Entity("Api.Models.Devices.Device", b =>
diff --git a/backend/Api/Models/TemperatureLogs.cs b/backend/Api/Models/TemperatureLogs.cs
index 9216987..16911a2 100644
--- a/backend/Api/Models/TemperatureLogs.cs
+++ b/backend/Api/Models/TemperatureLogs.cs
@@ -4,8 +4,6 @@
{
public int Id { get; set; }
- public int DeviceId { get; set; }
-
public double Temperature { get; set; }
public DateTime Date { get; set; }
diff --git a/docs/Domainmodel.png b/docs/Domainmodel.png
new file mode 100644
index 0000000..2dec779
Binary files /dev/null and b/docs/Domainmodel.png differ
diff --git a/docs/TempAlarmModelDiagram.png b/docs/TempAlarmModelDiagram.png
index f607443..af323e5 100644
Binary files a/docs/TempAlarmModelDiagram.png and b/docs/TempAlarmModelDiagram.png differ