Skip to content

Commit d73e7f7

Browse files
CopilotLeftofZen
andauthored
Migrate missing objects from ObjectAvailability enum to dedicated TblObjectMissing table (#225)
* Initial plan * Add TblObjectMissing table and update ObjectMissingRouteHandler Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com> * Update ObjectRouteHandler and tests to use TblObjectMissing Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com> * rename tables * implement missing parts --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: LeftofZen <7483209+LeftofZen@users.noreply.github.com> Co-authored-by: Benjamin Sutas <benjamin.sutas@gmail.com>
1 parent 7fdcdd4 commit d73e7f7

18 files changed

Lines changed: 3178 additions & 284 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Definitions.DTO.Comparers;
4+
5+
public class DtoObjectMissingEntryComparer : IEqualityComparer<DtoObjectMissingEntry>
6+
{
7+
public bool Equals(DtoObjectMissingEntry? x, DtoObjectMissingEntry? y)
8+
{
9+
if (x is null || y is null)
10+
{
11+
return false;
12+
}
13+
14+
return
15+
x.Id == y.Id
16+
&& x.DatName == y.DatName
17+
&& x.DatChecksum == y.DatChecksum
18+
&& x.ObjectType == y.ObjectType;
19+
}
20+
21+
public int GetHashCode([DisallowNull] DtoObjectMissingEntry obj)
22+
=> HashCode.Combine(obj.Id, obj.DatName, obj.DatChecksum, obj.ObjectType);
23+
}

Definitions/DTO/Comparers/DtoMissingObjectEntryComparer.cs renamed to Definitions/DTO/Comparers/DtoObjectMissingUploadComparer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
namespace Definitions.DTO.Comparers;
44

5-
public class DtoMissingObjectEntryComparer : IEqualityComparer<DtoMissingObjectEntry>
5+
public class DtoObjectMissingUploadComparer : IEqualityComparer<DtoObjectMissingUpload>
66
{
7-
public bool Equals(DtoMissingObjectEntry? x, DtoMissingObjectEntry? y)
7+
public bool Equals(DtoObjectMissingUpload? x, DtoObjectMissingUpload? y)
88
{
99
if (x is null || y is null)
1010
{
1111
return false;
1212
}
1313

14-
return x.DatName == y.DatName
14+
return
15+
x.DatName == y.DatName
1516
&& x.DatChecksum == y.DatChecksum
1617
&& x.ObjectType == y.ObjectType;
1718
}
1819

19-
public int GetHashCode([DisallowNull] DtoMissingObjectEntry obj)
20+
public int GetHashCode([DisallowNull] DtoObjectMissingUpload obj)
2021
=> HashCode.Combine(obj.DatName, obj.DatChecksum, obj.ObjectType);
2122
}

Definitions/DTO/DtoDatObjectEntry.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace Definitions.DTO;
22

3-
43
public record DtoDatObjectEntry(
54
UniqueObjectId Id,
65
string DatName,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Definitions.ObjectModels.Types;
2+
3+
namespace Definitions.DTO;
4+
5+
public record DtoObjectMissingEntry(
6+
UniqueObjectId Id,
7+
string DatName,
8+
uint32_t DatChecksum,
9+
ObjectType ObjectType) : IHasId;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Definitions.DTO;
44

5-
public record DtoMissingObjectEntry(
5+
public record DtoObjectMissingUpload(
66
string DatName,
77
uint32_t DatChecksum,
88
ObjectType ObjectType);

Definitions/DTO/Mappers/DtoExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public static DtoObjectEntry ToDtoEntry(this TblObject table)
100100
public static TblObject ToTable(this DtoObjectEntry dto)
101101
=> new() { Id = dto.Id, Name = dto.InternalName, Description = dto.Description, ObjectSource = dto.ObjectSource, ObjectType = dto.ObjectType, VehicleType = dto.VehicleType, CreatedDate = dto.CreatedDate, ModifiedDate = dto.ModifiedDate, UploadedDate = dto.UploadedDate };
102102

103+
public static DtoObjectMissingEntry ToDtoEntry(this TblObjectMissing table)
104+
=> new(table.Id, table.DatName, table.DatChecksum, table.ObjectType);
105+
106+
public static TblObjectMissing ToTable(this DtoObjectMissingEntry dto)
107+
=> new() { Id = dto.Id, DatName = dto.DatName, DatChecksum = dto.DatChecksum, ObjectType = dto.ObjectType };
108+
103109
public static DtoScenarioEntry ToDtoEntry(this TblSC5File table)
104110
=> new(table.Id, table.Name);
105111

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Definitions.ObjectModels.Types;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace Definitions.Database;
5+
6+
[Index(nameof(DatName), nameof(DatChecksum), IsUnique = true)]
7+
public class TblObjectMissing : DbIdObject
8+
{
9+
public required string DatName { get; set; }
10+
11+
public required uint DatChecksum { get; set; }
12+
13+
public required ObjectType ObjectType { get; set; }
14+
}

Definitions/Database/LocoDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class LocoDbContext : IdentityDbContext<TblUser, TblUserRole, UniqueObjec
1818
public DbSet<TblObject> Objects => Set<TblObject>();
1919
public DbSet<TblStringTableRow> StringTable => Set<TblStringTableRow>();
2020
public DbSet<TblDatObject> DatObjects => Set<TblDatObject>();
21+
public DbSet<TblObjectMissing> ObjectsMissing => Set<TblObjectMissing>();
2122

2223
#region Objects
2324

0 commit comments

Comments
 (0)