Skip to content

Commit

Permalink
[DMS-410] Implement paging for configuration service (#351)
Browse files Browse the repository at this point in the history
* Use limit offset query parameters for get all endpoints

* Add order by

* Paging parameters not required in latest AdminAPI
  • Loading branch information
simpat-adam authored Nov 20, 2024
1 parent 39c3afa commit 246a6c4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<ApplicationQueryResult> QueryApplication(PagingQuery query)
{
string sql = """
SELECT a.Id, a.ApplicationName, a.VendorId, a.ClaimSetName, e.EducationOrganizationId
FROM dmscs.Application a
FROM (SELECT * FROM dmscs.Application ORDER BY Id LIMIT @Limit OFFSET @Offset) AS a
LEFT OUTER JOIN dmscs.ApplicationEducationOrganization e ON a.Id = e.ApplicationId
ORDER BY a.ApplicationName;
""";
Expand All @@ -100,6 +100,7 @@ FROM dmscs.Application a
application.EducationOrganizationIds.Add(educationOrganizationId);
return application;
},
param: query,
splitOn: "EducationOrganizationId"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public async Task<VendorQueryResult> QueryVendor(PagingQuery query)
{
var sql = """
SELECT Id, Company, ContactName, ContactEmailAddress, NamespacePrefix
FROM dmscs.Vendor v LEFT OUTER JOIN dmscs.VendorNamespacePrefix p ON v.Id = p.VendorId;
FROM (SELECT * FROM dmscs.Vendor ORDER BY Id LIMIT @Limit OFFSET @Offset) AS v
LEFT OUTER JOIN dmscs.VendorNamespacePrefix p ON v.Id = p.VendorId;
""";
var vendors = await connection.QueryAsync<VendorResponse, string, VendorResponse>(
sql,
Expand All @@ -73,6 +74,7 @@ public async Task<VendorQueryResult> QueryVendor(PagingQuery query)
vendor.NamespacePrefixes = namespacePrefix;
return vendor;
},
param: query,
splitOn: "NamespacePrefix"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace EdFi.DmsConfigurationService.DataModel;

/// <summary>
/// Used in queries where paging is required.
/// Used in queries where paging is supported.
/// </summary>
public class PagingQuery
{
public int Offset { get; set; }
public int Limit { get; set; }
public int? Offset { get; set; } = 0;
public int? Limit { get; set; } = 25;
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public async Task Should_return_success_response()
)
);

var getResponse = await client.GetAsync("/v2/applications");
var getResponse = await client.GetAsync("/v2/applications?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/applications/1");
var updateResponse = await client.PutAsync(
"/v2/applications/1",
Expand Down Expand Up @@ -366,7 +366,7 @@ public async Task Should_return_internal_server_error_response()
"application/json"
)
);
var getResponse = await client.GetAsync("/v2/applications");
var getResponse = await client.GetAsync("/v2/applications?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/applications/1");
var updateResponse = await client.PutAsync(
"/v2/applications/1",
Expand Down Expand Up @@ -451,7 +451,7 @@ public async Task Should_return_internal_server_error_response()
)
);

var getResponse = await client.GetAsync("/v2/applications");
var getResponse = await client.GetAsync("/v2/applications?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/applications/1");
var updateResponse = await client.PostAsync(
"/v2/applications",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task Should_return_proper_success_responses()
"application/json"
)
);
var getResponse = await client.GetAsync("/v2/vendors");
var getResponse = await client.GetAsync("/v2/vendors?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/vendors/1");
var updateResponse = await client.PutAsync(
"/v2/vendors/1",
Expand Down Expand Up @@ -418,7 +418,7 @@ public async Task Should_return_internal_server_error_response()
"application/json"
)
);
var getResponse = await client.GetAsync("/v2/vendors");
var getResponse = await client.GetAsync("/v2/vendors?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/vendors/1");
var updateResponse = await client.PutAsync(
"/v2/vendors/1",
Expand Down Expand Up @@ -489,7 +489,7 @@ public async Task Should_return_internal_server_error_response()
"application/json"
)
);
var getResponse = await client.GetAsync("/v2/vendors");
var getResponse = await client.GetAsync("/v2/vendors?offset=0&limit=25");
var getByIdResponse = await client.GetAsync("/v2/vendors/1");
var updateResponse = await client.PutAsync(
"/v2/vendors/1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,11 @@ ILogger<ApplicationModule> logger

private static async Task<IResult> GetAll(
IApplicationRepository applicationRepository,
[AsParameters] PagingQuery query,
HttpContext httpContext
)
{
ApplicationQueryResult getResult = await applicationRepository.QueryApplication(
new PagingQuery() { Limit = 9999, Offset = 0 }
);
ApplicationQueryResult getResult = await applicationRepository.QueryApplication(query);
return getResult switch
{
ApplicationQueryResult.Success success => Results.Ok(success.ApplicationResponses),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ IVendorRepository repository
};
}

private static async Task<IResult> GetAll(IVendorRepository repository, HttpContext httpContext)
private static async Task<IResult> GetAll(
IVendorRepository repository,
[AsParameters] PagingQuery query,
HttpContext httpContext
)
{
VendorQueryResult getResult = await repository.QueryVendor(
new PagingQuery() { Limit = 9999, Offset = 0 }
);
VendorQueryResult getResult = await repository.QueryVendor(query);
return getResult switch
{
VendorQueryResult.Success success => Results.Ok(success.VendorResponses),
Expand Down

0 comments on commit 246a6c4

Please sign in to comment.