Add server configuration service and repo
This commit is contained in:
@@ -20,7 +20,10 @@ public class ProfileRepository(DatabaseContext dbContext) : IProfileRepository
|
||||
.Where(x => profileIds.Contains(x.ProfileId))
|
||||
.ToListAsync(ct);
|
||||
|
||||
public Task<Profile?> GetByPlatform(PlatformType platform, string platformId, CancellationToken ct = default)
|
||||
public Task<Profile?> GetByPlatform(
|
||||
PlatformType platform,
|
||||
string platformId,
|
||||
CancellationToken ct = default)
|
||||
=> dbContext.Profiles
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.Platform == platform &&
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using RecNet.Domain.Entities.Configuration;
|
||||
using RecNet.Domain.Repositories;
|
||||
|
||||
namespace RecNet.Infrastructure.Persistence.Repositories;
|
||||
|
||||
public class ServerConfigRepository(DatabaseContext dbContext) : IServerConfigRepository
|
||||
{
|
||||
public Task<ServerConfig?> GetAsync(string key, CancellationToken ct = default)
|
||||
=> dbContext.ServerConfigs
|
||||
.FirstOrDefaultAsync(x => x.Key == key, ct);
|
||||
|
||||
public async Task SetAsync(string key, string value, CancellationToken ct = default)
|
||||
{
|
||||
var config = await GetAsync(key, ct);
|
||||
|
||||
if (config is null)
|
||||
{
|
||||
config = ServerConfig.Create(key, value);
|
||||
await dbContext.ServerConfigs.AddAsync(config, ct);
|
||||
return;
|
||||
}
|
||||
|
||||
config.SetValue(value);
|
||||
}
|
||||
|
||||
public Task SaveChangesAsync(CancellationToken ct = default)
|
||||
=> dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
Reference in New Issue
Block a user