Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
akbaramd committed Dec 29, 2024
1 parent 298d50f commit 0211555
Show file tree
Hide file tree
Showing 52 changed files with 372 additions and 902 deletions.
2 changes: 1 addition & 1 deletion Nezam.EES.Shared/Application/Dto/PagiantedResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nezam.EES.Service.Identity.Application.Dto;
namespace Nezam.EEs.Shared.Application.Dto;

public class PaginatedResponse<T>
{
Expand Down
2 changes: 1 addition & 1 deletion Nezam.EES.Shared/Application/Dto/PaginatedRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;

namespace Nezam.EES.Service.Identity.Application.Dto;
namespace Nezam.EEs.Shared.Application.Dto;

public class PaginatedRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,4 @@ public UserCreatedEvent(UserId userId, string userName, string? email, UserProfi
Profile = profile;
}
}

public class UserNameUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public string NewUserName { get; }

public UserNameUpdatedEvent(UserId userId, string newUserName)
{
UserId = userId;
NewUserName = newUserName;
}
}

public class UserPasswordUpdatedEvent : DomainEvent
{
public UserId UserId { get; }

public UserPasswordUpdatedEvent(UserId userId)
{
UserId = userId;
}
}

public class UserEmailUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public string? NewEmail { get; }

public UserEmailUpdatedEvent(UserId userId, string? newEmail)
{
UserId = userId;
NewEmail = newEmail;
}
}

public class UserProfileUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public UserProfileValue? NewProfile { get; }

public UserProfileUpdatedEvent(UserId userId, UserProfileValue? newProfile)
{
UserId = userId;
NewProfile = newProfile;
}
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Payeh.SharedKernel.Domain.DomainEvents;

namespace Nezam.EEs.Shared.Domain.Identity.User.DomainEvents;

public class UserEmailUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public string? NewEmail { get; }

