Skip to content

Commit

Permalink
Merge pull request microsoft#14 from aaronba/syncbranch
Browse files Browse the repository at this point in the history
Fix during Settings update call on new user record
  • Loading branch information
mattahearn authored Apr 24, 2024
2 parents b7a11f7 + d8552de commit ae5e220
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions webapi/Controllers/UserSettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<IActionResult> GetUserSettingsAsync(Guid userId)
this._logger.LogDebug("No user settings record found. Creating a default record");

// No record found, create a new settings record for this user
var newUserSettings = new UserSettings(userId.ToString(), false, false, false, true, true, false, false, false, true, true, false);
UserSettings newUserSettings = new(userId.ToString(), false, false, false, true, true, false, false, false, true, true, false);
await this._userSettingsRepository.CreateAsync(newUserSettings);
return this.Ok(newUserSettings); // Only 1 record per user id
}
Expand Down Expand Up @@ -91,36 +91,48 @@ public async Task<IActionResult> UpdateUserSettingsAsync(
[FromBody] EditUserSettingsParameters msgParameters,
[FromRoute] Guid userId)
{
if (msgParameters.userId != null)
IEnumerable<UserSettings> settings;
try
{
var settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId.ToString());

foreach (var setting in settings)
if (msgParameters.userId != null)
{
// Update existing settings record for this user
setting!.DarkMode = msgParameters.darkMode;
setting!.Planners = msgParameters.planners;
setting!.Personas = msgParameters.personas;
setting!.SimplifiedChatExperience = msgParameters.simplifiedChatExperience;
setting!.AzureContentSafety = msgParameters.azureContentSafety;
setting!.AzureAISearch = msgParameters.azureAISearch;
setting!.ExportChatSessions = msgParameters.exportChatSessions;
setting!.LiveChatSessionSharing = msgParameters.liveChatSessionSharing;
setting!.FeedbackFromUser = msgParameters.feedbackFromUser;
setting!.DeploymentGPT35 = msgParameters.deploymentGPT35;
setting!.DeploymentGPT4 = msgParameters.deploymentGPT4;
await this._userSettingsRepository.UpsertAsync(setting);
settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId.ToString());

return this.Ok(setting);
}
if (!settings.OfType<UserSettings>().Any())
{
this._logger.LogDebug("No user settings record found. Creating a default record");

// Create a new settings record for this user
UserSettings newUserSettings = new(msgParameters.userId, msgParameters.darkMode, msgParameters.planners, msgParameters.personas,
msgParameters.simplifiedChatExperience, msgParameters.azureContentSafety, msgParameters.azureAISearch, msgParameters.exportChatSessions,
msgParameters.liveChatSessionSharing, msgParameters.feedbackFromUser, msgParameters.deploymentGPT35, msgParameters.deploymentGPT4);
await this._userSettingsRepository.CreateAsync(newUserSettings);
return this.Ok(newUserSettings);
}

// Create a new settings record for this user
var newUserSettings = new UserSettings(msgParameters.userId, msgParameters.darkMode, msgParameters.planners, msgParameters.personas,
msgParameters.simplifiedChatExperience, msgParameters.azureContentSafety, msgParameters.azureAISearch, msgParameters.exportChatSessions,
msgParameters.liveChatSessionSharing, msgParameters.feedbackFromUser, msgParameters.deploymentGPT35, msgParameters.deploymentGPT4);
await this._userSettingsRepository.CreateAsync(newUserSettings);
foreach (var setting in settings)
{
// Update existing settings record for this user
setting!.DarkMode = msgParameters.darkMode;
setting!.Planners = msgParameters.planners;
setting!.Personas = msgParameters.personas;
setting!.SimplifiedChatExperience = msgParameters.simplifiedChatExperience;
setting!.AzureContentSafety = msgParameters.azureContentSafety;
setting!.AzureAISearch = msgParameters.azureAISearch;
setting!.ExportChatSessions = msgParameters.exportChatSessions;
setting!.LiveChatSessionSharing = msgParameters.liveChatSessionSharing;
setting!.FeedbackFromUser = msgParameters.feedbackFromUser;
setting!.DeploymentGPT35 = msgParameters.deploymentGPT35;
setting!.DeploymentGPT4 = msgParameters.deploymentGPT4;
await this._userSettingsRepository.UpsertAsync(setting);

return this.Ok(newUserSettings);
return this.Ok(setting);
}
}
}
catch (Exception ex)
{
this._logger.LogError(ex.ToString());
}

return this.NotFound(" User ID was not sent to update user settings'.");
Expand Down

0 comments on commit ae5e220

Please sign in to comment.