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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,90 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Managing.Infrastructure.Databases.Migrations
{
/// <inheritdoc />
public partial class AddUserSettings : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "AutoswapAmount",
table: "Users",
type: "numeric(18,8)",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "EnableAutoswap",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "IsGmxEnabled",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<decimal>(
name: "LowEthAmountAlert",
table: "Users",
type: "numeric(18,8)",
nullable: true);
migrationBuilder.AddColumn<decimal>(
name: "MaxTxnGasFeePerPosition",
table: "Users",
type: "numeric(18,8)",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "MaxWaitingTimeForPositionToGetFilledSeconds",
table: "Users",
type: "integer",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "MinimumConfidence",
table: "Users",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AutoswapAmount",
table: "Users");
migrationBuilder.DropColumn(
name: "EnableAutoswap",
table: "Users");
migrationBuilder.DropColumn(
name: "IsGmxEnabled",
table: "Users");
migrationBuilder.DropColumn(
name: "LowEthAmountAlert",
table: "Users");
migrationBuilder.DropColumn(
name: "MaxTxnGasFeePerPosition",
table: "Users");
migrationBuilder.DropColumn(
name: "MaxWaitingTimeForPositionToGetFilledSeconds",
table: "Users");
migrationBuilder.DropColumn(
name: "MinimumConfidence",
table: "Users");
}
}
}

View File

@@ -1425,16 +1425,37 @@ namespace Managing.Infrastructure.Databases.Migrations
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<decimal?>("AutoswapAmount")
.HasColumnType("decimal(18,8)");
b.Property<string>("AvatarUrl")
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<bool>("EnableAutoswap")
.HasColumnType("boolean");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
b.Property<bool>("IsGmxEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LastConnectionDate")
.HasColumnType("timestamp with time zone");
b.Property<decimal?>("LowEthAmountAlert")
.HasColumnType("decimal(18,8)");
b.Property<decimal?>("MaxTxnGasFeePerPosition")
.HasColumnType("decimal(18,8)");
b.Property<int?>("MaxWaitingTimeForPositionToGetFilledSeconds")
.HasColumnType("integer");
b.Property<string>("MinimumConfidence")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)

View File

@@ -1,6 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Managing.Common;
using Microsoft.EntityFrameworkCore;
using static Managing.Common.Enums;
namespace Managing.Infrastructure.Databases.PostgreSql.Entities;
@@ -17,6 +19,15 @@ public class UserEntity
public DateTimeOffset? LastConnectionDate { get; set; }
public bool IsAdmin { get; set; }
// User Settings
[Column(TypeName = "decimal(18,8)")] public decimal? LowEthAmountAlert { get; set; }
public bool EnableAutoswap { get; set; } = false;
[Column(TypeName = "decimal(18,8)")] public decimal? AutoswapAmount { get; set; }
public int? MaxWaitingTimeForPositionToGetFilledSeconds { get; set; }
[Column(TypeName = "decimal(18,8)")] public decimal? MaxTxnGasFeePerPosition { get; set; }
public bool IsGmxEnabled { get; set; } = false;
public Confidence? MinimumConfidence { get; set; }
// Navigation properties
public virtual ICollection<AccountEntity> Accounts { get; set; } = new List<AccountEntity>();
}

View File

@@ -101,6 +101,8 @@ public class ManagingDbContext : DbContext
entity.Property(e => e.AgentName).HasMaxLength(255);
entity.Property(e => e.AvatarUrl).HasMaxLength(500);
entity.Property(e => e.TelegramChannel).HasMaxLength(255);
entity.Property(e => e.MinimumConfidence)
.HasConversion<string>(); // Store enum as string
// Create indexes for performance
entity.HasIndex(e => e.Name).IsUnique();

View File

@@ -133,6 +133,14 @@ public static class PostgreSqlMappers
OwnerWalletAddress = entity.OwnerWalletAddress,
Id = entity.Id, // Assuming Id is the primary key for UserEntity
IsAdmin = entity.IsAdmin,
LastConnectionDate = entity.LastConnectionDate,
LowEthAmountAlert = entity.LowEthAmountAlert,
EnableAutoswap = entity.EnableAutoswap,
AutoswapAmount = entity.AutoswapAmount,
MaxWaitingTimeForPositionToGetFilledSeconds = entity.MaxWaitingTimeForPositionToGetFilledSeconds,
MaxTxnGasFeePerPosition = entity.MaxTxnGasFeePerPosition,
IsGmxEnabled = entity.IsGmxEnabled,
MinimumConfidence = entity.MinimumConfidence,
Accounts = entity.Accounts?.Select(MapAccountWithoutUser).ToList() ?? new List<Account>()
};
}
@@ -167,7 +175,15 @@ public static class PostgreSqlMappers
AvatarUrl = user.AvatarUrl,
TelegramChannel = user.TelegramChannel,
OwnerWalletAddress = user.OwnerWalletAddress,
IsAdmin = user.IsAdmin
IsAdmin = user.IsAdmin,
LastConnectionDate = user.LastConnectionDate,
LowEthAmountAlert = user.LowEthAmountAlert,
EnableAutoswap = user.EnableAutoswap,
AutoswapAmount = user.AutoswapAmount,
MaxWaitingTimeForPositionToGetFilledSeconds = user.MaxWaitingTimeForPositionToGetFilledSeconds,
MaxTxnGasFeePerPosition = user.MaxTxnGasFeePerPosition,
IsGmxEnabled = user.IsGmxEnabled,
MinimumConfidence = user.MinimumConfidence
};
}

View File

@@ -256,6 +256,14 @@ public class PostgreSqlUserRepository : BaseRepositoryWithLogging, IUserReposito
existingUser.TelegramChannel = user.TelegramChannel;
existingUser.OwnerWalletAddress = user.OwnerWalletAddress;
existingUser.IsAdmin = user.IsAdmin;
existingUser.LastConnectionDate = user.LastConnectionDate;
existingUser.LowEthAmountAlert = user.LowEthAmountAlert;
existingUser.EnableAutoswap = user.EnableAutoswap;
existingUser.AutoswapAmount = user.AutoswapAmount;
existingUser.MaxWaitingTimeForPositionToGetFilledSeconds = user.MaxWaitingTimeForPositionToGetFilledSeconds;
existingUser.MaxTxnGasFeePerPosition = user.MaxTxnGasFeePerPosition;
existingUser.IsGmxEnabled = user.IsGmxEnabled;
existingUser.MinimumConfidence = user.MinimumConfidence;
_context.Users.Update(existingUser);