Browse Source

Implemented GetAttendeesAsync server side.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
7e6a45f88a
  1. 15
      eventhub/src/EventHub.Application.Contracts/Events/Registrations/EventAttendeeDto.cs
  2. 3
      eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs
  3. 4
      eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs
  4. 3
      eventhub/src/EventHub.Application/Events/EventAppService.cs
  5. 28
      eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs
  6. 8
      eventhub/src/EventHub.Web/Pages/Events/Components/AttendeesArea/AttendeesAreaViewComponent.cs
  7. 31
      eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs

15
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; }
}
}

3
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<bool> IsRegisteredAsync(Guid eventId);
Task<PagedResultDto<EventAttendeeDto>> GetAttendeesAsync(Guid eventId);
}
}

4
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<Event, EventDetailDto>()
.Ignore(x => x.OrganizationName)
.Ignore(x => x.OrganizationDisplayName);
CreateMap<AppUser, EventAttendeeDto>();
}
}
}

3
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;

28
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<AppUser, Guid> _userRepository;
private readonly IRepository<Event, Guid> _eventRepository;
private readonly IRepository<EventRegistration, Guid> _eventRegistrationRepository;
public EventRegistrationAppService(
EventRegistrationManager eventRegistrationManager,
IRepository<AppUser, Guid> userRepository,
IRepository<Event, Guid> eventRepository)
IRepository<Event, Guid> eventRepository,
IRepository<EventRegistration, Guid> 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<PagedResultDto<EventAttendeeDto>> 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<EventAttendeeDto>(
totalCount,
ObjectMapper.Map<List<AppUser>, List<EventAttendeeDto>>(users)
);
}
}
}

8
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<IViewComponentResult> InvokeAsync(Guid eventId)
{
var attendees = await _eventRegistrationAppService.GetAttendeesAsync(eventId);
return View("~/Pages/Events/Components/AttendeesArea/Default.cshtml");
}
}

31
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<EventRegistration> GetRegistrationOrNull(Guid eventId, Guid userId)
{
return await WithUnitOfWorkAsync(async () =>

Loading…
Cancel
Save