diff --git a/src/Core/Application/Members/IMemberService.cs b/src/Core/Application/Members/IMemberService.cs index f14ce43..aa4105c 100644 --- a/src/Core/Application/Members/IMemberService.cs +++ b/src/Core/Application/Members/IMemberService.cs @@ -10,7 +10,7 @@ public interface IMemberService : ITransientService //Task GetCountAsync(CancellationToken cancellationToken); - //Task GetAsync(string userId, CancellationToken cancellationToken); + Task GetAsync(string userId, CancellationToken cancellationToken); /*Task> GetRolesAsync(string userId, CancellationToken cancellationToken); Task AssignRolesAsync(string userId, UserRolesRequest request, CancellationToken cancellationToken); diff --git a/src/Core/Application/Participants/CreateGuestParticipantRequest .cs b/src/Core/Application/Participants/CreateGuestParticipantRequest .cs new file mode 100644 index 0000000..e9ba8e9 --- /dev/null +++ b/src/Core/Application/Participants/CreateGuestParticipantRequest .cs @@ -0,0 +1,55 @@ +using EventManagment.Application.Members; +using EventManagment.Domain.Common.Events; +using EventManagment.Domain.Events; + +namespace EventManagment.Application.Participants; + +public class CreateGuestParticipantRequest : IRequest +{ + public Guid EventId { get; set; } + public string MemberNumber { get; set; } = default!; + public string FirstName { get; set; } = default!; + public string LastName { get; set; } = default!; + public string Address { get; set; } = default!; + public string Gender { get; set; } = default!; + public string? Email { get; set; } + public string PhoneNumber { get; set; } = default!; + public string? Title { get; set; } + +} + +public class CreateGuestParticipantRequestHandler : IRequestHandler +{ + private readonly IRepository _repository; + private readonly IFileStorageService _file; + private readonly IMemberService _memberService; + + public CreateGuestParticipantRequestHandler(IRepository repository, IFileStorageService file, IMemberService memberService) => + (_repository, _file, _memberService) = (repository, file, memberService); + + public async Task Handle(CreateGuestParticipantRequest request, CancellationToken cancellationToken) + { + // TODO: USE THE MEMBER NUMBER FROM THE REQUEST TO FETCH THE MEMBER INFORMATION FROM THE MEMBER SERVICE + var member = await _memberService.GetAsync(request.MemberNumber, cancellationToken); + // TODO: HANDLE WHEN THE MEMBER NUMBER DOES NOT EXIST FROM THE MEMBER SERVICE + if(member is null) + { + throw new ArgumentNullException($"Invalid Member Number{request.MemberNumber}"); + } + // TODO: IMPLEMENT A PRIVATE METHOD IN AN HELPER CLASS TO GENERATE REGISTRATION NUMBER FOR THE PARTICIPANT BASED ON THE EVENT + + // TODO: THE PARTICIPANT OBJECT SHOULD BE CREATED FROM THE DOMAIN CONSTRUCTOR IN THE PARTICIPANT CLASS. + var participant = new Participant(request.MemberNumber,request.FirstName, request.LastName, request.Address, + request.PhoneNumber, request.Email, request.Gender, request.Title, ParticipantType.Guest); + + // Add Domain Events to be raised after the commit + participant.DomainEvents.Add(EntityCreatedEvent.WithEntity(participant)); + + await _repository.AddAsync(participant, cancellationToken); + + // TODO: GENERATE TAG/TICKET DOWNLOAD LINK TO BE SENT VIA SMS OR EMAIL + // TODO: SEND AN SMS, WHATSAPP OR EMAIL MESSAGE TO THE REGISTERED PARTICIPANT, CALL AN INOTIFICATION SERVICE TO DO THIS. OR USE A BACKGROUND JOB , ADDING THE REGISTRATION TO A QUEUE + + return participant.Id; + } +} \ No newline at end of file diff --git a/src/Core/Domain/Events/Participant.cs b/src/Core/Domain/Events/Participant.cs index 1893b56..728591b 100644 --- a/src/Core/Domain/Events/Participant.cs +++ b/src/Core/Domain/Events/Participant.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Sockets; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -14,7 +15,7 @@ public class Participant : AuditableEntity, IAggregateRoot public ParticipantType ParticipantType { get; private set; } public string FirstName { get; private set; } = default!; public string LastName { get; private set; } = default!; - public string? Tiltle { get; private set; } + public string? Title { get; private set; } public string? Email { get; private set; } public string? PhoneNumber { get; private set; } public int? JamaatId { get; private set; } @@ -28,4 +29,28 @@ public class Participant : AuditableEntity, IAggregateRoot public DateTime? CheckInDate { get; private set; } // TODO: ADD DOMAIN CONSTRUCTOR TO CREATE PARTICIPANT + + public Participant(string memberNum, string firstName, string lastName, string address, string phoneNum, string email, string gender, string title, ParticipantType participant) + { + MemberNumber = memberNum; + RegistrationNumber = GenerateRandomNumber(); + FirstName = firstName; + LastName = lastName; + Address = address; + PhoneNumber = phoneNum; + Email = email; + Gender = gender; + Title = title; + ParticipantType = participant; + } + + public Participant() + { + + } + private static string GenerateRandomNumber() + { + var registrationNum = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 7); + return registrationNum; + } } diff --git a/src/Host/Controllers/Participants/ParticipantsController.cs b/src/Host/Controllers/Participants/ParticipantsController.cs index 132dcd4..7593192 100644 --- a/src/Host/Controllers/Participants/ParticipantsController.cs +++ b/src/Host/Controllers/Participants/ParticipantsController.cs @@ -25,4 +25,12 @@ public async Task GetAsync(Guid eventId, Guid participantId) { return await Mediator.Send(new GetParticipantByEventIdRequest(eventId, participantId)); } + + [HttpPost] + [MustHavePermission(FSHAction.Create, FSHResource.Participants)] + [OpenApiOperation("Register Guest Participant.", "")] + public Task CreateAsyn(CreateGuestParticipantRequest request) + { + return Mediator.Send(request); + } }