Add agent summary update functionality and improve user controller

- Introduced a new endpoint in UserController to update the agent summary, ensuring balance data is refreshed after transactions.
- Implemented ForceUpdateSummaryImmediate method in IAgentGrain to allow immediate updates without cooldown checks.
- Enhanced StartBotCommandHandler to force update the agent summary before starting the bot, ensuring accurate balance data.
- Updated TypeScript API client to include the new update-agent-summary method for frontend integration.
This commit is contained in:
2026-01-03 03:09:44 +07:00
parent 78c2788ba7
commit fb49190346
7 changed files with 163 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
using Managing.Api.Authorization;
using Managing.Api.Models.Requests;
using Managing.Application.Abstractions.Models;
using Managing.Application.Abstractions.Services;
using Managing.Application.ManageBot.Commands;
using Managing.Domain.Users;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -18,6 +21,7 @@ public class UserController : BaseController
private IConfiguration _config;
private readonly IJwtUtils _jwtUtils;
private readonly IWebhookService _webhookService;
private readonly IMediator _mediator;
/// <summary>
/// Initializes a new instance of the <see cref="UserController"/> class.
@@ -26,13 +30,15 @@ public class UserController : BaseController
/// <param name="userService">Service for user-related operations.</param>
/// <param name="jwtUtils">Utility for JWT token operations.</param>
/// <param name="webhookService">Service for webhook operations.</param>
/// <param name="mediator">Mediator for handling commands.</param>
public UserController(IConfiguration config, IUserService userService, IJwtUtils jwtUtils,
IWebhookService webhookService)
IWebhookService webhookService, IMediator mediator)
: base(userService)
{
_config = config;
_jwtUtils = jwtUtils;
_webhookService = webhookService;
_mediator = mediator;
}
/// <summary>
@@ -158,7 +164,7 @@ public class UserController : BaseController
var user = await GetUser();
// Map API request to DTO
// Note: IsGmxEnabled and DefaultExchange are not updatable via settings endpoint
var settingsDto = new Managing.Application.Abstractions.Models.UserSettingsDto
var settingsDto = new UserSettingsDto
{
LowEthAmountAlert = settings.LowEthAmountAlert,
EnableAutoswap = settings.EnableAutoswap,
@@ -174,4 +180,17 @@ public class UserController : BaseController
var updatedUser = await _userService.UpdateUserSettings(user, settingsDto);
return Ok(updatedUser);
}
/// <summary>
/// Updates the agent summary by refreshing balance data and recalculating metrics.
/// Should be called after a topup/deposit to ensure the balance is up to date.
/// </summary>
/// <returns>Success response.</returns>
[HttpPost("update-agent-summary")]
public async Task<ActionResult> UpdateAgentSummary()
{
var user = await GetUser();
await _mediator.Send(new UpdateAgentSummaryCommand(user));
return Ok(new { message = "Agent summary updated successfully" });
}
}