Update doc and todo (#4)

* Updade doc

* Updade doc
This commit is contained in:
Oda
2024-07-20 21:33:50 +07:00
committed by GitHub
parent a43e560d3a
commit 743d04e6c5
12 changed files with 483 additions and 71 deletions

View File

@@ -11,6 +11,10 @@ using static Managing.Common.Enums;
namespace Managing.Api.Controllers;
/// <summary>
/// Controller for bot operations such as starting, stopping, deleting, and managing bots.
/// Requires authorization for access and produces JSON responses.
/// </summary>
[ApiController]
[Authorize]
[Route("[controller]")]
@@ -22,6 +26,13 @@ public class BotController : ControllerBase
private readonly IHubContext<BotHub> _hubContext;
private readonly IBacktester _backtester;
/// <summary>
/// Initializes a new instance of the <see cref="BotController"/> class.
/// </summary>
/// <param name="logger">Logger for logging information.</param>
/// <param name="mediator">Mediator for handling commands and requests.</param>
/// <param name="hubContext">SignalR hub context for real-time communication.</param>
/// <param name="backtester">Backtester for running backtests on bots.</param>
public BotController(ILogger<BotController> logger, IMediator mediator, IHubContext<BotHub> hubContext, IBacktester backtester)
{
_logger = logger;
@@ -30,6 +41,11 @@ public class BotController : ControllerBase
_backtester = backtester;
}
/// <summary>
/// Starts a bot with the specified parameters.
/// </summary>
/// <param name="request">The request containing bot start parameters.</param>
/// <returns>A string indicating the result of the start operation.</returns>
[HttpPost]
[Route("Start")]
public async Task<ActionResult<string>> Start(StartBotRequest request)
@@ -41,6 +57,12 @@ public class BotController : ControllerBase
return Ok(result);
}
/// <summary>
/// Stops a bot specified by type and name.
/// </summary>
/// <param name="botType">The type of the bot to stop.</param>
/// <param name="botName">The name of the bot to stop.</param>
/// <returns>A string indicating the result of the stop operation.</returns>
[HttpGet]
[Route("Stop")]
public async Task<ActionResult<string>> Stop(BotType botType, string botName)
@@ -53,6 +75,11 @@ public class BotController : ControllerBase
return Ok(result);
}
/// <summary>
/// Deletes a bot specified by name.
/// </summary>
/// <param name="botName">The name of the bot to delete.</param>
/// <returns>A boolean indicating the result of the delete operation.</returns>
[HttpDelete]
[Route("Delete")]
public async Task<ActionResult<bool>> Delete(string botName)
@@ -65,6 +92,10 @@ public class BotController : ControllerBase
return Ok(result);
}
/// <summary>
/// Stops all active bots.
/// </summary>
/// <returns>A string summarizing the results of the stop operations for all bots.</returns>
[HttpGet]
[Route("StopAll")]
public async Task<string> StopAll()
@@ -83,6 +114,12 @@ public class BotController : ControllerBase
return result;
}
/// <summary>
/// Restarts a bot specified by type and name.
/// </summary>
/// <param name="botType">The type of the bot to restart.</param>
/// <param name="botName">The name of the bot to restart.</param>
/// <returns>A string indicating the result of the restart operation.</returns>
[HttpGet]
[Route("Restart")]
public async Task<ActionResult<string>> Restart(BotType botType, string botName)
@@ -95,6 +132,10 @@ public class BotController : ControllerBase
return Ok(result);
}
/// <summary>
/// Restarts all active bots.
/// </summary>
/// <returns>A string summarizing the results of the restart operations for all bots.</returns>
[HttpGet]
[Route("RestartAll")]
public async Task<string> RestartAll()
@@ -113,6 +154,11 @@ public class BotController : ControllerBase
return result;
}
/// <summary>
/// Toggles the watching status of a bot specified by name.
/// </summary>
/// <param name="botName">The name of the bot to toggle watching status.</param>
/// <returns>A string indicating the new watching status of the bot.</returns>
[HttpGet]
[Route("ToggleIsForWatching")]
public async Task<ActionResult<string>> ToggleIsForWatching(string botName)
@@ -125,12 +171,20 @@ public class BotController : ControllerBase
return Ok(result);
}
/// <summary>
/// Retrieves a list of active bots.
/// </summary>
/// <returns>A list of active trading bots.</returns>
[HttpGet]
public async Task<List<TradingBot>> GetActiveBots()
{
return await GetBotList();
}
/// <summary>
/// Retrieves a list of active bots by sending a command to the mediator.
/// </summary>
/// <returns>A list of trading bots.</returns>
private async Task<List<TradingBot>> GetBotList()
{
var result = await _mediator.Send(new GetActiveBotsCommand());
@@ -160,9 +214,12 @@ public class BotController : ControllerBase
return list;
}
/// <summary>
/// Notifies subscribers about the current list of bots via SignalR.
/// </summary>
private async Task NotifyBotSubscriberAsync()
{
var botsList = await GetBotList();
await _hubContext.Clients.All.SendAsync("BotsSubscription", botsList);
}
}
}