Skip to content

Commit

Permalink
Get foundItems route
Browse files Browse the repository at this point in the history
  • Loading branch information
Centerville1 committed Feb 7, 2025
1 parent 87f27e7 commit cc62b3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Gordon360/Controllers/LostAndFoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,14 @@ public ActionResult<string> CreateFoundItemReport([FromBody] FoundItemViewModel

return Ok(reportID);
}

[HttpGet]
[Route(("founditems/{itemID}"))]
public ActionResult<FoundItemViewModel> GetFoundItem(string itemID)
{
var authenticatedUserUsername = AuthUtils.GetUsername(User);

return Ok(lostAndFoundService.GetFoundItem(itemID, authenticatedUserUsername));
}
}
}
10 changes: 10 additions & 0 deletions Gordon360/Documentation/Gordon360.xml

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

35 changes: 35 additions & 0 deletions Gordon360/Services/LostAndFoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Gordon360.Models.CCT;
using Gordon360.Models.CCT.Context;
using Gordon360.Models.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Graph;
using Serilog;
using System;
Expand Down Expand Up @@ -565,5 +566,39 @@ public string CreateFoundItem(FoundItemViewModel FoundItemDetails, string userna

return reportID + (numReportsToday + 1);
}

/// <summary>
/// Gets a found item by ID, only allowed for admin users
/// </summary>
/// <param name="foundItemID">The ID of the found item</param>
/// <param name="username">The username of the person making the request</param>
/// <returns>A Found Item object</returns>
/// <exception cref="ResourceNotFoundException">If the report with given ID doesn't exist or the user
/// doesn't have permissions to read it</exception>
public FoundItemViewModel GetFoundItem(string foundItemID, string username)
{
if (!hasFullPermissions(username))
{
throw new ResourceNotFoundException();
}

FoundItemViewModel report;

var data = context.FoundItemData.FirstOrDefault(x => x.ID == foundItemID);
if (data != null)
{
report = (FoundItemViewModel)data;

// Get the list of all admin actions on this report, and add them to the report.
report.adminActions = context.FoundActionsTakenData.Where(x => x.foundID == foundItemID)
.Select(x => (FoundActionsTakenViewModel)x);
}
else
{
// If no such report exists
throw new ResourceNotFoundException();
}
return report;
}
}
}
1 change: 1 addition & 0 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ IEnumerable<MissingItemReportViewModel> GetMissingItemsAll(string username,
MissingItemReportViewModel? GetMissingItem(int id, string username);
IEnumerable<ActionsTakenViewModel> GetActionsTaken(int id, string username, bool getPublicOnly = false, bool elevatedPermissions = false);
public string CreateFoundItem(FoundItemViewModel reportDetails, string username);
public FoundItemViewModel GetFoundItem(string foundItemID, string username);
}


Expand Down

0 comments on commit cc62b3d

Please sign in to comment.