diff --git a/eventhub/src/EventHub.Application.Contracts/Events/Registrations/EventAttendeeDto.cs b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/EventAttendeeDto.cs new file mode 100644 index 0000000..31d7e5f --- /dev/null +++ b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/EventAttendeeDto.cs @@ -0,0 +1,15 @@ +using System; + +namespace EventHub.Events.Registrations +{ + public class EventAttendeeDto + { + public Guid Id { get; set; } + + public string UserName { get; set; } + + public string Name { get; set; } + + public string Surname { get; set; } + } +} diff --git a/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs index 0f34d94..f27c22b 100644 --- a/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs +++ b/eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace EventHub.Events.Registrations @@ -11,5 +12,7 @@ namespace EventHub.Events.Registrations Task UnregisterAsync(Guid eventId); Task IsRegisteredAsync(Guid eventId); + + Task> GetAttendeesAsync(Guid eventId); } } diff --git a/eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs b/eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs index 49fad20..c8690d3 100644 --- a/eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs +++ b/eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs @@ -1,6 +1,8 @@ using AutoMapper; using EventHub.Events; +using EventHub.Events.Registrations; using EventHub.Organizations; +using EventHub.Users; using Volo.Abp.AutoMapper; namespace EventHub @@ -20,6 +22,8 @@ namespace EventHub CreateMap() .Ignore(x => x.OrganizationName) .Ignore(x => x.OrganizationDisplayName); + + CreateMap(); } } } diff --git a/eventhub/src/EventHub.Application/Events/EventAppService.cs b/eventhub/src/EventHub.Application/Events/EventAppService.cs index 48101d9..5fd3d84 100644 --- a/eventhub/src/EventHub.Application/Events/EventAppService.cs +++ b/eventhub/src/EventHub.Application/Events/EventAppService.cs @@ -72,9 +72,10 @@ namespace EventHub.Events query = query.Where(i => i.@event.EndTime <= input.MaxDate); } + var totalCount = await AsyncExecuter.CountAsync(query); + query = query.PageBy(input).OrderBy(x => x.@event.StartTime); - var totalCount = await AsyncExecuter.CountAsync(query); var items = await AsyncExecuter.ToListAsync(query); var now = Clock.Now; diff --git a/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs b/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs index dc6d2e9..d0dc286 100644 --- a/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs +++ b/eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using EventHub.Users; using Microsoft.AspNetCore.Authorization; +using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Repositories; using Volo.Abp.Users; @@ -12,15 +15,18 @@ namespace EventHub.Events.Registrations private readonly EventRegistrationManager _eventRegistrationManager; private readonly IRepository _userRepository; private readonly IRepository _eventRepository; + private readonly IRepository _eventRegistrationRepository; public EventRegistrationAppService( EventRegistrationManager eventRegistrationManager, IRepository userRepository, - IRepository eventRepository) + IRepository eventRepository, + IRepository eventRegistrationRepository) { _eventRegistrationManager = eventRegistrationManager; _userRepository = userRepository; _eventRepository = eventRepository; + _eventRegistrationRepository = eventRegistrationRepository; } [Authorize] @@ -49,5 +55,25 @@ namespace EventHub.Events.Registrations await _userRepository.GetAsync(CurrentUser.GetId()) ); } + + public async Task> GetAttendeesAsync(Guid eventId) + { + var eventRegistrationQueryable = await _eventRegistrationRepository.GetQueryableAsync(); + var userQueryable = await _userRepository.GetQueryableAsync(); + + var query = from eventRegistration in eventRegistrationQueryable + join user in userQueryable on eventRegistration.UserId equals user.Id + where eventRegistration.EventId == eventId + orderby eventRegistration.CreationTime descending + select user; + + var totalCount = await AsyncExecuter.CountAsync(query); + var users = await AsyncExecuter.ToListAsync(query.Take(10)); + + return new PagedResultDto( + totalCount, + ObjectMapper.Map, List>(users) + ); + } } } diff --git a/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs b/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs index 64c592e..8afd4e3 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs +++ b/eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using EventHub.Events.Registrations; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; @@ -12,12 +13,17 @@ namespace EventHub.Web.Pages.Events.Components.AttendeesArea )] public class AttendeesAreaViewComponent : AbpViewComponent { - public AttendeesAreaViewComponent() + private readonly IEventRegistrationAppService _eventRegistrationAppService; + + public AttendeesAreaViewComponent(IEventRegistrationAppService eventRegistrationAppService) { + _eventRegistrationAppService = eventRegistrationAppService; } public async Task InvokeAsync(Guid eventId) { + var attendees = await _eventRegistrationAppService.GetAttendeesAsync(eventId); + return View("~/Pages/Events/Components/AttendeesArea/Default.cshtml"); } } diff --git a/eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs b/eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs index d445dca..1e4ecd3 100644 --- a/eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs +++ b/eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs @@ -59,6 +59,37 @@ namespace EventHub.Events.Registrations ).ShouldBeNull(); } + [Fact] + public async Task Should_Get_List_Of_Attendees() + { + await WithUnitOfWorkAsync(async () => + { + await _eventRegistrationRepository.InsertAsync( + new EventRegistration( + Guid.NewGuid(), + _testData.AbpMicroservicesFutureEventId, + _testData.UserAdminId + ) + ); + + await _eventRegistrationRepository.InsertAsync( + new EventRegistration( + Guid.NewGuid(), + _testData.AbpMicroservicesFutureEventId, + _testData.UserJohnId + ) + ); + }); + + var result = await _eventRegistrationAppService.GetAttendeesAsync( + _testData.AbpMicroservicesFutureEventId + ); + + result.TotalCount.ShouldBeGreaterThanOrEqualTo(2); + result.Items.ShouldContain(x => x.Id == _testData.UserAdminId); + result.Items.ShouldContain(x => x.Id == _testData.UserJohnId); + } + private async Task GetRegistrationOrNull(Guid eventId, Guid userId) { return await WithUnitOfWorkAsync(async () =>