Перепиливание под чистый DDD
This commit is contained in:
52
backend/src/Modules/Profiles/Domain/Profile.cs
Normal file
52
backend/src/Modules/Profiles/Domain/Profile.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using System;
|
||||
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
public sealed class Profile : AggregateRoot<Guid>
|
||||
{
|
||||
public string Username { get; private set; }
|
||||
public string DisplayName { get; private set; }
|
||||
public string? Bio { get; private set; }
|
||||
public string? Avatar { get; private set; }
|
||||
public DateTime? Birthday { get; private set; }
|
||||
public bool HideStoryViews { get; private set; }
|
||||
public string Profilename => Username;
|
||||
public string Name => DisplayName;
|
||||
public string AvatarUrl => Avatar;
|
||||
public bool IsPrivate => false;
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
public int FollowersCount => 0;
|
||||
public int FollowingCount => 0;
|
||||
public int FriendsCount => 0;
|
||||
|
||||
private Profile(Guid id, string username, string displayName, string? bio = null)
|
||||
: base(id)
|
||||
{
|
||||
Username = username;
|
||||
DisplayName = displayName;
|
||||
Bio = bio;
|
||||
}
|
||||
|
||||
public static Profile Create(Guid userId, string username, string displayName, string? bio = null)
|
||||
{
|
||||
return new Profile(userId, username, displayName, bio);
|
||||
}
|
||||
|
||||
public void UpdateProfile(string displayName, string? bio, DateTime? birthday)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Bio = bio;
|
||||
Birthday = birthday;
|
||||
}
|
||||
|
||||
public void UpdateAvatar(string? avatarUrl)
|
||||
{
|
||||
Avatar = avatarUrl;
|
||||
}
|
||||
|
||||
public void UpdateSettings(bool hideStoryViews)
|
||||
{
|
||||
HideStoryViews = hideStoryViews;
|
||||
}
|
||||
}
|
||||
10
backend/src/Modules/Profiles/Domain/ProfilesErrors.cs
Normal file
10
backend/src/Modules/Profiles/Domain/ProfilesErrors.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
using Knot.Shared.Kernel;
|
||||
public static class ProfilesErrors
|
||||
{
|
||||
public static readonly Error ProfileNotFound = new("Profile.NotFound", "Profile not found");
|
||||
}
|
||||
public static class IdentityErrors
|
||||
{
|
||||
public static readonly Error UserNotFound = new("Profile.NotFound", "Profile not found");
|
||||
}
|
||||
Reference in New Issue
Block a user