Files
Artemy 6d1c53beeb Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
2026-07-16 19:27:45 +07:00

79 lines
2.3 KiB
C#

using Govor.Domain;
using Govor.Domain.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Profiles;
public class ProfileService : IProfileService
{
private readonly ILogger<ProfileService> _logger;
private readonly GovorDbContext _context;
public ProfileService(GovorDbContext context, ILogger<ProfileService> logger)
{
_context = context;
_logger = logger;
}
public async Task<Result<UserProfile>> GetUserProfileAsync(Guid userId)
{
_logger.LogInformation("Getting user {UserId} profile", userId);
var profile = await _context.Users
.AsNoTracking()
.Where(u => u.Id == userId)
.Select(user => new UserProfile
{
Id = user.Id,
Username = user.Username,
Description = user.Description,
IconId = user.IconId
})
.FirstOrDefaultAsync();
if (profile is null)
{
return Result<UserProfile>.Failure(CreateNotFoundError(userId));
}
return profile;
}
public async Task<Result> SetDescription(string description, Guid userId)
{
_logger.LogInformation("Updating description for user {UserId}", userId);
var updatedRows = await _context.Users
.Where(u => u.Id == userId)
.ExecuteUpdateAsync(setters => setters.SetProperty(u => u.Description, description));
if (updatedRows == 0)
{
return Result.Failure(CreateNotFoundError(userId));
}
return Result.Success();
}
public async Task<Result> SetNewIcon(Guid userId, Guid iconId)
{
_logger.LogInformation("Updating icon for user {UserId}", userId);
var updatedRows = await _context.Users
.Where(u => u.Id == userId)
.ExecuteUpdateAsync(setters => setters.SetProperty(u => u.IconId, iconId));
if (updatedRows == 0)
{
return Result.Failure(CreateNotFoundError(userId));
}
return Result.Success();
}
private static Error CreateNotFoundError(Guid userId) =>
new("Profile.UserNotFound", $"User with ID {userId} was not found.");
}