Add GetBotByUserIdAndNameAsync method to IBotService and BotService
- Implemented GetBotByUserIdAndNameAsync in IBotService and BotService to retrieve a bot by user ID and name. - Updated GetUserStrategyCommandHandler to utilize the new method for fetching strategies based on user ID. - Added corresponding method in IBotRepository and PostgreSqlBotRepository for database access.
This commit is contained in:
@@ -19,6 +19,7 @@ public interface IBotService
|
||||
Task<IEnumerable<Bot>> GetBotsByUser(int id);
|
||||
Task<IEnumerable<Bot>> GetBotsByIdsAsync(IEnumerable<Guid> botIds);
|
||||
Task<Bot> GetBotByName(string name);
|
||||
Task<Bot> GetBotByUserIdAndNameAsync(int userId, string name);
|
||||
Task<Bot> GetBotByIdentifier(Guid identifier);
|
||||
Task<LightSignal> CreateManualSignalAsync(Guid identifier, TradeDirection direction);
|
||||
Task<Position> ClosePositionAsync(Guid identifier, Guid positionId);
|
||||
|
||||
@@ -289,6 +289,11 @@ namespace Managing.Application.ManageBot
|
||||
return await _botRepository.GetBotByNameAsync(name);
|
||||
}
|
||||
|
||||
public async Task<Bot> GetBotByUserIdAndNameAsync(int userId, string name)
|
||||
{
|
||||
return await _botRepository.GetBotByUserIdAndNameAsync(userId, name);
|
||||
}
|
||||
|
||||
public async Task<Bot> GetBotByIdentifier(Guid identifier)
|
||||
{
|
||||
return await _botRepository.GetBotByIdentifierAsync(identifier);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Domain.Bots;
|
||||
using MediatR;
|
||||
@@ -11,19 +12,28 @@ namespace Managing.Application.ManageBot
|
||||
public class GetUserStrategyCommandHandler : IRequestHandler<GetUserStrategyCommand, Bot>
|
||||
{
|
||||
private readonly IBotService _botService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public GetUserStrategyCommandHandler(IBotService botService)
|
||||
public GetUserStrategyCommandHandler(IBotService botService, IUserService userService)
|
||||
{
|
||||
_botService = botService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task<Bot> Handle(GetUserStrategyCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var strategy = await _botService.GetBotByName(request.StrategyName);
|
||||
var user = await _userService.GetUserByAgentName(request.AgentName);
|
||||
if (user == null)
|
||||
{
|
||||
throw new Exception($"User with agent name {request.AgentName} not found");
|
||||
}
|
||||
|
||||
var strategy = await _botService.GetBotByUserIdAndNameAsync(user.Id, request.StrategyName);
|
||||
if (strategy == null)
|
||||
{
|
||||
throw new Exception($"Strategy with name {request.StrategyName} not found");
|
||||
throw new Exception($"Strategy with name {request.StrategyName} not found for agent {request.AgentName}");
|
||||
}
|
||||
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user