domBudg/back/Services/Domain/UserService.cs

50 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Contracts.DTO;
using Contracts.Mappers;
using Contracts.Repositories;
using Contracts.SearchModels;
using Contracts.Services;
using Contracts.ViewModels;
using Services.Support.Exceptions;
namespace Services.Domain;
public class UserService : IUserService
{
private readonly IUserRepo _userRepo;
public UserService(IUserRepo userRepo)
{
_userRepo = userRepo;
}
public async Task<UserViewModel> Delete(UserSearch search)
{
var user = await _userRepo.Delete(search);
if (user == null)
{
throw new UserNotFoundException($"Пользователь для удаления не найден");
}
return user.ToView();
}
public async Task<UserViewModel> GetDetails(UserSearch search)
{
var user = await _userRepo.Get(search);
if (user == null)
{
throw new UserNotFoundException($"Пользователь {search.Name} не найден");
}
return user.ToView();
}
public async Task<UserViewModel> UpdateUserData(UserDto user)
{
var updatedUser = await _userRepo.Update(user);
if (updatedUser == null)
{
throw new EntityNotFoundException("При обновлении не получилось найти пользователя с id = " + user.Id);
}
return updatedUser.ToView();
}
}