diff --git a/src/EventHub.Application/Events/EventAppService.cs b/src/EventHub.Application/Events/EventAppService.cs index 9af1a05..2eb3f62 100644 --- a/src/EventHub.Application/Events/EventAppService.cs +++ b/src/EventHub.Application/Events/EventAppService.cs @@ -9,6 +9,7 @@ using EventHub.Users; using Microsoft.AspNetCore.Authorization; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.Authorization; using Volo.Abp.BlobStoring; using Volo.Abp.Domain.Repositories; using Volo.Abp.Users; @@ -67,7 +68,8 @@ namespace EventHub.Events @event.SetLocation(input.IsOnline, input.OnlineLink, input.CountryId, input.City); @event.Language = input.Language; - @event.Capacity = input.Capacity; + + await _eventManager.SetCapacityAsync(@event, input.Capacity); if (input.CoverImageContent != null && input.CoverImageContent.Length > 0) { @@ -206,23 +208,20 @@ namespace EventHub.Events if (organization.OwnerUserId != CurrentUser.GetId()) { - throw new BusinessException(EventHubErrorCodes.NotAuthorizedToUpdateEventProfile) - .WithData("EventTitle", @event.Title); + throw new AbpAuthorizationException( + L["EventHub:NotAuthorizedToUpdateEvent"].Value.Replace("{EventTitle}", @event.Title), + EventHubErrorCodes.NotAuthorizedToUpdateEvent + ); } + + @event.SetLocation(input.IsOnline, input.OnlineLink, input.CountryId, input.City); + @event.SetTitle(input.Title); + @event.SetDescription(input.Description); + @event.Language = input.Language; - var updatedEvent = await _eventManager.UpdateAsync( - id, - input.CountryId, - input.Title, - input.Description, - input.Language, - input.IsOnline, - input.OnlineLink, - input.City, - input.Capacity - ); + await _eventManager.SetCapacityAsync(@event, input.Capacity); - await _eventRepository.UpdateAsync(updatedEvent); + await _eventRepository.UpdateAsync(@event); } [Authorize] diff --git a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs index 3ff4783..4b4bccd 100644 --- a/src/EventHub.Domain.Shared/EventHubErrorCodes.cs +++ b/src/EventHub.Domain.Shared/EventHubErrorCodes.cs @@ -9,7 +9,7 @@ public const string NotAuthorizedToUpdateOrganizationProfile = "EventHub:NotAuthorizedToUpdateOrganizationProfile"; public const string CapacityOfEventFull = "EventHub:CapacityOfEventFull"; public const string CapacityCantBeLowerThanRegisteredUserCount = "EventHub:CapacityCantBeLowerThanRegisteredUserCount"; - public const string NotAuthorizedToUpdateEventProfile = "EventHub:NotAuthorizedToUpdateEventProfile"; + public const string NotAuthorizedToUpdateEvent = "EventHub:NotAuthorizedToUpdateEvent"; public const string CantChangeEventTiming = "EventHub:CantChangeEventTiming"; } } diff --git a/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/src/EventHub.Domain.Shared/Localization/EventHub/en.json index a485c8c..b8ff954 100644 --- a/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -63,7 +63,7 @@ "LocationHasNotSpecifiedYet": "Event {0} has not been specified yet.", "Language": "Language", "EventHub:CapacityCantBeLowerThanRegisteredUserCount": "Capacity can not be lower than the currently registered user count.", - "EventHub:NotAuthorizedToUpdateEventProfile": "You are not authorized to update the \"{EventTitle}\" event.", + "EventHub:NotAuthorizedToUpdateEvent": "You are not authorized to update the \"{EventTitle}\" event.", "CoverImage": "Cover Image", "EventHub:CantChangeEventTiming": "Can not change the event timing more than {MaxTimingChangeLimit} times.", "EventCoverImageEditSuccessMessage": "The event's cover image has been changed successfully.", diff --git a/src/EventHub.Domain/Events/Event.cs b/src/EventHub.Domain/Events/Event.cs index 2722a27..012f53c 100644 --- a/src/EventHub.Domain/Events/Event.cs +++ b/src/EventHub.Domain/Events/Event.cs @@ -30,7 +30,7 @@ namespace EventHub.Events public string Language { get; set; } - public int? Capacity { get; set; } + public int? Capacity { get; internal set; } public bool IsRemindingEmailSent { get; set; } diff --git a/src/EventHub.Domain/Events/EventManager.cs b/src/EventHub.Domain/Events/EventManager.cs index c43aa31..ac933c5 100644 --- a/src/EventHub.Domain/Events/EventManager.cs +++ b/src/EventHub.Domain/Events/EventManager.cs @@ -44,32 +44,20 @@ namespace EventHub.Events ); } - public async Task UpdateAsync( - Guid id, - Guid? countryId, - string title, - string description, - string language, - bool isOnline, - string onlineLink, - string city, + public async Task SetCapacityAsync( + Event @event, int? capacity) { - var @event = await _eventRepository.GetAsync(id); - var registeredUserCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id); - - if (capacity < registeredUserCount) + if (capacity.HasValue) { - throw new BusinessException(EventHubErrorCodes.CapacityCantBeLowerThanRegisteredUserCount); + var registeredUserCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id); + if (capacity.Value < registeredUserCount) + { + throw new BusinessException(EventHubErrorCodes.CapacityCantBeLowerThanRegisteredUserCount); + } } - @event.SetTitle(title); - @event.SetDescription(description); - @event.SetLocation(isOnline, onlineLink, countryId, city); @event.Capacity = capacity; - @event.Language = language; - - return @event; } } } diff --git a/test/EventHub.Domain.Tests/Events/EventManagerTests.cs b/test/EventHub.Domain.Tests/Events/EventManagerTests.cs index 714228a..3d43cfa 100644 --- a/test/EventHub.Domain.Tests/Events/EventManagerTests.cs +++ b/test/EventHub.Domain.Tests/Events/EventManagerTests.cs @@ -47,26 +47,19 @@ namespace EventHub.Events } [Fact] - public async Task Should_Update_The_Event() + public async Task Should_Update_The_Event_Capacity() { await WithUnitOfWorkAsync(async () => { var @event = await _eventRepository.GetAsync(_testData.AbpMicroservicesFutureEventId); + var newCapacity = @event.Capacity.HasValue ? @event.Capacity.Value + 1 : 42; - var updatedEvent = await _eventManager.UpdateAsync( - @event.Id, - null, - "Updated_Microservice_Event_Title", - "Updated_Microservice_Event_Description" + @event.Description, - "en", - true, - "online_link", - null, - null + await _eventManager.SetCapacityAsync( + @event, + newCapacity ); - @event.Title.ShouldBe(updatedEvent.Title); - @event.Description.ShouldBe(updatedEvent.Description); + @event.Capacity.ShouldBe(newCapacity); }); } }