Skip to content

Commit

Permalink
Added report filters for colors, category, and keywords to API for ge…
Browse files Browse the repository at this point in the history
…tting all missing items
  • Loading branch information
Centerville1 committed Jan 29, 2025
1 parent 4a50a83 commit c18d1a4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
13 changes: 10 additions & 3 deletions Gordon360/Controllers/LostAndFoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,28 @@ public async Task<ActionResult> UpdateReportStatus(int missingItemId, string sta
/// <summary>
/// Get the list of missing item reports for the currently authenticated user.
/// </summary>
/// <param name="status">The selected status</param>
/// <param name="color">The selected color for filtering reports</param>
/// <param name="category">The selected category for filtering reports</param>
/// <param name="keywords">The selected keywords for filtering by keywords</param>
/// <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>
/// <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? user = null,
string? status = null,
string? color = null,
string? category = null,
string? keywords = null)
{
IEnumerable<MissingItemReportViewModel> result;
var authenticatedUserUsername = AuthUtils.GetUsername(User);

// If no username specified in the query, get all items
if (user == null)
{
result = lostAndFoundService.GetMissingItemsAll(authenticatedUserUsername, status);
result = lostAndFoundService.GetMissingItemsAll(authenticatedUserUsername, status, color, category, keywords);
}
else
{
Expand Down
11 changes: 8 additions & 3 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 @@ -300,11 +300,14 @@ public IEnumerable<MissingItemReportViewModel> GetMissingItems(string requestedU
/// Get all missing item reports
/// Throw unauthorized access exception if the user doesn't have admin permissions
/// </summary>
/// <param name="status">The selected status</param>
/// <param name="color">The selected color for filtering reports</param>
/// <param name="category">The selected category for filtering reports</param>
/// <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>
/// <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)
public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username, string? status, string? color, string? category, string? keywords)
{
if (!hasFullPermissions(username))
{
Expand All @@ -316,6 +319,21 @@ public IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string usernam
{
missingItems = missingItems.Where(x => x.status == status);
}
if (color is not null)
{
missingItems = missingItems.Where(x => x.colors.Contains(color));
}
if (category is not null)
{
missingItems = missingItems.Where(x => x.category == category);
}
if (keywords is not null)
{
missingItems = missingItems.Where(x => x.firstName.Contains(keywords)
|| x.lastName.Contains(keywords)
|| x.description.Contains(keywords)
|| x.locationLost.Contains(keywords));
}

// 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
3 changes: 2 additions & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using RecIMActivityViewModel = Gordon360.Models.ViewModels.RecIM.ActivityViewModel;
Expand Down Expand Up @@ -232,7 +233,7 @@ 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);
IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username, 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 c18d1a4

Please sign in to comment.