Enhance DataController to support status filtering in GetStrategiesPaginated method
- Added an optional status parameter to the GetStrategiesPaginated method, defaulting to Running if not provided. - Updated the bot retrieval logic to apply the status filter directly, simplifying the filtering process and ensuring accurate bot status management.
This commit is contained in:
@@ -918,6 +918,7 @@ public class DataController : ControllerBase
|
|||||||
public async Task<ActionResult<PaginatedResponse<TradingBotResponse>>> GetStrategiesPaginated(
|
public async Task<ActionResult<PaginatedResponse<TradingBotResponse>>> GetStrategiesPaginated(
|
||||||
int pageNumber = 1,
|
int pageNumber = 1,
|
||||||
int pageSize = 10,
|
int pageSize = 10,
|
||||||
|
BotStatus? status = null,
|
||||||
string? name = null,
|
string? name = null,
|
||||||
string? ticker = null,
|
string? ticker = null,
|
||||||
string? agentName = null,
|
string? agentName = null,
|
||||||
@@ -943,11 +944,14 @@ public class DataController : ControllerBase
|
|||||||
// Check environment variable for filtering profitable strategies only
|
// Check environment variable for filtering profitable strategies only
|
||||||
var showOnlyProfitable = _configuration.GetValue<bool>("showOnlyProfitable", false);
|
var showOnlyProfitable = _configuration.GetValue<bool>("showOnlyProfitable", false);
|
||||||
|
|
||||||
// Get paginated bots excluding Saved status
|
// Default to Running status if not provided
|
||||||
|
var statusFilter = status ?? BotStatus.Running;
|
||||||
|
|
||||||
|
// Get paginated bots with status filter
|
||||||
var (bots, totalCount) = await _botService.GetBotsPaginatedAsync(
|
var (bots, totalCount) = await _botService.GetBotsPaginatedAsync(
|
||||||
pageNumber,
|
pageNumber,
|
||||||
pageSize,
|
pageSize,
|
||||||
null, // No specific status filter - we'll exclude Saved in the service call
|
statusFilter,
|
||||||
name,
|
name,
|
||||||
ticker,
|
ticker,
|
||||||
agentName,
|
agentName,
|
||||||
@@ -957,9 +961,9 @@ public class DataController : ControllerBase
|
|||||||
sortDirection,
|
sortDirection,
|
||||||
showOnlyProfitable);
|
showOnlyProfitable);
|
||||||
|
|
||||||
// Filter out Saved status bots
|
// No additional filtering needed since we're using the status filter directly
|
||||||
var filteredBots = bots.Where(bot => bot.Status != BotStatus.Saved).ToList();
|
var filteredBots = bots.ToList();
|
||||||
var filteredCount = totalCount - bots.Count(bot => bot.Status == BotStatus.Saved);
|
var filteredCount = totalCount;
|
||||||
|
|
||||||
// Map to response objects
|
// Map to response objects
|
||||||
var tradingBotResponses = MapBotsToTradingBotResponse(filteredBots);
|
var tradingBotResponses = MapBotsToTradingBotResponse(filteredBots);
|
||||||
|
|||||||
Reference in New Issue
Block a user