Add MasterBotUserId and MasterAgentName for copy trading support

- Introduced MasterBotUserId and MasterAgentName properties to facilitate copy trading functionality.
- Updated relevant models, controllers, and database entities to accommodate these new properties.
- Enhanced validation logic in StartCopyTradingCommandHandler to ensure proper ownership checks for master strategies.
This commit is contained in:
2025-11-20 00:33:31 +07:00
parent 97103fbfe8
commit ff2df2d9ac
13 changed files with 1852 additions and 20 deletions

View File

@@ -79,6 +79,7 @@ public class PostgreSqlBotRepository : IBotRepository
existingEntity.LastStartTime = bot.LastStartTime;
existingEntity.LastStopTime = bot.LastStopTime;
existingEntity.AccumulatedRunTimeSeconds = bot.AccumulatedRunTimeSeconds;
existingEntity.MasterBotUserId = bot.MasterBotUserId;
await _context.SaveChangesAsync().ConfigureAwait(false);
}
@@ -114,10 +115,26 @@ public class PostgreSqlBotRepository : IBotRepository
var entities = await _context.Bots
.AsNoTracking()
.Include(m => m.User)
.Include(m => m.MasterBotUser)
.Where(b => b.UserId == id)
.ToListAsync()
.ConfigureAwait(false);
return PostgreSqlMappers.Map(entities);
// Map entities to domain objects
var bots = PostgreSqlMappers.Map(entities).ToList();
// Attach master bot users to domain objects
foreach (var entity in entities.Where(e => e.MasterBotUser != null))
{
var bot = bots.FirstOrDefault(b => b.MasterBotUserId == entity.MasterBotUserId);
if (bot != null)
{
// Convert UserEntity to User domain object
bot.MasterBotUser = PostgreSqlMappers.Map(entity.MasterBotUser);
}
}
return bots;
}
public async Task<IEnumerable<Bot>> GetBotsByStatusAsync(BotStatus status)