Аватар

This commit is contained in:
Халимов Рустам
2026-04-05 01:27:58 +03:00
parent 53f193970c
commit e11240f78f
13 changed files with 133 additions and 47 deletions

View File

@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Profiles.Application.DTOs;
using Knot.Contracts.Profiles.Domain;
using Knot.Modules.Profiles.Domain;
using Knot.Modules.Profiles.Infrastructure.Mappings;
using Knot.Shared.Kernel;
using MongoDB.Bson;
@@ -76,17 +70,19 @@ internal class ProfileRepository : IProfileRepository
public async Task<Result<UserProfileDto>> UpdateAsync(UserProfileDto dto, CancellationToken ct = default)
{
var profile = await _profiles.Find(p => p.Id == dto.UserId).FirstOrDefaultAsync(ct);
if (profile is null)
var document = await _profiles.Find(p => p.Id == dto.UserId).FirstOrDefaultAsync(ct);
if (document is null)
return Result.Failure<UserProfileDto>(ProfilesErrors.ProfileNotFound);
profile.UpdateProfile(
dto.DisplayName ?? profile.DisplayName,
dto.About ?? profile.Bio,
document.UpdateProfile(
dto.DisplayName ?? document.DisplayName,
dto.About ?? document.Bio,
dto.Birthday);
await _profiles.ReplaceOneAsync(p => p.Id == dto.UserId, profile, new ReplaceOptions { IsUpsert = true }, ct);
return Result.Success(profile.ToDto());
document.UpdateAvatar(dto.Avatar);
await _profiles.ReplaceOneAsync(p => p.Id == dto.UserId, document, cancellationToken: ct);
return Result.Success(document.ToDto());
}
public async Task<Result> UpdateStatusAsync(Guid userId, bool isBanned, bool isDeleted, CancellationToken ct = default)