Refactor app architecture and clean local artifacts
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using Backend.Data;
|
||||
using Backend.Domain;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public sealed class AdminAuditRepository(AwardsDbContext dbContext) : IAdminAuditRepository
|
||||
{
|
||||
public void Add(AdminAuditEntry entry) => dbContext.AdminAuditEntries.Add(entry);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Backend.Domain;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public interface IAdminAuditRepository
|
||||
{
|
||||
void Add(AdminAuditEntry entry);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Backend.Domain;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public interface IRiskFlagRepository
|
||||
{
|
||||
Task<bool> ExistsOpenRecentAsync(
|
||||
int? seasonId,
|
||||
string? twitchUserId,
|
||||
string source,
|
||||
string type,
|
||||
string clientIp,
|
||||
DateTimeOffset threshold,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
void Add(RiskFlag riskFlag);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Backend.Domain;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public interface IUserSessionRepository
|
||||
{
|
||||
Task<UserSession?> GetActiveByTokenAsync(string token, CancellationToken cancellationToken = default);
|
||||
Task<int> CountRecentSessionsFromIpAsync(string ipAddress, DateTimeOffset since, CancellationToken cancellationToken = default);
|
||||
void Add(UserSession session);
|
||||
Task SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Backend.Data;
|
||||
using Backend.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public sealed class RiskFlagRepository(AwardsDbContext dbContext) : IRiskFlagRepository
|
||||
{
|
||||
public Task<bool> ExistsOpenRecentAsync(
|
||||
int? seasonId,
|
||||
string? twitchUserId,
|
||||
string source,
|
||||
string type,
|
||||
string clientIp,
|
||||
DateTimeOffset threshold,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
dbContext.RiskFlags.AnyAsync(
|
||||
item => item.Status == "open"
|
||||
&& item.Source == source
|
||||
&& item.Type == type
|
||||
&& item.TwitchUserId == twitchUserId
|
||||
&& item.CreatedFromIp == clientIp
|
||||
&& item.SeasonId == seasonId
|
||||
&& item.CreatedAt >= threshold,
|
||||
cancellationToken);
|
||||
|
||||
public void Add(RiskFlag riskFlag) => dbContext.RiskFlags.Add(riskFlag);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Backend.Data;
|
||||
using Backend.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Backend.Repositories;
|
||||
|
||||
public sealed class UserSessionRepository(AwardsDbContext dbContext) : IUserSessionRepository
|
||||
{
|
||||
public Task<UserSession?> GetActiveByTokenAsync(string token, CancellationToken cancellationToken = default) =>
|
||||
dbContext.UserSessions.FirstOrDefaultAsync(
|
||||
item => item.SessionToken == token && item.IsActive,
|
||||
cancellationToken);
|
||||
|
||||
public Task<int> CountRecentSessionsFromIpAsync(string ipAddress, DateTimeOffset since, CancellationToken cancellationToken = default) =>
|
||||
dbContext.UserSessions.CountAsync(
|
||||
item => item.CreatedFromIp == ipAddress && item.CreatedAt >= since,
|
||||
cancellationToken);
|
||||
|
||||
public void Add(UserSession session) => dbContext.UserSessions.Add(session);
|
||||
|
||||
public Task SaveChangesAsync(CancellationToken cancellationToken = default) =>
|
||||
dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
Reference in New Issue
Block a user