Skip to content

Commit

Permalink
Merge pull request #1094 from RossClark01/RA_Pref_Contact_API
Browse files Browse the repository at this point in the history
API for setting and getting the pref contact for an RA
  • Loading branch information
jtasonye authored Nov 14, 2024
2 parents b5a74bb + e8093a5 commit b4fe9b0
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 108 deletions.
166 changes: 113 additions & 53 deletions Gordon360/Controllers/HousingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,81 +454,141 @@ public async Task<IActionResult> GetRangeAssignments()
}
}

/// <summary>
/// Checks an RA in
/// </summary>
/// <param name="checkin">The viewmodel object of the RA checking in</param>
/// <returns>true if ra checked in succesfully</returns>
[HttpPost("ra-checkin")]
public async Task<ActionResult<bool>> RA_Checkin([FromBody] RA_On_CallViewModel RAcheckin)
/// <summary>
/// Sets or updates an RA's preferred contact method
/// </summary>
/// <param name="raId">The ID of the RA</param>
/// <param name="preferredContactMethod">The contact method (e.g., "Phone", "Teams")</param>
/// <returns>True if the contact method was successfully set</returns>
[HttpPost("set-preferred-contact")]
public async Task<IActionResult> SetPreferredContact([FromQuery] string raId, [FromQuery] string preferredContactMethod)
{
if (string.IsNullOrWhiteSpace(raId) || string.IsNullOrWhiteSpace(preferredContactMethod))
{
try
{
var checkedIn = await housingService.RA_CheckinAsync(RAcheckin);
if (checkedIn)
{
return Created("RA checked in successfully.", checkedIn);
}
return BadRequest("Failed to check in RA.");
}
catch (InvalidOperationException ex)
return BadRequest("RA ID and contact method are required.");
}

try
{
var result = await housingService.SetPreferredContactMethodAsync(raId, preferredContactMethod);
if (result)
{
return BadRequest(ex.Message);
return Ok("Preferred contact method set successfully.");
}
catch (Exception ex)
else
{
return StatusCode(500, $"Internal server error: {ex.Message}");
return StatusCode(500, "An error occurred while setting the preferred contact method.");
}
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}

/// <summary>
/// Gets the ID of the on-call RA for a specified hall.
/// </summary>
/// <param name="Hall_ID">The ID of the hall</param>
/// <returns>The ID of the on-call RA, or a 404 if no RA is on call</returns>
[HttpGet("on-call-ra/{Hall_ID}")]
public async Task<ActionResult<string>> GetOnCallRA(string Hall_ID)
/// <summary>
/// Retrieves the preferred contact information for an RA based on their contact preference.
/// If the RA has a contact preference set, it will return either their phone number or a Microsoft Teams link
/// with their email embedded. If no preference exists, the method defaults to returning the RA's phone number.
/// </summary>
/// <param name="raId">The ID of the RA whose contact information is being requested.</param>
/// <returns>A string containing the preferred contact information (phone number or Teams link) or a default
/// phone number if no preference is set.</returns>
[HttpGet("ra-contact/{raId}")]
public async Task<ActionResult<string>> GetRAContact(string raId)
{
try
{
try
var contactInfo = await housingService.GetPreferredContactAsync(raId);

if (string.IsNullOrEmpty(contactInfo))
{
var raId = await housingService.GetOnCallRAAsync(Hall_ID);
return NotFound("RA contact information not found.");
}

if (raId == null)
{
return NotFound($"No RA is currently on call for hall ID: {Hall_ID}");
}
return Ok(contactInfo);
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}

return Ok(raId);
}
catch (Exception ex)
/// <summary>
/// Checks an RA in
/// </summary>
/// <param name="checkin">The viewmodel object of the RA checking in</param>
/// <returns>true if RA checked in successfully</returns>
[HttpPost("ra-checkin")]
public async Task<ActionResult<bool>> RA_Checkin([FromBody] RA_On_CallViewModel RAcheckin)
{
try
{
var checkedIn = await housingService.RA_CheckinAsync(RAcheckin);
if (checkedIn)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
return Created("RA checked in successfully.", checkedIn);
}
return BadRequest("Failed to check in RA.");
}
catch (InvalidOperationException ex)
{
return BadRequest(ex.Message);
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}

/// <summary>
/// Gets the on-call RAs for all halls.
/// </summary>
/// <returns>The RAs on call</returns>
[HttpGet("on-call-ra/all")]
public async Task<ActionResult<List<RA_On_Call_GetViewModel>>> GetOnCallRAAllHalls()
/// <summary>
/// Gets the ID of the on-call RA for a specified hall.
/// </summary>
/// <param name="Hall_ID">The ID of the hall</param>
/// <returns>The ID of the on-call RA, or a 404 if no RA is on call</returns>
[HttpGet("on-call-ra/{Hall_ID}")]
public async Task<ActionResult<string>> GetOnCallRA(string Hall_ID)
{
try
{
try
var raId = await housingService.GetOnCallRAAsync(Hall_ID);

if (raId == null)
{
var onCallRAs = await housingService.GetOnCallRAAllHallsAsync();
return NotFound($"No RA is currently on call for hall ID: {Hall_ID}");
}

if (onCallRAs == null || !onCallRAs.Any())
{
return NotFound("No RA is currently on call for any hall.");
}
return Ok(raId);
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}

return Ok(onCallRAs);
}
catch (Exception ex)
/// <summary>
/// Gets the on-call RAs for all halls.
/// </summary>
/// <returns>The RAs on call</returns>
[HttpGet("on-call-ra/all")]
public async Task<ActionResult<List<RA_On_Call_GetViewModel>>> GetOnCallRAAllHalls()
{
try
{
var onCallRAs = await housingService.GetOnCallRAAllHallsAsync();

if (onCallRAs == null || !onCallRAs.Any())
{
return StatusCode(500, $"Internal server error: {ex.Message}");
return NotFound("No RA is currently on call for any hall.");
}

return Ok(onCallRAs);
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}



Expand Down
34 changes: 34 additions & 0 deletions Gordon360/Documentation/Gordon360.xml

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Gordon360.Extensions.System;
using Gordon360.Models.CCT;
using System;
using System.Collections.Generic;

namespace Gordon360.Models.ViewModels;
public class RA_ContactPreference
{
public string Ra_ID { get; set; } // ID of the RA
public string PreferredContactMethod { get; set; } // e.g., "Phone", "Teams"
}
Loading

0 comments on commit b4fe9b0

Please sign in to comment.