Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store SMSOptedIn in CustomProfile #1126

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gordon360/Controllers/AcademicCheckInController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ public async Task<ActionResult<EmergencyContactViewModel>> PutEmergencyContactAs
public async Task<ActionResult> PutCellPhoneAsync([FromBody] MobilePhoneUpdateViewModel data)
{
var username = AuthUtils.GetUsername(User);
var id = accountService.GetAccountByUsername(username).GordonID;

try
{
await academicCheckInService.PutCellPhoneAsync(id, data);
await academicCheckInService.PutCellPhoneAsync(username, data);
return Ok();
}
catch (System.Exception e)
Expand Down
4 changes: 2 additions & 2 deletions Gordon360/Documentation/Gordon360.xml

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

3 changes: 3 additions & 0 deletions Gordon360/Gordon360.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Models\CCT\Context\efpt.CCT.config.json.user" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public partial class CUSTOM_PROFILE
[StringLength(4)]
[Unicode(false)]
public string PlannedGradYear { get; set; }

public bool SMSOptedIn { get; set; }
}
10 changes: 6 additions & 4 deletions Gordon360/Services/AcademicCheckInService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Gordon360.Services;
/// Service Class that facilitates data transactions between the AcademicCheckInController and the CheckIn database model.
/// </summary>
///
public partial class AcademicCheckInService(CCTContext context) : IAcademicCheckInService
public partial class AcademicCheckInService(CCTContext context, IProfileService profileService, IAccountService accountService) : IAcademicCheckInService
{
/// <summary> Stores the emergency contact information of a particular user </summary>
/// <param name="data"> The object that stores the contact info </param>
Expand Down Expand Up @@ -70,13 +70,15 @@ private static string CreateNotesValue(string MobilePhone, string HomePhone)

/// <summary> Stores the cellphone preferences for the current user </summary>
/// <param name="data"> The phone number object for the user </param>
/// <param name="id"> The id of the student to be updated </param>
/// <param name="username"> The username of the student to be updated </param>
/// <returns> The stored data </returns>
public async Task PutCellPhoneAsync(string id, MobilePhoneUpdateViewModel data)
public async Task PutCellPhoneAsync(string username, MobilePhoneUpdateViewModel data)
{
// TODO: Store SMS Consent value somewhere
await profileService.UpdateCustomProfileAsync(username, "SMSOptedIn", new Models.CCT.CUSTOM_PROFILE { username = username, SMSOptedIn = data.SMSOptedIn });

string id = accountService.GetAccountByUsername(username).GordonID;
var result = await context.Procedures.FINALIZATION_UPDATECELLPHONEAsync(id, FormatNumber(data.PersonalPhone), data.MakePrivate, NoneProvided: false);

if (result == null || result.Any(r => r.Success != true))
{
throw new ResourceNotFoundException() { ExceptionMessage = "The data was not found." };
Expand Down
28 changes: 18 additions & 10 deletions Gordon360/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DateTime GetBirthdate(string username)
// Test accounts always have current date and time as birthday, so
// treat this the same as no birthday
// Comment this out to see "happy birthday" banner in test accounts
var lifetime = DateTime.Now - (DateTime) birthdate;
var lifetime = DateTime.Now - (DateTime)birthdate;
if (lifetime.Days < 1) // no valid user was born within the last 24 hours
{
return impossible_birthdate;
Expand Down Expand Up @@ -236,41 +236,49 @@ public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_

if (original == null)
{
await context.CUSTOM_PROFILE.AddAsync(new CUSTOM_PROFILE { username = username, calendar = content.calendar, facebook = content.facebook, twitter = content.twitter, instagram = content.instagram, linkedin = content.linkedin, handshake = content.handshake, PlannedGradYear = content.PlannedGradYear });

await context.CUSTOM_PROFILE.AddAsync(new CUSTOM_PROFILE
{
username = username,
calendar = content.calendar,
facebook = content.facebook,
twitter = content.twitter,
instagram = content.instagram,
linkedin = content.linkedin,
handshake = content.handshake,
PlannedGradYear = content.PlannedGradYear,
SMSOptedIn = content.SMSOptedIn,
});
}
else
{

switch (type)
{

case "calendar":
original.calendar = content.calendar;
break;

case "facebook":
original.facebook = content.facebook;
break;

case "twitter":
original.twitter = content.twitter;
break;

case "instagram":
original.instagram = content.instagram;
break;

case "linkedin":
original.linkedin = content.linkedin;
break;

case "handshake":
original.handshake = content.handshake;
break;
case "plannedGradYear":
original.PlannedGradYear = content.PlannedGradYear;
break;
case "SMSOptedIn":
original.SMSOptedIn = content.SMSOptedIn;
break;
default:
throw new NotSupportedException($"Unrecognized custom profile setting {type}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public interface IAcademicCheckInService
Task<EnrollmentCheckinHolds> GetHoldsAsync(string id);
Task SetStatusAsync(string id);
Task<AcademicCheckInViewModel> PutDemographicAsync(string id, AcademicCheckInViewModel data);
Task<bool> GetStatusAsync(string id);
Task<bool> GetStatusAsync(string username);
}

namespace RecIM
Expand Down
Loading