Skip to content

Commit

Permalink
feat: Merge ArtEvent Management into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
FranchescoSoto committed Nov 13, 2023
2 parents dd8ef06 + db56815 commit 65514b0
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Model.domainevents;
using PERUSTARS.AtEventManagement.Domain.Model.Repositories;
using PERUSTARS.AtEventManagement.Domain.Model.ValueObjects;
using PERUSTARS.Shared.Domain.Repositories;
using System;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -13,21 +15,34 @@ public class CancelArtEventCommandHandler : IRequestHandler<CancelArtEventComman
{
private readonly IArtEventRepository _artEventRepository;
private readonly IUnitOfWork _unitOfWork;
public CancelArtEventCommandHandler(IMediator mediator, IArtEventRepository artEventRepository, IUnitOfWork unitOfWork)
private readonly IPublisher _publisher;
public CancelArtEventCommandHandler(IMediator mediator, IArtEventRepository artEventRepository, IUnitOfWork unitOfWork,IPublisher publisher)
{
_artEventRepository = artEventRepository;
_unitOfWork = unitOfWork;
_publisher = publisher;

}
public async Task<string> Handle(CancelArtEventCommand request, CancellationToken cancellationToken)
{
ArtEvent artEvent = _artEventRepository.FindByIdAsync(request.id).Result;
if (artEvent != null)
{
artEvent.CurrentStatus = ArtEventStatus.CANCELLED;
_artEventRepository.Update(artEvent);
await _unitOfWork.CompleteAsync();
return "Event updated!!!";

artEvent.CurrentStatus = ArtEventStatus.CANCELLED;
_artEventRepository.Update(artEvent);
await _publisher.Publish(new ArtEventCancelledEvent()
{
Title = artEvent.Title,
Description = artEvent.Description,
Location = artEvent.Location,
EndDate = DateTime.Now,
CurrentStatus = ArtEventStatus.CANCELLED,
StartDate = (DateTime)artEvent.StartDateTime
});
await _unitOfWork.CompleteAsync();
return "Event updated!!!";

}
else {
return "The event with the given id doesn't exist";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Model.domainevents;
using PERUSTARS.AtEventManagement.Domain.Model.Repositories;
using PERUSTARS.AtEventManagement.Domain.Model.ValueObjects;
using PERUSTARS.Shared.Domain.Repositories;
Expand All @@ -13,10 +14,12 @@ public class RescheduleArtEventCommandHandler : IRequestHandler<RescheduleArtEve
{
private readonly IArtEventRepository _artEventRepository;
private readonly IUnitOfWork _unitOfWork;
public RescheduleArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork)
private readonly IPublisher _publisher;
public RescheduleArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork, IPublisher publisher)
{
_artEventRepository = artEventRepository;
_unitOfWork = unitOfWork;
_publisher = publisher;
}
public async Task<string> Handle(RescheduleArtEventCommand request, CancellationToken cancellationToken)
{
Expand All @@ -27,6 +30,14 @@ public async Task<string> Handle(RescheduleArtEventCommand request, Cancellation
artEvent.CurrentStatus = ArtEventStatus.RESCHEDULED;
_artEventRepository.Update(artEvent);
await _unitOfWork.CompleteAsync();
await _publisher.Publish(new ArtEventRescheduledEvent()
{
Title = artEvent.Title,
Description = artEvent.Description,
CurrentStatus = ArtEventStatus.RESCHEDULED,
StartDate = (System.DateTime)artEvent.StartDateTime,
Location = artEvent.Location
});
return "Art Event rescheduled!!";
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public async Task<string> Handle(StartArtEventCommand request, CancellationToken
else
{
artEvent.CurrentStatus = ArtEventStatus.STARTED;
_artEventRepository.Update(artEvent);
_unitOfWork.CompleteAsync();
return "Event started!!";

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.domainevents;
using PERUSTARS.CommunicationAndNotificationManagement.Domain.Model.Commands;
using PERUSTARS.CommunicationAndNotificationManagement.Domain.Services;
using System.Threading;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Application.artevents.events
{
public class ArtEventRescheduledEventHandler : INotificationHandler<ArtEventRescheduledEvent>
{
private readonly INotificationCommandService _notificationCommandService;
public ArtEventRescheduledEventHandler(INotificationCommandService notificationCommandService)
{
_notificationCommandService = notificationCommandService;
}
public async Task Handle(ArtEventRescheduledEvent notification, CancellationToken cancellationToken)
{
NotifyArtEventRescheduledCommand notifyArtEventRescheduledCommand = new NotifyArtEventRescheduledCommand();
notifyArtEventRescheduledCommand.Title = notification.Title;
notifyArtEventRescheduledCommand.Description = notification.Description;
notifyArtEventRescheduledCommand.Location = notification.Location;
notifyArtEventRescheduledCommand.StartDate = notification.StartDate;
notifyArtEventRescheduledCommand.CurrentStatus = notification.CurrentStatus;
await _notificationCommandService.ExecuteNotifyArtEventRescheduledCommand(notifyArtEventRescheduledCommand);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.domainevents;
using PERUSTARS.CommunicationAndNotificationManagement.Domain.Model.Commands;
using PERUSTARS.CommunicationAndNotificationManagement.Domain.Services;
using PERUSTARS.Shared.Domain.Repositories;
using System.Threading;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Application.artevents.events
{
public class CancelledArtEventEventHandler : INotificationHandler<ArtEventCancelledEvent>
{
private readonly IUnitOfWork _unitOfWork;
private readonly INotificationCommandService _notificationCommandService;
public CancelledArtEventEventHandler(INotificationCommandService notificationCommandService, IUnitOfWork unitOfWork)
{
_notificationCommandService = notificationCommandService;
_unitOfWork = unitOfWork;
}

public async Task Handle(ArtEventCancelledEvent notification, CancellationToken cancellationToken)
{
NotifyArtEventCancelledCommand notifyArtEventCancelledCommand = new NotifyArtEventCancelledCommand();
notifyArtEventCancelledCommand.Title = notification.Title;
notifyArtEventCancelledCommand.Description= notification.Description;
notifyArtEventCancelledCommand.Location = notification.Location;
notifyArtEventCancelledCommand.EndDate = notification.EndDate;
notifyArtEventCancelledCommand.CurrentStatus = notification.CurrentStatus;
notifyArtEventCancelledCommand.StartDate = notification.StartDate;
await _notificationCommandService.ExecuteNotifyArtEventCancelledCommand(notifyArtEventCancelledCommand);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.ValueObjects;
using System;

namespace PERUSTARS.AtEventManagement.Domain.Model.domainevents
{
public class ArtEventCancelledEvent:INotification
{
public string Title { set; get; }
public string Description { set; get; }
public Location Location { set; get; }
public DateTime StartDate { get; set; } //ArtEventStartDate
public DateTime EndDate { get; set; } //ArtEventEndDate
public ArtEventStatus CurrentStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.ValueObjects;
using System;

namespace PERUSTARS.AtEventManagement.Domain.Model.domainevents
{
public class ArtEventRescheduledEvent:INotification
{
public string Title { get; set; } //ArtEventTitle
public string Description { get; set; } //ArtEventDescription
public Location Location { get; set; } //ArtEventLocation
public DateTime StartDate { get; set; } //ArtEventStartDate
public ArtEventStatus CurrentStatus { get; set; } //ArtEventStatus
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public async Task<IActionResult> cancelArtEvent(int id) {
string response = await _artEventCommandService.cancelArtEvent(cancelArtEventCommand);
return Ok(response);
}
[HttpPost("start/{id}")]
public async Task<IActionResult> startArtEvent(int id) {
StartArtEventCommand startArtEventCommand = new StartArtEventCommand();
startArtEventCommand.id= id;
string response= await _artEventCommandService.startArtEventCommand(startArtEventCommand);
return Ok(response);

}

[HttpPut("edit")]
public async Task<IActionResult> editArtEvent([FromBody] EditArtEventCommand editArtEventCommand)
{
Expand Down
1 change: 1 addition & 0 deletions PERUSTARS/PERUSTARS/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"ConnectionStrings": {


//"DefaultConnection1ssssss": "server=localhost;port=3306;database=perustars;uid=root;password=admin",
// BD Deployment //"DefaultConnection": "server=perustars-main-db.mysql.database.azure.com;port=3306;database=perustars;uid=perustarsAdmin;password=Admin123"
//"DefaultConnection3": "Server=MYSQL5047.site4now.net;Database=db_a758df_perusta;Uid=a758df_perusta;Pwd=password1",
Expand Down

0 comments on commit 65514b0

Please sign in to comment.