Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Application/Features/Auth/Interfaces/IUserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IUserRepository
Task RegisterUserAsync(User user);
Task<User?> GetUserByEmailAsync(string email);
Task<bool> IsUserExistsByIdAsync(Guid userId);
Task<bool> IsUserExistsByEmailAsync(string email);
Task SaveChangesAsync();
Task<List<ViewUser>> GetAllUsersAsync();
Task<User?> GetUserByIdAsync(Guid userId);
Expand Down
5 changes: 5 additions & 0 deletions Application/Features/Auth/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Application.Features.Auth.Interfaces;
using Domain.Entities;
using Domain.Enums;
using Domain.Exceptions;

namespace Application.Features.Auth.Services;

Expand Down Expand Up @@ -34,6 +35,10 @@ public UserService(IUserRepository repository, IJwtTokenService jwtTokenGenerato
public async Task<string> RegisterUserAsync(RegisterUserRequestDto registerUserRequestDto)
{
var password = _passwordHasher.Hash(registerUserRequestDto.Password);

if (await _userRepository.IsUserExistsByEmailAsync(registerUserRequestDto.Email))
throw new DuplicateUserException("Email already exists");

var user = new User(registerUserRequestDto.FullName, registerUserRequestDto.Email,
registerUserRequestDto.PhoneNumber, password);
await _userRepository.RegisterUserAsync(user);
Expand Down
6 changes: 3 additions & 3 deletions Application/Features/Tenant/Services/TenantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TenantService(TenantRepositoryContract tenantRepository, IUSerContext use
_userRepository = userRepository;
}

public async Task<string> Register(RegisterTenantDTO dto)
public async Task<Guid> Register(RegisterTenantDTO dto)
{
//Todo: slug maker
// Todo : Date manager
Expand All @@ -41,7 +41,7 @@ public async Task<string> Register(RegisterTenantDTO dto)
user.AssignTenantToUser(tenant.Id);
await _tenantRepository.SaveAsync();

var tenantId = await _tenantRepository.GetCurrentTenantAsync();
return $"{tenant.Name} Registered belong to user {user.FullName} created";
// var tenantId = await _tenantRepository.GetCurrentTenantAsync();
return tenant.Id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Application.Features.Tenant.Services;

public interface TenantServiceContract
{
Task<string> Register(RegisterTenantDTO dto);
Task<Guid> Register(RegisterTenantDTO dto);
}
8 changes: 8 additions & 0 deletions Domain/Exceptions/DupplicateUserExeption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Domain.Exceptions;

public class DuplicateUserException:Exception
{
public DuplicateUserException(string message) :base(message)
{
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading