Skip to content

Commit

Permalink
Added pagination features
Browse files Browse the repository at this point in the history
  • Loading branch information
Centerville1 committed Jan 29, 2025
1 parent c18d1a4 commit ebed1f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Gordon360/Controllers/LostAndFoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public async Task<ActionResult> UpdateReportStatus(int missingItemId, string sta
/// <param name="status">The selected status for filtering reports</param>
/// <param name="user">Query parameter, default is null and route will get all missing items, or if user is set
/// route will get missing items for the authenticated user</param>
/// <param name="lastId">The ID of the last fetched report to start from for pagination</param>
/// <param name="pageSize">The size of the page to fetch for pagination</param>
/// <returns>ObjectResult - an http status code, with an array of MissingItem objects in the body </returns>
[HttpGet]
[Route("missingitems")]
public ActionResult<IEnumerable<MissingItemReportViewModel>> GetMissingItems(string? user = null,
int? lastId = null,
int? pageSize = null,
string? status = null,
string? color = null,
string? category = null,
Expand All @@ -103,7 +107,7 @@ public ActionResult<IEnumerable<MissingItemReportViewModel>> GetMissingItems(str
// If no username specified in the query, get all items
if (user == null)
{
result = lostAndFoundService.GetMissingItemsAll(authenticatedUserUsername, status, color, category, keywords);
result = lostAndFoundService.GetMissingItemsAll(authenticatedUserUsername, lastId, pageSize, status, color, category, keywords);
}
else
{
Expand Down
15 changes: 10 additions & 5 deletions Gordon360/Documentation/Gordon360.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions Gordon360/Services/LostAndFoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,24 @@ public IEnumerable<MissingItemReportViewModel> GetMissingItems(string requestedU
/// <param name="keywords">The selected keywords for filtering by keywords</param>
/// <param name="status">The selected status for filtering reports</param>
/// <param name="username">The username of the person making the request</param>
/// <param name="lastId">The ID of the last fetched report to start from for pagination</param>
/// <param name="pageSize">The size of the page to fetch for pagination</param>
/// <returns>An enumerable of Missing Item Reports, from the Missing Item Data view</returns>
/// <exception cref="UnauthorizedAccessException">If a user without admin permissions attempts to use</exception>
public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username, string? status, string? color, string? category, string? keywords)
public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username,
int? lastId,
int? pageSize,
string? status,
string? color,
string? category,
string? keywords)
{
if (!hasFullPermissions(username))
{
throw new UnauthorizedAccessException();
}

IQueryable<MissingItemData> missingItems = context.MissingItemData;
IQueryable<MissingItemData> missingItems = context.MissingItemData.OrderBy(item => item.ID);
if (status is not null)
{
missingItems = missingItems.Where(x => x.status == status);
Expand All @@ -331,9 +339,19 @@ public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string usernam
{
missingItems = missingItems.Where(x => x.firstName.Contains(keywords)
|| x.lastName.Contains(keywords)
|| (x.firstName + " " + x.lastName).Contains(keywords)
|| x.description.Contains(keywords)
|| x.locationLost.Contains(keywords));
}
if (lastId is not null)
{
missingItems = missingItems.Where(item => item.ID > lastId);
}
if (pageSize is not null)
{
int pageLength = pageSize ?? default(int);
missingItems = missingItems.Take(pageLength);
}

// Perform a group join to create a MissingItemReportViewModel with actions taken data for each report
// Only performs a single SQL query to the db, so much more performant than alternative solutions
Expand Down
8 changes: 7 additions & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ public interface ILostAndFoundService
public int CreateMissingItemReport(MissingItemReportViewModel reportDetails, string username);
public int CreateActionTaken(int id, ActionsTakenViewModel ActionsTaken, string username);
IEnumerable<MissingItemReportViewModel> GetMissingItems(string requestedUsername, string requestorUsername);
IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username, string? status, string? color, string? category, string? keywords);
IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username,
int? lastId,
int? pageSize,
string? status,
string? color,
string? category,
string? keywords);
Task UpdateMissingItemReportAsync(int id, MissingItemReportViewModel reportDetails, string username);
Task UpdateReportStatusAsync(int id, string status, string username);
MissingItemReportViewModel? GetMissingItem(int id, string username);
Expand Down

0 comments on commit ebed1f5

Please sign in to comment.