Skip to content

Commit

Permalink
Filtering working
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke-W-Hart committed Jan 27, 2025
1 parent 5251e71 commit 6c7fac3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gordon360/Controllers/LostAndFoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task<ActionResult> UpdateReportStatus(int missingItemId, string sta
/// <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 status, string? user = null)
public ActionResult<IEnumerable<MissingItemReportViewModel>> GetMissingItems(string? status, string? user = null)
{
IEnumerable<MissingItemReportViewModel> result;
var authenticatedUserUsername = AuthUtils.GetUsername(User);
Expand Down
3 changes: 2 additions & 1 deletion Gordon360/Documentation/Gordon360.xml

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

19 changes: 16 additions & 3 deletions Gordon360/Services/LostAndFoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,26 @@ public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string usernam
throw new UnauthorizedAccessException();
}

// 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
return context.MissingItemData
// If status is null do not perform where
if (status == null)
{
return context.MissingItemData
.GroupJoin(context.ActionsTakenData,
missingItem => missingItem.ID,
action => action.missingID,
(missingItem, action) => MissingItemReportViewModel.From(missingItem, action));
}
else
{
// 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
return context.MissingItemData.Where(x => x.status == status)
.GroupJoin(context.ActionsTakenData,
missingItem => missingItem.ID,
action => action.missingID,
(missingItem, action) => MissingItemReportViewModel.From(missingItem, action));
}

}

/// <summary>
Expand Down

0 comments on commit 6c7fac3

Please sign in to comment.