Add more errors
This commit is contained in:
@@ -47,6 +47,7 @@ public class DataController : ControllerBase
|
|||||||
/// <param name="accountService">Service for account management.</param>
|
/// <param name="accountService">Service for account management.</param>
|
||||||
/// <param name="cacheService">Service for caching data.</param>
|
/// <param name="cacheService">Service for caching data.</param>
|
||||||
/// <param name="statisticService">Service for statistical analysis.</param>
|
/// <param name="statisticService">Service for statistical analysis.</param>
|
||||||
|
/// <param name="agentService">Service for agents</param>
|
||||||
/// <param name="hubContext">SignalR hub context for real-time communication.</param>
|
/// <param name="hubContext">SignalR hub context for real-time communication.</param>
|
||||||
/// <param name="mediator">Mediator for handling commands and queries.</param>
|
/// <param name="mediator">Mediator for handling commands and queries.</param>
|
||||||
/// <param name="tradingService">Service for trading operations.</param>
|
/// <param name="tradingService">Service for trading operations.</param>
|
||||||
@@ -451,6 +452,11 @@ public class DataController : ControllerBase
|
|||||||
[HttpGet("GetUserStrategies")]
|
[HttpGet("GetUserStrategies")]
|
||||||
public async Task<ActionResult<List<UserStrategyDetailsViewModel>>> GetUserStrategies(string agentName)
|
public async Task<ActionResult<List<UserStrategyDetailsViewModel>>> GetUserStrategies(string agentName)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(agentName))
|
||||||
|
{
|
||||||
|
return BadRequest("Agent name cannot be null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
// Get all strategies for the specified user
|
// Get all strategies for the specified user
|
||||||
var userStrategies = await _mediator.Send(new GetUserStrategiesCommand(agentName));
|
var userStrategies = await _mediator.Send(new GetUserStrategiesCommand(agentName));
|
||||||
|
|
||||||
@@ -476,6 +482,16 @@ public class DataController : ControllerBase
|
|||||||
[HttpGet("GetUserStrategy")]
|
[HttpGet("GetUserStrategy")]
|
||||||
public async Task<ActionResult<UserStrategyDetailsViewModel>> GetUserStrategy(string agentName, string strategyName)
|
public async Task<ActionResult<UserStrategyDetailsViewModel>> GetUserStrategy(string agentName, string strategyName)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(agentName))
|
||||||
|
{
|
||||||
|
return BadRequest("Agent name cannot be null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(strategyName))
|
||||||
|
{
|
||||||
|
return BadRequest("Strategy name cannot be null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
// Get the specific strategy for the user
|
// Get the specific strategy for the user
|
||||||
var strategy = await _mediator.Send(new GetUserStrategyCommand(agentName, strategyName));
|
var strategy = await _mediator.Send(new GetUserStrategyCommand(agentName, strategyName));
|
||||||
|
|
||||||
|
|||||||
@@ -56,14 +56,12 @@ public class UserService : IUserService
|
|||||||
|
|
||||||
if (!_authorizedAddresses.Any(a => string.Equals(a, recoveredAddress, StringComparison.OrdinalIgnoreCase)))
|
if (!_authorizedAddresses.Any(a => string.Equals(a, recoveredAddress, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
_logger.LogWarning($"Address {recoveredAddress} not authorized");
|
throw new Exception($"Address {recoveredAddress} not authorized");
|
||||||
throw new Exception("Address not authorized");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recoveredAddress == null || !recoveredAddress.Equals(address))
|
if (recoveredAddress == null || !recoveredAddress.Equals(address))
|
||||||
{
|
{
|
||||||
_logger.LogWarning($"Address {recoveredAddress} not corresponding");
|
throw new Exception($"Address {recoveredAddress} not corresponding");
|
||||||
throw new Exception("Address not corresponding");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if account exist
|
// Check if account exist
|
||||||
@@ -72,7 +70,7 @@ public class UserService : IUserService
|
|||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
if (!user.Name.Equals(name))
|
if (!user.Name.Equals(name))
|
||||||
throw new Exception("Name not corresponding");
|
throw new Exception("Name not corresponding to user " + name);
|
||||||
|
|
||||||
// User and account found
|
// User and account found
|
||||||
user.Accounts = _accountService.GetAccountsByUser(user).ToList();
|
user.Accounts = _accountService.GetAccountsByUser(user).ToList();
|
||||||
@@ -82,7 +80,7 @@ public class UserService : IUserService
|
|||||||
|
|
||||||
if (account == null)
|
if (account == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Account not found");
|
throw new Exception("Account not found for address " + recoveredAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
Reference in New Issue
Block a user