Skip to content

Commit

Permalink
wmr - Reworked GetResidentRA API route
Browse files Browse the repository at this point in the history
  • Loading branch information
jtasonye committed Nov 10, 2024
1 parent 2fd99f4 commit 25b5988
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Gordon360/Controllers/HousingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ public async Task<IActionResult> DeleteAssignment(int rangeId)
/// <param name="hallId">The ID of the hall.</param>
/// <param name="roomNumber">The resident's room number.</param>
/// <returns>Returns the RA's ID if found, otherwise null.</returns>
[HttpGet("GetResidentRA")]
public async Task<ActionResult<string>> GetResidentRA([FromQuery] string hallId, [FromQuery] string roomNumber)
[HttpGet("GetResidentRA/{hallId}/{roomNumber}")]
public async Task<ActionResult<string>> GetResidentRA(string hallId, string roomNumber)
{
try
{
Expand Down
13 changes: 12 additions & 1 deletion Gordon360/Services/HousingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,18 @@ public async Task<string> GetResidentRAAsync(string hallId, string roomNumber)
throw new InvalidOperationException("No RA assigned to this room range.");
}

return assignedRA;
// Use RA_ID to query RA_Assigned_Ranges_View for the RA’s name
var assignedRAName = await context.RA_Assigned_Ranges_View
.Where(raView => raView.RA_ID == assignedRA)
.Select(raView => raView.Fname + " " + raView.Lname)
.FirstOrDefaultAsync();

if (assignedRAName == null)
{
throw new InvalidOperationException("No RA name found for the RA ID.");
}

return assignedRAName;
}

/// <summary>
Expand Down

0 comments on commit 25b5988

Please sign in to comment.