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

DP-603: Explicitly configure single query behaviour in organisation queries #822

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void Dispose()
return await context.Organisations
.Include(p => p.Addresses)
.ThenInclude(p => p.Address)
.AsSingleQuery()
.FirstOrDefaultAsync(t => t.Guid == organisationId);
}

Expand All @@ -23,13 +24,15 @@ public void Dispose()
return await context.Organisations
.Include(p => p.Addresses)
.ThenInclude(p => p.Address)
.AsSingleQuery()
.FirstOrDefaultAsync(t => t.Name == name);
}
public async Task<IEnumerable<OrganisationPerson>> FindOrganisationPersons(Guid organisationId)
{
return await context.Set<OrganisationPerson>()
.Include(op => op.Person)
.Where(op => op.Organisation.Guid == organisationId)
.AsSingleQuery()
.ToListAsync();
}

Expand All @@ -51,6 +54,7 @@ public async Task<IEnumerable<Organisation>> FindByUserUrn(string userUrn)
.Include(p => p.Organisations)
.ThenInclude(p => p.Addresses)
.ThenInclude(p => p.Address)
.AsSingleQuery()
.FirstOrDefaultAsync(p => p.UserUrn == userUrn);
return person?.Organisations ?? [];
}
Expand All @@ -61,6 +65,7 @@ public async Task<IEnumerable<Organisation>> FindByUserUrn(string userUrn)
.Include(p => p.Identifiers)
.Include(p => p.Addresses)
.ThenInclude(p => p.Address)
.AsSingleQuery()
.FirstOrDefaultAsync(o => o.Identifiers.Any(i => i.Scheme == scheme && i.IdentifierId == identifierId));
}

Expand All @@ -84,7 +89,7 @@ public async Task<IList<Organisation>> Get(string? type)
break;
}

return await result.ToListAsync();
return await result.AsSingleQuery().ToListAsync();
}

public async Task<IList<ConnectedEntity>> GetConnectedIndividualTrusts(int organisationId)
Expand All @@ -94,7 +99,7 @@ public async Task<IList<ConnectedEntity>> GetConnectedIndividualTrusts(int organ
.Where(x => x.IndividualOrTrust != null && x.EntityType == ConnectedEntity.ConnectedEntityType.Individual)
.Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId);

return await result.ToListAsync();
return await result.AsSingleQuery().ToListAsync();
}

public async Task<IList<ConnectedEntity>> GetConnectedOrganisations(int organisationId)
Expand All @@ -104,7 +109,7 @@ public async Task<IList<ConnectedEntity>> GetConnectedOrganisations(int organisa
.Where(x => x.Organisation != null && x.EntityType == ConnectedEntity.ConnectedEntityType.Organisation)
.Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId);

return await result.ToListAsync();
return await result.AsSingleQuery().ToListAsync();
}

public async Task<IList<ConnectedEntity>> GetConnectedTrustsOrTrustees(int organisationId)
Expand All @@ -114,7 +119,7 @@ public async Task<IList<ConnectedEntity>> GetConnectedTrustsOrTrustees(int organ
.Where(x => x.IndividualOrTrust != null && x.EntityType == ConnectedEntity.ConnectedEntityType.TrustOrTrustee)
.Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId);

return await result.ToListAsync();
return await result.AsSingleQuery().ToListAsync();
}

public async Task<Organisation.LegalForm?> GetLegalForm(int organisationId)
Expand All @@ -134,6 +139,7 @@ public async Task<IList<OperationType>> GetOperationTypes(int organisationId)
var organisation = await context.Organisations
.Where(x => x.Id == organisationId)
.Include(x => x.SupplierInfo)
.AsSingleQuery()
.FirstOrDefaultAsync();

return organisation?.SupplierInfo?.OperationTypes ?? [];
Expand Down