Add BacktestCount
This commit is contained in:
1452
src/Managing.Infrastructure.Database/Migrations/20251001055823_AddBacktestCountToAgentSummary.Designer.cs
generated
Normal file
1452
src/Managing.Infrastructure.Database/Migrations/20251001055823_AddBacktestCountToAgentSummary.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Managing.Infrastructure.Databases.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddBacktestCountToAgentSummary : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BacktestCount",
|
||||
table: "AgentSummaries",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BacktestCount",
|
||||
table: "AgentSummaries");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)");
|
||||
|
||||
b.Property<int>("BacktestCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
|
||||
@@ -251,7 +251,8 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
ActiveStrategiesCount = domain.ActiveStrategiesCount,
|
||||
TotalVolume = domain.TotalVolume,
|
||||
TotalBalance = domain.TotalBalance,
|
||||
TotalFees = domain.TotalFees
|
||||
TotalFees = domain.TotalFees,
|
||||
BacktestCount = domain.BacktestCount
|
||||
};
|
||||
}
|
||||
|
||||
@@ -269,6 +270,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
entity.TotalVolume = domain.TotalVolume;
|
||||
entity.TotalBalance = domain.TotalBalance;
|
||||
entity.TotalFees = domain.TotalFees;
|
||||
entity.BacktestCount = domain.BacktestCount;
|
||||
}
|
||||
|
||||
private static AgentSummary MapToDomain(AgentSummaryEntity entity)
|
||||
@@ -290,6 +292,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
TotalVolume = entity.TotalVolume,
|
||||
TotalBalance = entity.TotalBalance,
|
||||
TotalFees = entity.TotalFees,
|
||||
BacktestCount = entity.BacktestCount,
|
||||
User = PostgreSqlMappers.Map(entity.User)
|
||||
};
|
||||
}
|
||||
@@ -329,4 +332,26 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
{
|
||||
return await _context.AgentSummaries.CountAsync();
|
||||
}
|
||||
|
||||
public async Task IncrementBacktestCountAsync(int userId)
|
||||
{
|
||||
var entity = await _context.AgentSummaries
|
||||
.FirstOrDefaultAsync(a => a.UserId == userId);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.BacktestCount++;
|
||||
entity.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Backtest count incremented for user {UserId} to {BacktestCount}",
|
||||
userId, entity.BacktestCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No AgentSummary found for user {UserId} when trying to increment backtest count",
|
||||
userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class AgentSummaryEntity
|
||||
public decimal TotalBalance { get; set; }
|
||||
public decimal TotalFees { get; set; }
|
||||
public decimal NetPnL { get; set; }
|
||||
public int BacktestCount { get; set; }
|
||||
|
||||
// Navigation property
|
||||
public UserEntity User { get; set; }
|
||||
|
||||
@@ -548,6 +548,7 @@ public class ManagingDbContext : DbContext
|
||||
entity.Property(e => e.ActiveStrategiesCount).IsRequired();
|
||||
entity.Property(e => e.TotalVolume).HasPrecision(18, 8);
|
||||
entity.Property(e => e.TotalBalance).HasPrecision(18, 8);
|
||||
entity.Property(e => e.BacktestCount).IsRequired();
|
||||
|
||||
// Create indexes for common queries
|
||||
entity.HasIndex(e => e.UserId).IsUnique();
|
||||
|
||||
Reference in New Issue
Block a user