Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup: Remove DTO PR #348

Merged
merged 8 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Geopilot.Api/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public IQueryable<Mandate> MandatesWithIncludes
.Include(m => m.Organisations)
.ThenInclude(o => o.Users)
.Include(m => m.Deliveries)
.ThenInclude(d => d.DeclaringUser)
.Include(m => m.Deliveries)
.ThenInclude(d => d.Assets);
}
}
Expand All @@ -104,5 +106,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
ArgumentNullException.ThrowIfNull(modelBuilder);

modelBuilder.Entity<Delivery>().HasQueryFilter(d => !d.Deleted);
modelBuilder.Entity<Asset>()
.HasQueryFilter(a => !a.Delivery.Deleted)
.HasQueryFilter(a => !a.Deleted);
}
}
2 changes: 2 additions & 0 deletions src/Geopilot.Api/ContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ public static void SeedMandates(this Context context)
var knownFileFormats = new string[] { ".xtf", ".gpkg", ".*", ".itf", ".xml", ".zip", ".csv" };
var mandateFaker = new Faker<Mandate>()
.UseDateTimeReference(referenceDateTime)
.StrictMode(true)
.RuleFor(o => o.Id, f => 0)
.RuleFor(o => o.Name, f => f.Commerce.ProductName())
.RuleFor(o => o.FileTypes, f => f.PickRandom(knownFileFormats, 4).Distinct().ToArray())
.RuleFor(o => o.SpatialExtent, f => GetExtent())
.Ignore(o => o.Coordinates)
.RuleFor(o => o.Organisations, f => f.PickRandom(context.Organisations.ToList(), 1).ToList())
.RuleFor(o => o.Deliveries, _ => new List<Delivery>());

Expand Down
2 changes: 1 addition & 1 deletion src/Geopilot.Api/Models/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Asset
/// <summary>
/// Backreference to the delivery the asset belongs to.
/// </summary>
public Delivery? Delivery { get; set; } = new Delivery();
public Delivery Delivery { get; set; } = null!;
tschumpr marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The deletion status of the asset.
Expand Down
4 changes: 2 additions & 2 deletions src/Geopilot.Api/Models/Delivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public class Delivery
/// <summary>
/// The user that declared the delivery.
/// </summary>
public User DeclaringUser { get; set; } = new User();
public User DeclaringUser { get; set; } = null!;

/// <summary>
/// The mandate the delivery fulfills.
/// </summary>
public Mandate? Mandate { get; set; } = new Mandate();
public Mandate Mandate { get; set; } = null!;

/// <summary>
/// Assets delivered or created by the validation and delivery process.
Expand Down
1 change: 1 addition & 0 deletions src/Geopilot.Frontend/src/pages/admin/mandates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Mandates = () => {
}, [fetchApi]);

async function saveMandate(mandate: Mandate) {
mandate.deliveries = [];
tschumpr marked this conversation as resolved.
Show resolved Hide resolved
mandate.organisations = mandate.organisations?.map(value =>
typeof value === "number"
? ({ id: value } as Organisation)
Expand Down
4 changes: 2 additions & 2 deletions tests/Geopilot.Api.Test/Controllers/DeliveryControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task Create(bool setOptionals)
public void Delete()
{
var guid = Guid.NewGuid();
var delivery = new Delivery { JobId = guid };
var delivery = new Delivery { JobId = guid, Mandate = context.Mandates.First(), DeclaringUser = context.Users.First() };
delivery.Assets.Add(new Asset());
context.Deliveries.Add(delivery);
context.SaveChanges();
Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task Download()
{
assetHandlerMock.Setup(p => p.DownloadAssetAsync(It.IsAny<Guid>(), It.IsAny<string>())).ReturnsAsync((Encoding.UTF8.GetBytes("Test"), "text/xml"));
var guid = Guid.NewGuid();
var delivery = new Delivery { JobId = guid };
var delivery = new Delivery { JobId = guid, Mandate = context.Mandates.First(), DeclaringUser = context.Users.First() };
delivery.Assets.Add(new Asset() { OriginalFilename = "Test.xml", SanitizedFilename = "xyz.xml" });
context.Deliveries.Add(delivery);
context.SaveChanges();
Expand Down
Loading