Add backup management
This commit is contained in:
41
src/Managing.Infrastructure.Database/BotRepository.cs
Normal file
41
src/Managing.Infrastructure.Database/BotRepository.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Infrastructure.Databases.MongoDb;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Abstractions;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Collections;
|
||||
|
||||
namespace Managing.Infrastructure.Databases;
|
||||
|
||||
public class BotRepository : IBotRepository
|
||||
{
|
||||
private readonly IMongoRepository<BotDto> _botRepository;
|
||||
|
||||
public BotRepository(IMongoRepository<BotDto> botRepository)
|
||||
{
|
||||
_botRepository = botRepository;
|
||||
}
|
||||
|
||||
public async Task InsertBotAsync(BotBackup bot)
|
||||
{
|
||||
await _botRepository.InsertOneAsync(MongoMappers.Map(bot));
|
||||
}
|
||||
|
||||
public IEnumerable<BotBackup> GetBots()
|
||||
{
|
||||
var bots = _botRepository.FindAll();
|
||||
return bots.Select(b => MongoMappers.Map(b));
|
||||
}
|
||||
|
||||
public async Task UpdateBackupBot(BotBackup bot)
|
||||
{
|
||||
var b = _botRepository.FindOne(b => b.Name == bot.Name);
|
||||
var dto = MongoMappers.Map(bot);
|
||||
dto.Id = b.Id;
|
||||
_botRepository.Update(dto);
|
||||
}
|
||||
|
||||
public void DeleteBotByName(string name)
|
||||
{
|
||||
var bot = _botRepository.FindOne(b => b.Name == name);
|
||||
_botRepository.DeleteById(bot.Id.ToString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Managing.Infrastructure.Databases.MongoDb.Attributes;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Configurations;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.MongoDb.Collections;
|
||||
|
||||
[BsonCollection("Bots")]
|
||||
public class BotDto : Document
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Data { get; set; }
|
||||
public BotType BotType { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using Managing.Domain.Accounts;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Domain.MoneyManagements;
|
||||
using Managing.Domain.Scenarios;
|
||||
@@ -650,5 +652,29 @@ public static class MongoMappers
|
||||
};
|
||||
}
|
||||
|
||||
internal static BotDto Map(BotBackup bot)
|
||||
{
|
||||
if (bot == null) return null;
|
||||
|
||||
return new BotDto
|
||||
{
|
||||
Name = bot.Name,
|
||||
BotType = bot.BotType,
|
||||
Data = bot.Data,
|
||||
};
|
||||
}
|
||||
|
||||
internal static BotBackup Map(BotDto b)
|
||||
{
|
||||
if (b == null) return null;
|
||||
|
||||
return new BotBackup
|
||||
{
|
||||
Name = b.Name,
|
||||
BotType = b.BotType,
|
||||
Data = b.Data
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user