Skip to content

Commit

Permalink
Contact preference endpoints combined into a single call
Browse files Browse the repository at this point in the history
  • Loading branch information
RossClark01 committed Dec 12, 2024
1 parent 7001703 commit b30bdb3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 93 deletions.
23 changes: 2 additions & 21 deletions Gordon360/Controllers/HousingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,37 +430,18 @@ public async Task<IActionResult> SetPreferredContact([FromRoute] string raId, [F
/// phone number if no preference is set.</returns>
[HttpGet("ra/{raId}/contact")]
[StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.HOUSING_CONTACT_PREFERENCE)]
public async Task<ActionResult<string>> GetRAContact([FromRoute] string raId)
public async Task<ActionResult<RA_ContactPreference>> GetRAContact([FromRoute] string raId)
{
var contactInfo = await housingService.GetPreferredContactAsync(raId);

if (string.IsNullOrEmpty(contactInfo))
if (contactInfo.Contact == null)
{
return NotFound("RA contact information not found.");
}

return Ok(contactInfo);
}

/// <summary>
/// Retrieves the preferred contact method for an RA based on their contact preference.
/// </summary>
/// <param name="raId">The ID of the RA whose contact information is being requested.</param>
/// <returns>A string containing the preferred contact method (Teams or Phone).</returns>
[HttpGet("ra/contact/preference/{raId}")]
public async Task<ActionResult> GetRAPrefContact([FromRoute] string raId)
{
var Preference = await housingService.GetContactPreferenceAsync(raId);

if (Preference == null)
{
return NotFound("RA preferred contact information not found.");
}

return Ok(Preference);

}


/// <summary>
/// Creates a new status event for an RA schedule
Expand Down
14 changes: 0 additions & 14 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
Expand Up @@ -8,4 +8,5 @@ public class RA_ContactPreference
{
public string Ra_ID { get; set; } // ID of the RA
public string PreferredContactMethod { get; set; } // e.g., "Phone", "Teams"
public string Contact { get; set; } // e.g "9788674500", "https..."
}
93 changes: 37 additions & 56 deletions Gordon360/Services/HousingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public async Task<RA_StudentsViewModel> GetResidentRAAsync(string hallId, string
// Fetch and include the preferred contact method for the RA
var preferredContact = await GetPreferredContactAsync(assignedRA.ID);

assignedRA.PreferredContact = preferredContact;
assignedRA.PreferredContact = preferredContact.Contact;

return assignedRA;
}
Expand Down Expand Up @@ -868,75 +868,56 @@ public async Task<bool> SetPreferredContactMethodAsync(string raId, string prefe
/// <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>
public async Task<string> GetPreferredContactAsync(string raId)
public async Task<RA_ContactPreference> GetPreferredContactAsync(string raId)
{
// Check if there is a preferred contact method for the given RA
var contactPreference = await context.RA_Pref_Contact
.FirstOrDefaultAsync(cp => cp.Ra_ID == raId);
// Check if there is a preferred contact method for the given RA
var contactPreference = await context.RA_Pref_Contact
.FirstOrDefaultAsync(cp => cp.Ra_ID == raId);

if (contactPreference != null)
{
// Determine the preferred method and get corresponding contact info
if (contactPreference.Pref_contact == "phone")
{
// Fetch RA's phone number from the RA_Students table
var ra = await context.RA_Students
.FirstOrDefaultAsync(r => r.ID == raId);
//find ra by id
var ra = await context.RA_Students
.FirstOrDefaultAsync(r => r.ID == raId);

return ra?.PhoneNumber ?? "Phone number not found";
}
else if (contactPreference.Pref_contact == "teams")
// default contact to be phone
var Contact = new RA_ContactPreference
{
// Fetch RA's email from the RA_Students table
var ra = await context.RA_Students
.FirstOrDefaultAsync(r => r.ID == raId);
Ra_ID = raId,
PreferredContactMethod = "phone",
Contact = ra?.PhoneNumber ?? "Phone number not found"
};

if (ra?.Email != null)

if (contactPreference != null)
{
// Determine the preferred method and get corresponding contact info
if (contactPreference.Pref_contact == "phone")
{
// Generate Teams link using the email
return $"https://teams.microsoft.com/l/chat/0/0?users={ra.Email}";
return Contact;
}
else
else if (contactPreference.Pref_contact == "teams")
{
return "Email not found";
}
}
}
// Fetch RA's email from the RA_Students table

// If no preference exists, return the phone number by default
var defaultContact = await context.RA_Students
.FirstOrDefaultAsync(r => r.ID == raId);

return defaultContact?.PhoneNumber ?? "Default phone number not found";
}

/// <summary>
/// Retrieves the preferred contact method for an RA based on their contact preference.
/// </summary>
/// <param name="raId">The ID of the RA whose contact information is being requested.</param>
/// <returns>An object containing the preferred contact method (Teams or Phone).</returns>
public async Task<object> GetContactPreferenceAsync(string raId)
{
// Check if there is a preferred contact method for the given RA
var contactPreference = await context.RA_Pref_Contact
.FirstOrDefaultAsync(cp => cp.Ra_ID == raId);
if (ra?.Email != null)
{
// Generate Teams link using the email
Contact = new RA_ContactPreference
{
Ra_ID = raId,
PreferredContactMethod = "teams",
Contact = $"https://teams.microsoft.com/l/chat/0/0?users={ra.Email}"
};

if (contactPreference != null)
{
return new
{
PreferredContact = contactPreference.Pref_contact
};
return Contact; //unable to generate teams link, default to phone
}
}
}

// If no preference exists, return phone default as default method
return new
{
PreferredContact = "phone"
};

// If no preference exists, return the phone number by default
return Contact;
}


/// <summary>
/// Gets the on-call RA's ID for specified hall.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ public interface IHousingService
Task<List<RA_StudentsViewModel>> GetAllRAsAsync();
Task<List<RA_Assigned_RangesViewModel>> GetRangeAssignmentsAsync();
Task<bool> SetPreferredContactMethodAsync(string raId, string preferredContactMethod);
Task<string> GetPreferredContactAsync(string raId);
Task<object> GetContactPreferenceAsync(string raId);
Task<RA_ContactPreference> GetPreferredContactAsync(string raId);
Task<bool> RA_CheckinAsync(string[] HallIDs, string raId);
Task<RA_On_Call_GetViewModel> GetOnCallRAAsync(string hallId);
Task<List<RA_On_Call_GetViewModel>> GetOnCallRAAllHallsAsync();
Expand Down

0 comments on commit b30bdb3

Please sign in to comment.