Add profiles domain, infra, API endpoints
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
namespace RecNet.Domain;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
7
RecNet.Domain/Common/PlatformType.cs
Normal file
7
RecNet.Domain/Common/PlatformType.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace RecNet.Domain.Common;
|
||||
|
||||
public enum PlatformType
|
||||
{
|
||||
Steamworks = 0,
|
||||
Meta = 1,
|
||||
}
|
||||
62
RecNet.Domain/Entities/Profiles/Profile.cs
Normal file
62
RecNet.Domain/Entities/Profiles/Profile.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using RecNet.Domain.Common;
|
||||
using RecNet.Domain.Exceptions;
|
||||
|
||||
namespace RecNet.Domain.Entities.Profiles;
|
||||
|
||||
public class Profile
|
||||
{
|
||||
public const int MinNameLength = 3;
|
||||
public const int MaxNameLength = 32;
|
||||
|
||||
private Profile(
|
||||
string name,
|
||||
PlatformType platform,
|
||||
string platformId)
|
||||
{
|
||||
SetName(name);
|
||||
|
||||
Platform = platform;
|
||||
PlatformId = RequireValue(platformId, nameof(platformId));
|
||||
|
||||
CreatedAt = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public Guid ProfileId { get; } = Guid.NewGuid();
|
||||
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public PlatformType Platform { get; private set; }
|
||||
public string PlatformId { get; private set; }
|
||||
public List<string> DeviceIds { get; private set; } = [];
|
||||
|
||||
public DateTimeOffset CreatedAt { get; private set; }
|
||||
|
||||
public static Profile Create(
|
||||
string name,
|
||||
PlatformType platform,
|
||||
string platformId)
|
||||
=> new(name, platform, platformId);
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
var requiredName = RequireValue(name, nameof(name));
|
||||
|
||||
if (requiredName.Length is < MinNameLength or > MaxNameLength)
|
||||
throw new DomainException($"Username must be between {MinNameLength} and {MaxNameLength} characters long.");
|
||||
|
||||
Name = requiredName;
|
||||
}
|
||||
|
||||
public void AddDeviceId(string deviceId)
|
||||
{
|
||||
deviceId = RequireValue(deviceId, nameof(deviceId));
|
||||
|
||||
if (DeviceIds.Contains(deviceId))
|
||||
return;
|
||||
|
||||
DeviceIds.Add(deviceId);
|
||||
}
|
||||
|
||||
private static string RequireValue(string value, string parameterName)
|
||||
=> !string.IsNullOrWhiteSpace(value) ? value : throw new DomainException($"{parameterName} is required.");
|
||||
}
|
||||
15
RecNet.Domain/Exceptions/DomainException.cs
Normal file
15
RecNet.Domain/Exceptions/DomainException.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace RecNet.Domain.Exceptions;
|
||||
|
||||
public class DomainException : Exception
|
||||
{
|
||||
public DomainException()
|
||||
{ }
|
||||
|
||||
public DomainException(string message)
|
||||
: base(message)
|
||||
{ }
|
||||
|
||||
public DomainException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
}
|
||||
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Entities\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
16
RecNet.Domain/Repositories/IProfileRepository.cs
Normal file
16
RecNet.Domain/Repositories/IProfileRepository.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using RecNet.Domain.Common;
|
||||
using RecNet.Domain.Entities.Profiles;
|
||||
|
||||
namespace RecNet.Domain.Repositories;
|
||||
|
||||
public interface IProfileRepository
|
||||
{
|
||||
Task<Profile?> GetByIdAsync(Guid profileId, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<Profile>> GetByIdsAsync(List<Guid> profileIds, CancellationToken ct = default);
|
||||
|
||||
Task<Profile?> GetByPlatform(PlatformType platform, string platformId, CancellationToken ct = default);
|
||||
|
||||
Task AddAsync(Profile profile, CancellationToken ct = default);
|
||||
|
||||
Task SaveChangesAsync(CancellationToken ct = default);
|
||||
}
|
||||
Reference in New Issue
Block a user