62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using MongoDB.Bson;
|
|
using MongoDB.Bson.Serialization.Attributes;
|
|
|
|
namespace Knot.Modules.Profiles.Domain;
|
|
|
|
/// <summary>
|
|
/// MongoDB-документ профиля пользователя.
|
|
/// Id совпадает с UserId из модуля Auth (Postgres).
|
|
/// </summary>
|
|
public sealed class ProfileDocument
|
|
{
|
|
[BsonId]
|
|
[BsonRepresentation(BsonType.String)]
|
|
public Guid Id { get; private set; }
|
|
|
|
public string Username { get; private set; }
|
|
|
|
public string DisplayName { get; private set; }
|
|
|
|
public string? Bio { get; private set; }
|
|
|
|
public string? AvatarUrl { get; private set; }
|
|
|
|
public DateTime? Birthday { get; private set; }
|
|
|
|
public bool HideStoryViews { get; private set; }
|
|
|
|
public DateTime CreatedAt { get; private set; }
|
|
|
|
#pragma warning disable CS8618
|
|
private ProfileDocument() { }
|
|
#pragma warning restore CS8618
|
|
|
|
private ProfileDocument(Guid id, string username, string displayName, string? bio)
|
|
{
|
|
Id = id;
|
|
Username = username;
|
|
DisplayName = displayName;
|
|
Bio = bio;
|
|
CreatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
public static ProfileDocument Create(Guid userId, string username, string displayName, string? bio = null)
|
|
=> new(userId, username, displayName, bio);
|
|
|
|
public void UpdateProfile(string displayName, string? bio, DateTime? birthday)
|
|
{
|
|
DisplayName = displayName;
|
|
Bio = bio;
|
|
Birthday = birthday;
|
|
}
|
|
|
|
public void UpdateAvatar(string? avatarUrl)
|
|
=> AvatarUrl = avatarUrl;
|
|
|
|
public void RemoveAvatar()
|
|
=> AvatarUrl = null;
|
|
|
|
public void UpdateSettings(bool hideStoryViews)
|
|
=> HideStoryViews = hideStoryViews;
|
|
}
|