Add user settings update functionality in UserController and UserService
Implement a new endpoint in UserController to allow users to update their settings. The UserService is updated to handle the logic for updating user settings, including partial updates for various fields. Additionally, the User entity and database schema are modified to accommodate new user settings properties, ensuring persistence and retrieval of user preferences.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Managing.Application.Abstractions.Grains;
|
||||
using Managing.Application.Abstractions.Models;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Abstractions.Shared;
|
||||
@@ -338,6 +339,36 @@ public class UserService : IUserService
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User> UpdateUserSettings(User user, UserSettingsDto settings)
|
||||
{
|
||||
user = await GetUserByName(user.Name);
|
||||
|
||||
// Update settings only if values are provided (partial update support)
|
||||
if (settings.LowEthAmountAlert.HasValue)
|
||||
user.LowEthAmountAlert = settings.LowEthAmountAlert.Value;
|
||||
|
||||
if (settings.EnableAutoswap.HasValue)
|
||||
user.EnableAutoswap = settings.EnableAutoswap.Value;
|
||||
|
||||
if (settings.AutoswapAmount.HasValue)
|
||||
user.AutoswapAmount = settings.AutoswapAmount.Value;
|
||||
|
||||
if (settings.MaxWaitingTimeForPositionToGetFilledSeconds.HasValue)
|
||||
user.MaxWaitingTimeForPositionToGetFilledSeconds = settings.MaxWaitingTimeForPositionToGetFilledSeconds.Value;
|
||||
|
||||
if (settings.MaxTxnGasFeePerPosition.HasValue)
|
||||
user.MaxTxnGasFeePerPosition = settings.MaxTxnGasFeePerPosition.Value;
|
||||
|
||||
if (settings.IsGmxEnabled.HasValue)
|
||||
user.IsGmxEnabled = settings.IsGmxEnabled.Value;
|
||||
|
||||
if (settings.MinimumConfidence.HasValue)
|
||||
user.MinimumConfidence = settings.MinimumConfidence.Value;
|
||||
|
||||
await _userRepository.SaveOrUpdateUserAsync(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User> GetUserByName(string name)
|
||||
{
|
||||
return await _userRepository.GetUserByNameAsync(name);
|
||||
|
||||
Reference in New Issue
Block a user