Skip to content

Commit

Permalink
feat: add events and comunication with comunication management
Browse files Browse the repository at this point in the history
  • Loading branch information
FranchescoSoto committed Nov 13, 2023
1 parent 50214c6 commit 561d2d9
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 11 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,7 @@ public async Task<string> Handle(StartArtEventCommand request, CancellationToken
else
{
artEvent.CurrentStatus = ArtEventStatus.STARTED;
_artEventRepository.Update(artEvent);
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
}
}
5 changes: 4 additions & 1 deletion PERUSTARS/PERUSTARS/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
},
"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"
//"DefaultConnection": "server=perustars-db.mysql.database.azure.com;port=3306;database=perustars;uid=perustarsAdmin;password=Miguel445"
//"DefaultConnection3": "Server=MYSQL5047.site4now.net;Database=db_a758df_perusta;Uid=a758df_perusta;Pwd=password1",
"DefaultConnection": "Server=bufyroukqdunhwcivvpo-mysql.services.clever-cloud.com;Database=bufyroukqdunhwcivvpo;Uid=ubcldvvxbrtlhp2d;Pwd=FltJthiJHLXaKDmKT11O"
//"DefaultConnection": "Server=bufyroukqdunhwcivvpo-mysql.services.clever-cloud.com;Database=bufyroukqdunhwcivvpo;Uid=ubcldvvxbrtlhp2d;Pwd=FltJthiJHLXaKDmKT11O"
//"PostgreSQLConnection": "host=localhost;port=5432;username=postgres;password=12345;database=perustars"
// "DefaultConnection": "server=localhost;port=3306;database=perustars;uid=root;password=root"
},
Expand Down
Binary file modified PERUSTARS/PERUSTARS/bin/Debug/net5.0/PERUSTARS.dll
Binary file not shown.
Binary file modified PERUSTARS/PERUSTARS/bin/Debug/net5.0/PERUSTARS.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\HP\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\HP\\.nuget\\packages",
"C:\\Users\\Franchesco\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Franchesco\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
]
}
Expand Down
7 changes: 5 additions & 2 deletions PERUSTARS/PERUSTARS/bin/Debug/net5.0/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
},
"ConnectionStrings": {

//"DefaultConnection1": "server=localhost;port=3306;database=perustars;uid=root;password=admin",

//"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"
//"DefaultConnection": "server=perustars-db.mysql.database.azure.com;port=3306;database=perustars;uid=perustarsAdmin;password=Miguel445"
//"DefaultConnection3": "Server=MYSQL5047.site4now.net;Database=db_a758df_perusta;Uid=a758df_perusta;Pwd=password1",
"DefaultConnection": "Server=bufyroukqdunhwcivvpo-mysql.services.clever-cloud.com;Database=bufyroukqdunhwcivvpo;Uid=ubcldvvxbrtlhp2d;Pwd=FltJthiJHLXaKDmKT11O"
//"DefaultConnection": "Server=bufyroukqdunhwcivvpo-mysql.services.clever-cloud.com;Database=bufyroukqdunhwcivvpo;Uid=ubcldvvxbrtlhp2d;Pwd=FltJthiJHLXaKDmKT11O"
//"PostgreSQLConnection": "host=localhost;port=5432;username=postgres;password=12345;database=perustars"
// "DefaultConnection": "server=localhost;port=3306;database=perustars;uid=root;password=root"
},
Expand Down

0 comments on commit 561d2d9

Please sign in to comment.