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:
2025-12-30 05:54:15 +07:00
parent 95e60108af
commit 79d8a381d9
13 changed files with 2022 additions and 2 deletions

View File

@@ -145,4 +145,29 @@ public class UserController : BaseController
return StatusCode(500, $"Failed to send test message: {ex.Message}");
}
}
/// <summary>
/// Updates the user settings for the current user.
/// </summary>
/// <param name="settings">The user settings to update.</param>
/// <returns>The updated user with the new settings.</returns>
[Authorize]
[HttpPut("settings")]
public async Task<ActionResult<User>> UpdateUserSettings([FromBody] UpdateUserSettingsRequest settings)
{
var user = await GetUser();
// Map API request to DTO
var settingsDto = new Managing.Application.Abstractions.Models.UserSettingsDto
{
LowEthAmountAlert = settings.LowEthAmountAlert,
EnableAutoswap = settings.EnableAutoswap,
AutoswapAmount = settings.AutoswapAmount,
MaxWaitingTimeForPositionToGetFilledSeconds = settings.MaxWaitingTimeForPositionToGetFilledSeconds,
MaxTxnGasFeePerPosition = settings.MaxTxnGasFeePerPosition,
IsGmxEnabled = settings.IsGmxEnabled,
MinimumConfidence = settings.MinimumConfidence
};
var updatedUser = await _userService.UpdateUserSettings(user, settingsDto);
return Ok(updatedUser);
}
}

View File

@@ -0,0 +1,16 @@
using Managing.Common;
using static Managing.Common.Enums;
namespace Managing.Api.Models.Requests;
public class UpdateUserSettingsRequest
{
public decimal? LowEthAmountAlert { get; set; }
public bool? EnableAutoswap { get; set; }
public decimal? AutoswapAmount { get; set; }
public int? MaxWaitingTimeForPositionToGetFilledSeconds { get; set; }
public decimal? MaxTxnGasFeePerPosition { get; set; }
public bool? IsGmxEnabled { get; set; }
public Confidence? MinimumConfidence { get; set; }
}