Add GameVersion domain and login validation
This commit is contained in:
31
RecNet.Domain/GameVersions/GameVersion.cs
Normal file
31
RecNet.Domain/GameVersions/GameVersion.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using RecNet.Domain.Exceptions;
|
||||
|
||||
namespace RecNet.Domain.GameVersions;
|
||||
|
||||
public class GameVersion
|
||||
{
|
||||
private GameVersion()
|
||||
{
|
||||
}
|
||||
|
||||
private GameVersion(string version, bool isValid)
|
||||
{
|
||||
Version = RequireValue(version, nameof(version));
|
||||
IsValid = isValid;
|
||||
}
|
||||
|
||||
public string Version { get; private set; } = string.Empty;
|
||||
public bool IsValid { get; private set; }
|
||||
|
||||
public static GameVersion Create(string version, bool isValid)
|
||||
=> new(version, isValid);
|
||||
|
||||
public void MarkValid()
|
||||
=> IsValid = true;
|
||||
|
||||
public void MarkInvalid()
|
||||
=> IsValid = false;
|
||||
|
||||
private static string RequireValue(string value, string parameterName)
|
||||
=> !string.IsNullOrWhiteSpace(value) ? value : throw new DomainException($"{parameterName} is required.");
|
||||
}
|
||||
12
RecNet.Domain/GameVersions/IGameVersionRepository.cs
Normal file
12
RecNet.Domain/GameVersions/IGameVersionRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace RecNet.Domain.GameVersions;
|
||||
|
||||
public interface IGameVersionRepository
|
||||
{
|
||||
Task<GameVersion?> GetAsync(string version, CancellationToken ct = default);
|
||||
|
||||
async Task<bool> IsValidAsync(string version, CancellationToken ct = default)
|
||||
{
|
||||
var gameVersion = await GetAsync(version, ct);
|
||||
return gameVersion?.IsValid == true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user