diff --git a/Gordon360/Controllers/HousingController.cs b/Gordon360/Controllers/HousingController.cs index 3f53d2f48..04ab75823 100644 --- a/Gordon360/Controllers/HousingController.cs +++ b/Gordon360/Controllers/HousingController.cs @@ -430,11 +430,11 @@ public async Task SetPreferredContact([FromRoute] string raId, [F /// phone number if no preference is set. [HttpGet("ra/{raId}/contact")] [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.HOUSING_CONTACT_PREFERENCE)] - public async Task> GetRAContact([FromRoute] string raId) + public async Task> 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."); } @@ -442,25 +442,6 @@ public async Task> GetRAContact([FromRoute] string raId) return Ok(contactInfo); } - /// - /// Retrieves the preferred contact method for an RA based on their contact preference. - /// - /// The ID of the RA whose contact information is being requested. - /// A string containing the preferred contact method (Teams or Phone). - [HttpGet("ra/contact/preference/{raId}")] - public async Task GetRAPrefContact([FromRoute] string raId) - { - var Preference = await housingService.GetContactPreferenceAsync(raId); - - if (Preference == null) - { - return NotFound("RA preferred contact information not found."); - } - - return Ok(Preference); - - } - /// /// Creates a new status event for an RA schedule diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 44ffa30c2..de2887a2b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -368,13 +368,6 @@ A string containing the preferred contact information (phone number or Teams link) or a default phone number if no preference is set. - - - Retrieves the preferred contact method for an RA based on their contact preference. - - The ID of the RA whose contact information is being requested. - A string containing the preferred contact method (Teams or Phone). - Creates a new status event for an RA schedule @@ -2057,13 +2050,6 @@ A string containing the preferred contact information (phone number or Teams link) or a default phone number if no preference is set. - - - Retrieves the preferred contact method for an RA based on their contact preference. - - The ID of the RA whose contact information is being requested. - An object containing the preferred contact method (Teams or Phone). - Gets the on-call RA's ID for specified hall. diff --git a/Gordon360/Models/ViewModels/Housing/RA_ContactPreferenceViewModel.cs b/Gordon360/Models/ViewModels/Housing/RA_ContactPreferenceViewModel.cs index 82dc10a9f..e26aecf3a 100644 --- a/Gordon360/Models/ViewModels/Housing/RA_ContactPreferenceViewModel.cs +++ b/Gordon360/Models/ViewModels/Housing/RA_ContactPreferenceViewModel.cs @@ -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..." } diff --git a/Gordon360/Services/HousingService.cs b/Gordon360/Services/HousingService.cs index c112e8a42..edda25329 100644 --- a/Gordon360/Services/HousingService.cs +++ b/Gordon360/Services/HousingService.cs @@ -757,7 +757,7 @@ public async Task 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; } @@ -868,75 +868,56 @@ public async Task SetPreferredContactMethodAsync(string raId, string prefe /// The ID of the RA whose contact information is being requested. /// A string containing the preferred contact information (phone number or Teams link) or a default /// phone number if no preference is set. - public async Task GetPreferredContactAsync(string raId) + public async Task 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"; - } - - /// - /// Retrieves the preferred contact method for an RA based on their contact preference. - /// - /// The ID of the RA whose contact information is being requested. - /// An object containing the preferred contact method (Teams or Phone). - public async Task 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; } + /// /// Gets the on-call RA's ID for specified hall. /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index c9c95ae4d..d4793617c 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -236,8 +236,7 @@ public interface IHousingService Task> GetAllRAsAsync(); Task> GetRangeAssignmentsAsync(); Task SetPreferredContactMethodAsync(string raId, string preferredContactMethod); - Task GetPreferredContactAsync(string raId); - Task GetContactPreferenceAsync(string raId); + Task GetPreferredContactAsync(string raId); Task RA_CheckinAsync(string[] HallIDs, string raId); Task GetOnCallRAAsync(string hallId); Task> GetOnCallRAAllHallsAsync();