diff --git a/Gordon360/Controllers/LostAndFoundController.cs b/Gordon360/Controllers/LostAndFoundController.cs index 171c4dda7..f54170952 100644 --- a/Gordon360/Controllers/LostAndFoundController.cs +++ b/Gordon360/Controllers/LostAndFoundController.cs @@ -82,13 +82,20 @@ public async Task UpdateReportStatus(int missingItemId, string sta /// /// Get the list of missing item reports for the currently authenticated user. /// - /// The selected status + /// The selected color for filtering reports + /// The selected category for filtering reports + /// The selected keywords for filtering by keywords + /// The selected status for filtering reports /// 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 /// ObjectResult - an http status code, with an array of MissingItem objects in the body [HttpGet] [Route("missingitems")] - public ActionResult> GetMissingItems(string? status, string? user = null) + public ActionResult> GetMissingItems(string? user = null, + string? status = null, + string? color = null, + string? category = null, + string? keywords = null) { IEnumerable result; var authenticatedUserUsername = AuthUtils.GetUsername(User); @@ -96,7 +103,7 @@ public ActionResult> GetMissingItems(str // 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 { diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 2f905006f..345149d28 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -324,11 +324,14 @@ ObjectResult - the http status code result of the action - + Get the list of missing item reports for the currently authenticated user. - The selected status + The selected color for filtering reports + The selected category for filtering reports + The selected keywords for filtering by keywords + The selected status for filtering reports 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 ObjectResult - an http status code, with an array of MissingItem objects in the body @@ -1959,11 +1962,13 @@ an Enumerable of Missing Item Reports containing all missing item reports If a user requests reports they are not permitted to access - + Get all missing item reports Throw unauthorized access exception if the user doesn't have admin permissions + + The selected status The username of the person making the request An enumerable of Missing Item Reports, from the Missing Item Data view diff --git a/Gordon360/Services/LostAndFoundService.cs b/Gordon360/Services/LostAndFoundService.cs index 9bfa303e6..a6af0d65c 100644 --- a/Gordon360/Services/LostAndFoundService.cs +++ b/Gordon360/Services/LostAndFoundService.cs @@ -300,11 +300,14 @@ public IEnumerable GetMissingItems(string requestedU /// Get all missing item reports /// Throw unauthorized access exception if the user doesn't have admin permissions /// - /// The selected status + /// The selected color for filtering reports + /// The selected category for filtering reports + /// The selected keywords for filtering by keywords + /// The selected status for filtering reports /// The username of the person making the request /// An enumerable of Missing Item Reports, from the Missing Item Data view /// If a user without admin permissions attempts to use - public IEnumerable GetMissingItemsAll(string username, string status) + public IEnumerable GetMissingItemsAll(string username, string? status, string? color, string? category, string? keywords) { if (!hasFullPermissions(username)) { @@ -316,6 +319,21 @@ public IEnumerable 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 diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index ce6af5ffa..fcf7ca33c 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -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; @@ -232,7 +233,7 @@ public interface ILostAndFoundService public int CreateMissingItemReport(MissingItemReportViewModel reportDetails, string username); public int CreateActionTaken(int id, ActionsTakenViewModel ActionsTaken, string username); IEnumerable GetMissingItems(string requestedUsername, string requestorUsername); - IEnumerable GetMissingItemsAll(string username, string status); + IEnumerable 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);