Fix db and fix endpoints

This commit is contained in:
2025-08-05 22:30:18 +07:00
parent 2dcbcc3ef2
commit 36529ae403
36 changed files with 5073 additions and 245 deletions

View File

@@ -1,20 +1,23 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static Managing.Common.Enums;
namespace Managing.Infrastructure.Databases.PostgreSql.Entities;
[Table("Accounts")]
public class AccountEntity
{
public int Id { get; set; }
public string Name { get; set; }
public TradingExchanges Exchange { get; set; }
public AccountType Type { get; set; }
public string? Key { get; set; }
[Key] public int Id { get; set; }
[Required] public string Name { get; set; }
[Required] public TradingExchanges Exchange { get; set; }
[Required] public AccountType Type { get; set; }
[Required] public string? Key { get; set; }
public string? Secret { get; set; }
public int? UserId { get; set; }
[Required] public int UserId { get; set; }
// Navigation properties
public UserEntity? User { get; set; }
// Store balances as JSON if needed, or skip them entirely
// public string? BalancesJson { get; set; }
}
}

View File

@@ -56,8 +56,10 @@ public class BacktestEntity
public string MoneyManagementJson { get; set; } = string.Empty;
[Required]
[MaxLength(255)]
public string UserName { get; set; } = string.Empty;
public int UserId { get; set; }
// Navigation property
public UserEntity? User { get; set; }
[Column(TypeName = "jsonb")]
public string? StatisticsJson { get; set; }

View File

@@ -15,7 +15,7 @@ public class BotEntity
public int UserId { get; set; }
[Required] [ForeignKey("UserId")] public required UserEntity User { get; set; }
[ForeignKey("UserId")] public UserEntity User { get; set; }
public BotStatus Status { get; set; }
public DateTime CreateDate { get; set; }

View File

@@ -15,10 +15,6 @@ public class BundleBacktestRequestEntity
[MaxLength(255)]
public string RequestId { get; set; } = string.Empty;
[Required]
[MaxLength(255)]
public string UserName { get; set; } = string.Empty;
// Foreign key to User entity
public int? UserId { get; set; }

View File

@@ -1,7 +1,9 @@
using System.ComponentModel.DataAnnotations.Schema;
using static Managing.Common.Enums;
namespace Managing.Infrastructure.Databases.PostgreSql.Entities;
[Table("GeneticRequests")]
public class GeneticRequestEntity
{
public int Id { get; set; }

View File

@@ -28,12 +28,14 @@ public class IndicatorEntity
public int? SmoothPeriods { get; set; }
public int? CyclePeriods { get; set; }
[MaxLength(255)]
public string? UserName { get; set; }
public int? UserId { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigation properties
public UserEntity? User { get; set; }
// Navigation property for the many-to-many relationship with scenarios
public virtual ICollection<ScenarioIndicatorEntity> ScenarioIndicators { get; set; } = new List<ScenarioIndicatorEntity>();
}

View File

@@ -22,7 +22,7 @@ public class PositionEntity
[MaxLength(255)] public string AccountName { get; set; }
[MaxLength(255)] public string? UserName { get; set; }
public int? UserId { get; set; }
// Foreign keys to trades
public int? OpenTradeId { get; set; }
@@ -37,6 +37,8 @@ public class PositionEntity
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigation properties
public UserEntity? User { get; set; }
[ForeignKey("OpenTradeId")] public virtual TradeEntity? OpenTrade { get; set; }
[ForeignKey("StopLossTradeId")] public virtual TradeEntity? StopLossTrade { get; set; }

View File

@@ -15,12 +15,15 @@ public class ScenarioEntity
public int LoopbackPeriod { get; set; }
[MaxLength(255)]
public string? UserName { get; set; }
[Required]
public int UserId { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigation properties
public UserEntity? User { get; set; }
// Navigation property for the many-to-many relationship with indicators
public virtual ICollection<ScenarioIndicatorEntity> ScenarioIndicators { get; set; } = new List<ScenarioIndicatorEntity>();
}

View File

@@ -26,8 +26,10 @@ public class SignalEntity
[MaxLength(255)]
public string IndicatorName { get; set; }
[MaxLength(255)]
public string? UserName { get; set; }
public int? UserId { get; set; }
// Navigation property
public UserEntity? User { get; set; }
// Candle data stored as JSON
[Column(TypeName = "text")]

View File

@@ -1,9 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Managing.Infrastructure.Databases.PostgreSql.Entities;
[Table("Users")]
[Index(nameof(Name), IsUnique = true)]
public class UserEntity
{
[Key] public int Id { get; set; }