36 lines
No EOL
989 B
C#
36 lines
No EOL
989 B
C#
using SurveyBackend.Core.Models;
|
|
using SurveyBackend.Core.Repositories;
|
|
using SurveyBackend.Core.Services;
|
|
using SurveyBackend.Services.Exceptions;
|
|
|
|
namespace SurveyBackend.Services.Services;
|
|
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
public UserService(IUserRepository userRepository)
|
|
{
|
|
_userRepository = userRepository;
|
|
}
|
|
|
|
public async Task<User> GetUserByEmail(string email)
|
|
{
|
|
return await _userRepository.GetUserByEmail(email) ?? throw new NotFoundException("Email not found");
|
|
}
|
|
|
|
public async Task<User> GetUserById(int id)
|
|
{
|
|
return await _userRepository.GetByIdAsync(id) ?? throw new NotFoundException("User not found");
|
|
}
|
|
|
|
public async Task<bool> IsEmailTaken(string email)
|
|
{
|
|
return await _userRepository.GetUserByEmail(email) != null;
|
|
}
|
|
|
|
public async Task CreateUserAsync(User user)
|
|
{
|
|
await _userRepository.AddAsync(user);
|
|
}
|
|
} |