mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Govor.Application.Interfaces;
|
|
using Govor.Application.Profiles;
|
|
using Govor.Core.Repositories.Users;
|
|
using Govor.Data.Repositories.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Govor.Application.Services;
|
|
|
|
public class ProfileService : IProfileService
|
|
{
|
|
private readonly ILogger<ProfileService> _logger;
|
|
private readonly IUsersRepository _userRepository;
|
|
|
|
public ProfileService(IUsersRepository userRepository, ILogger<ProfileService> logger)
|
|
{
|
|
_userRepository = userRepository;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<UserProfile> GetUserProfileAsync(Guid userId)
|
|
{
|
|
_logger.LogInformation("Gettings user {userId} profile", userId);
|
|
try
|
|
{
|
|
var user = await _userRepository.FindByIdAsync(userId);
|
|
|
|
return new UserProfile
|
|
{
|
|
Id = user.Id,
|
|
Username = user.Username,
|
|
Description = user.Description,
|
|
IconId = user.IconId
|
|
};
|
|
}
|
|
catch (NotFoundByKeyException<Guid> ex)
|
|
{
|
|
throw new NotFoundException("User's profile cant be found with given id", ex);
|
|
}
|
|
}
|
|
|
|
public async Task SetDescription(string description, Guid userId)
|
|
{
|
|
var user = await _userRepository.FindByIdAsync(userId);
|
|
|
|
user.Description = description;
|
|
await _userRepository.UpdateAsync(user);
|
|
}
|
|
|
|
public async Task SetNewIcon(Guid userId, Guid iconId)
|
|
{
|
|
var user = await _userRepository.FindByIdAsync(userId);
|
|
|
|
user.IconId = iconId;
|
|
await _userRepository.UpdateAsync(user);
|
|
}
|
|
}
|