public UserEmailUpdatedEvent(UserId userId, string? newEmail)
{
UserId = userId;
NewEmail = newEmail;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Payeh.SharedKernel.Domain.DomainEvents;

namespace Nezam.EEs.Shared.Domain.Identity.User.DomainEvents;

public class UserNameUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public string NewUserName { get; }

public UserNameUpdatedEvent(UserId userId, string newUserName)
{
UserId = userId;
NewUserName = newUserName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Payeh.SharedKernel.Domain.DomainEvents;

namespace Nezam.EEs.Shared.Domain.Identity.User.DomainEvents;

public class UserPasswordUpdatedEvent : DomainEvent
{
public UserId UserId { get; }

public UserPasswordUpdatedEvent(UserId userId)
{
UserId = userId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Nezam.EEs.Shared.Domain.Identity.User.ValueObjects;
using Payeh.SharedKernel.Domain.DomainEvents;

namespace Nezam.EEs.Shared.Domain.Identity.User.DomainEvents;

public class UserProfileUpdatedEvent : DomainEvent
{
public UserId UserId { get; }
public UserProfileValue? NewProfile { get; }

public UserProfileUpdatedEvent(UserId userId, UserProfileValue? newProfile)
{
UserId = userId;
NewProfile = newProfile;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nezam.EES.Service.Identity.Application.Dto;
using Nezam.EEs.Shared.Application.Dto;

namespace Nezam.EES.Service.Identity.Application.UseCases.Roles.GetRoles;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Nezam.EES.Service.Identity.Application.Dto;
using Nezam.EES.Service.Identity.Application.Dto.Roles;
using Nezam.EEs.Shared.Application.Dto;

namespace Nezam.EES.Service.Identity.Application.UseCases.Roles.GetRoles;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override async Task HandleAsync(CancellationToken ct)
ThrowError("User not found.");
}

var deleteResult = await _userDomainService.DeleteAsync(existingUserResult.Data);
var deleteResult = await _userDomainService.SoftDeleteAsync(existingUserResult.Data);

if (deleteResult.IsFailure)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public override async Task HandleAsync(GetUsersRequest req, CancellationToken ct
{
string searchTerm = req.Search.Trim();
query = query.Where(u =>
u.IsSoftDeleted == false &&
u.Email != null &&
(u.UserName.Value.Contains(searchTerm) || u.Email.Value.Contains(searchTerm)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nezam.EES.Service.Identity.Application.Dto;
using Nezam.EEs.Shared.Application.Dto;

namespace Nezam.EES.Service.Identity.Application.UseCases.Users.GetUsers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Nezam.EES.Service.Identity.Application.Dto;
using Nezam.EES.Service.Identity.Application.Dto.Users;
using Nezam.EEs.Shared.Application.Dto;

namespace Nezam.EES.Service.Identity.Application.UseCases.Users.GetUsers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IUserDomainService
Task<PayehResult<UserEntity>> Create(UserEntity user);
Task<PayehResult> UpdateAsync(UserEntity user);
Task<PayehResult> DeleteAsync(UserEntity user);
Task<PayehResult> SoftDeleteAsync(UserEntity user);
Task<PayehResult<UserEntity>> GetUserByIdAsync(UserId userId);
Task<PayehResult<UserEntity>> GetUserByUsernameAsync(UserNameId username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ public async Task<PayehResult> DeleteAsync(UserEntity user)
await _userRepository.DeleteAsync(user, true); // Delete the user (with auto-save flag)
return PayehResult.Success();
}
public async Task<PayehResult> SoftDeleteAsync(UserEntity user)
{
if (user == null)
return PayehResult.Failure("User cannot be null.");

user.SoftDelete();
await _userRepository.UpdateAsync(user, true); // Delete the user (with auto-save flag)
return PayehResult.Success();
}
// Get a user by ID
public async Task<PayehResult<UserEntity>> GetUserByIdAsync(UserId userId)
{
Expand Down
6 changes: 6 additions & 0 deletions Nezam.EES.Slice.Identity/Domains/Users/UserEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class UserEntity : AggregateRoot
public UserEmailValue? Email { get; private set; }
public UserProfileValue? Profile { get; private set; }
public ICollection<UserTokenEntity> Tokens { get; private set; } = [];

public bool IsSoftDeleted { get; private set; } = false;

// Collection to hold assigned roles
public ICollection<RoleEntity> Roles { get; private set; } = [];
Expand Down Expand Up @@ -86,6 +88,10 @@ public void RemoveRole(RoleEntity role)
}
}

public void SoftDelete()
{
IsSoftDeleted = true;
}


// Method to check if the user has a specific role
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Nezam.EES.Slice.Secretariat.Domains.Documents.ValueObjects;
using Nezam.EES.Slice.Secretariat.Domains.Participant;

namespace Nezam.EES.Slice.Secretariat.Application.Dto;

public class DocumentDto
{
public DocumentId DocumentId { get; set; }
Expand Down Expand Up @@ -44,4 +46,4 @@ public static ParticipantDto FromEntity(Participant participant)
Name = participant.Name,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using Nezam.EES.Slice.Secretariat.Domains.Participant.Repositories;
using Payeh.SharedKernel.UnitOfWork;

namespace Nezam.EES.Slice.Secretariat.Applciation.DomainHandlers;
namespace Nezam.EES.Slice.Secretariat.Application.EventHandlers.Users;

public class UserCreatedEventHandler : INotificationHandler<UserCreatedEvent>
public class UserCreatedDomainEventHandler : INotificationHandler<UserCreatedEvent>
{
private readonly IParticipantRepository _participantRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;

public UserCreatedEventHandler(IParticipantRepository participantRepository, IUnitOfWorkManager unitOfWorkManager)
public UserCreatedDomainEventHandler(IParticipantRepository participantRepository, IUnitOfWorkManager unitOfWorkManager)
{
_participantRepository = participantRepository;
_unitOfWorkManager = unitOfWorkManager;
Expand Down Expand Up @@ -40,11 +40,14 @@ public async Task Handle(UserCreatedEvent notification, CancellationToken cancel
else
{
// Create a new participant
var newParticipant = new Participant(
$"{notification.Profile.FirstName} {notification.Profile.LastName}");
newParticipant.UpdateUserId(notification.UserId);
if (notification.Profile!=null)
{
var newParticipant = new Participant(
$"{notification.Profile.FirstName} {notification.Profile.LastName}");
newParticipant.UpdateUserId(notification.UserId);

await _participantRepository.AddAsync(newParticipant, autoSave: true);
await _participantRepository.AddAsync(newParticipant, autoSave: true);
}
}

await uow.CommitAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using MediatR;
using Nezam.EEs.Shared.Domain.Identity.User.DomainEvents;
using Nezam.EES.Slice.Secretariat.Domains.Participant;
using Nezam.EES.Slice.Secretariat.Domains.Participant.Repositories;
using Payeh.SharedKernel.UnitOfWork;

namespace Nezam.EES.Slice.Secretariat.Application.EventHandlers.Users;

public class UserProfileUpdatedDomainEventHandler : INotificationHandler<UserProfileUpdatedEvent>
{
private readonly IParticipantRepository _participantRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;

public UserProfileUpdatedDomainEventHandler(IParticipantRepository participantRepository,
IUnitOfWorkManager unitOfWorkManager)
{
_participantRepository = participantRepository;
_unitOfWorkManager = unitOfWorkManager;
}

public async Task Handle(UserProfileUpdatedEvent notification, CancellationToken cancellationToken)
{
using var uow = _unitOfWorkManager.Begin();

try
{
// Check if a participant already exists for the given user ID
var existingParticipant = await _participantRepository.FindOneAsync(
p => p.UserId == notification.UserId);

if (existingParticipant != null)
{
// Update the existing participant
if (notification.NewProfile != null)
{
existingParticipant.UpdateName(
$"{notification.NewProfile.FirstName} {notification.NewProfile.LastName}");
await _participantRepository.UpdateAsync(existingParticipant, autoSave: true);
}
}
else
{
// Create a new participant
if (notification.NewProfile != null)
{
var newParticipant = new Participant(
$"{notification.NewProfile.FirstName} {notification.NewProfile.LastName}");
newParticipant.UpdateUserId(notification.UserId);
await _participantRepository.AddAsync(newParticipant, autoSave: true);
}
}
await uow.CommitAsync(cancellationToken);
}
catch (Exception ex)
{
await uow.RollbackAsync(cancellationToken);
throw new InvalidOperationException("Failed to handle UserCreatedEvent", ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Nezam.EES.Slice.Secretariat.Application.UseCases.Documents.CreateDocument;

public record CreateDocumentRequest
(
string Title,string Content,Guid ReceiverParticipantId
);
Loading

0 comments on commit 0211555

Please sign in to comment.