From 78c7b68ea45ae00e5e988b2e40b536cda1aad08e Mon Sep 17 00:00:00 2001 From: berkansasmaz Date: Fri, 10 Dec 2021 16:34:29 +0300 Subject: [PATCH] feat: Delete and Update track --- .../Events/DeleteTractDto.cs | 6 + .../Events/IEventAppService.cs | 2 + .../Events/EventAppService.cs | 8 ++ .../EventHubErrorCodes.cs | 1 + .../Localization/EventHub/en.json | 3 +- src/EventHub.Domain/Events/Event.cs | 13 +++ .../Controllers/Events/EventController.cs | 7 ++ .../CreateEventArea/_addTrackSection.cshtml | 58 +++++++--- .../CreateEventArea/create-event-area.js | 104 ++++++++++++++++-- 9 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 src/EventHub.Application.Contracts/Events/DeleteTractDto.cs diff --git a/src/EventHub.Application.Contracts/Events/DeleteTractDto.cs b/src/EventHub.Application.Contracts/Events/DeleteTractDto.cs new file mode 100644 index 0000000..fd9d396 --- /dev/null +++ b/src/EventHub.Application.Contracts/Events/DeleteTractDto.cs @@ -0,0 +1,6 @@ +namespace EventHub.Events; + +public class DeleteTractDto +{ + public string Name { get; set; } +} diff --git a/src/EventHub.Application.Contracts/Events/IEventAppService.cs b/src/EventHub.Application.Contracts/Events/IEventAppService.cs index 59b5011..c287748 100644 --- a/src/EventHub.Application.Contracts/Events/IEventAppService.cs +++ b/src/EventHub.Application.Contracts/Events/IEventAppService.cs @@ -27,6 +27,8 @@ namespace EventHub.Events Task AddTrackAsync(Guid id, AddTractDto input); + Task DeleteTrackAsync(Guid id, Guid trackId); + Task AddSessionAsync(Guid id, AddSessionDto input); Task GetCoverImageAsync(Guid id); diff --git a/src/EventHub.Application/Events/EventAppService.cs b/src/EventHub.Application/Events/EventAppService.cs index 52cc28f..75936d5 100644 --- a/src/EventHub.Application/Events/EventAppService.cs +++ b/src/EventHub.Application/Events/EventAppService.cs @@ -270,6 +270,14 @@ namespace EventHub.Events await _eventRepository.UpdateAsync(@event); } + public async Task DeleteTrackAsync(Guid id, Guid trackId) + { + var @event = await _eventRepository.GetAsync(id, true); + await CheckOwnerControlAsync(@event); + + @event.RemoveTrack(trackId); + } + [Authorize] public async Task AddSessionAsync(Guid id, AddSessionDto input) { diff --git a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs index 951de36..572a9f4 100644 --- a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs +++ b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs @@ -17,5 +17,6 @@ public const string UserNotFound = "EventHub:UserNotFound"; public const string OrganizationNotFound = "EventHub:OrganizationNotFound"; public const string TrackNameAlreadyExist = "EventHub:TrackNameAlreadyExist"; + public const string TrackNotFound = "EventHub:TrackNotFound"; } } diff --git a/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/src/EventHub.Domain.Shared/Localization/EventHub/en.json index f21596f..f933d5e 100644 --- a/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -153,6 +153,7 @@ "Online": "Online", "InPerson": "In Person", "UpgradeToPremium": "Upgrade To Premium", - "EventHub:TrackNameAlreadyExist": "The track {Name} already exists" + "EventHub:TrackNameAlreadyExist": "The track {Name} already exists", + "EventHub:TrackNotFound": "The track not found!" } } diff --git a/src/EventHub.Domain/Events/Event.cs b/src/EventHub.Domain/Events/Event.cs index 0eb92b6..75e4f65 100644 --- a/src/EventHub.Domain/Events/Event.cs +++ b/src/EventHub.Domain/Events/Event.cs @@ -139,6 +139,19 @@ namespace EventHub.Events return this; } + + public Event RemoveTrack(Guid trackId) + { + var track = Tracks.SingleOrDefault(x => x.Id == trackId); + if (track is null) + { + throw new BusinessException(EventHubErrorCodes.TrackNotFound); + } + + Tracks.Remove(track); + + return this; + } public Event AddSession( Guid trackId, diff --git a/src/EventHub.HttpApi/Controllers/Events/EventController.cs b/src/EventHub.HttpApi/Controllers/Events/EventController.cs index 9c0bcc4..fab0029 100644 --- a/src/EventHub.HttpApi/Controllers/Events/EventController.cs +++ b/src/EventHub.HttpApi/Controllers/Events/EventController.cs @@ -88,6 +88,13 @@ namespace EventHub.Controllers.Events await _eventAppService.AddTrackAsync(id, input); } + [HttpPost] + [Route("{id}/tracks/{trackId}")] + public async Task DeleteTrackAsync(Guid id, Guid trackId) + { + await _eventAppService.DeleteTrackAsync(id, trackId); + } + [HttpPost] [Route("{id}/sessions")] public async Task AddSessionAsync(Guid id, AddSessionDto input) diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml index 8ab4e9c..6806b01 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml @@ -16,7 +16,14 @@
@track.Name - Edit + + + Edit + + + Delete + +
} @@ -31,7 +38,7 @@