Stop all bot for a user

This commit is contained in:
2025-08-06 16:03:42 +07:00
parent b70018ba15
commit 93a6f9fd9e
3 changed files with 107 additions and 0 deletions

View File

@@ -195,6 +195,43 @@ public class BotController : BaseController
}
}
/// <summary>
/// Stops all active bots for the connected user.
/// </summary>
/// <returns>A boolean indicating the result of the stop all operation.</returns>
[HttpGet]
[Route("StopAll")]
public async Task<ActionResult<bool>> StopAll()
{
try
{
var user = await GetUser();
if (user == null)
{
return Unauthorized("User not found");
}
var result = await _mediator.Send(new StopAllUserBotsCommand(user));
if (result)
{
await NotifyBotSubscriberAsync();
_logger.LogInformation($"All bots stopped successfully for user {user.Name}");
}
else
{
_logger.LogWarning($"Failed to stop all bots for user {user.Name}");
}
return Ok(result);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error stopping all bots");
return StatusCode(500, $"Error stopping all bots: {ex.Message}");
}
}
/// <summary>
/// Deletes a bot specified by name.
/// </summary>