Browse Source

List events

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
fd4a60d474
  1. 24
      eventhub/src/EventHub.Application.Contracts/Events/EventInListDto.cs
  2. 17
      eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs
  3. 3
      eventhub/src/EventHub.Application.Contracts/Events/IEventAppService.cs
  4. 46
      eventhub/src/EventHub.Application/Events/EventAppService.cs
  5. 3
      eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json
  6. 2
      eventhub/src/EventHub.Web/Pages/Events/New.cshtml.cs
  7. 28
      eventhub/src/EventHub.Web/Pages/Index.cshtml
  8. 26
      eventhub/src/EventHub.Web/Pages/Index.cshtml.cs
  9. 43
      eventhub/test/EventHub.Application.Tests/Events/EventAppServiceTests.cs
  10. 12
      eventhub/test/EventHub.TestBase/EventHubTestData.cs
  11. 53
      eventhub/test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

24
eventhub/src/EventHub.Application.Contracts/Events/EventInListDto.cs

@ -0,0 +1,24 @@
using System;
using Volo.Abp.Application.Dtos;
namespace EventHub.Events
{
public class EventInListDto : EntityDto<Guid>
{
public string OrganizationName { get; set; }
public string OrganizationDisplayName { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public bool IsOnline { get; set; }
public bool IsLive { get; set; }
}
}

17
eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs

@ -0,0 +1,17 @@
using System;
using Volo.Abp.Application.Dtos;
namespace EventHub.Events
{
public class EventListFilterDto : PagedResultRequestDto
{
public DateTime? MinDate { get; set; }
public DateTime? MaxDate { get; set; }
public EventListFilterDto()
{
MaxResultCount = 20;
}
}
}

3
eventhub/src/EventHub.Application.Contracts/Events/IEventAppService.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace EventHub.Events
@ -6,5 +7,7 @@ namespace EventHub.Events
public interface IEventAppService : IApplicationService
{
Task<EventDto> CreateAsync(CreateEventDto input);
Task<PagedResultDto<EventInListDto>> GetListAsync(EventListFilterDto input);
}
}

46
eventhub/src/EventHub.Application/Events/EventAppService.cs

@ -1,8 +1,10 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using EventHub.Organizations;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
@ -10,8 +12,8 @@ namespace EventHub.Events
{
public class EventAppService : EventHubAppService, IEventAppService
{
private readonly IRepository<Organization, Guid> _organizationRepository;
private readonly EventManager _eventManager;
private readonly IRepository<Organization, Guid> _organizationRepository;
private readonly IRepository<Event, Guid> _eventRepository;
public EventAppService(
@ -50,5 +52,47 @@ namespace EventHub.Events
return ObjectMapper.Map<Event, EventDto>(@event);
}
public async Task<PagedResultDto<EventInListDto>> GetListAsync(EventListFilterDto input)
{
var eventQueryable = await _eventRepository.GetQueryableAsync();
var organizationQueryable = await _organizationRepository.GetQueryableAsync();
var query = from @event in eventQueryable
join organization in organizationQueryable on @event.OrganizationId equals organization.Id
select new {@event, organization};
if (input.MinDate.HasValue)
{
query = query.Where(i => i.@event.EndTime >= input.MinDate);
}
if (input.MaxDate.HasValue)
{
query = query.Where(i => i.@event.EndTime <= input.MaxDate);
}
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;
var dtos = items.Select(
i => new EventInListDto
{
Id = i.@event.Id,
Title = i.@event.Title,
EndTime = i.@event.EndTime,
StartTime = i.@event.StartTime,
IsOnline = i.@event.IsOnline,
OrganizationName = i.organization.Name,
OrganizationDisplayName = i.organization.DisplayName,
IsLive = now.IsBetween(i.@event.StartTime, i.@event.EndTime)
}
).ToList();
return new PagedResultDto<EventInListDto>(totalCount, dtos);
}
}
}

3
eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json

@ -23,6 +23,7 @@
"Members": "Members",
"SeeOrganization": "See Organization",
"Organization": "Organization",
"Submit": "Submit"
"Submit": "Submit",
"SeeEvent": "See Event"
}
}

2
eventhub/src/EventHub.Web/Pages/Events/New.cshtml.cs

@ -17,7 +17,7 @@ namespace EventHub.Web.Pages.Events
[BindProperty]
public NewEventViewModel Event { get; set; }
public List<SelectListItem> Organizations { get; set; }
public List<SelectListItem> Organizations { get; private set; }
private readonly IEventAppService _eventAppService;
private readonly IOrganizationAppService _organizationAppService;

28
eventhub/src/EventHub.Web/Pages/Index.cshtml

@ -3,14 +3,36 @@
@using Microsoft.AspNetCore.Mvc.Localization
@using EventHub.Localization
@inject IHtmlLocalizer<EventHubResource> L
@section styles {
<abp-style-bundle>
<abp-style src="/Pages/Index.css" />
<abp-style src="/Pages/Index.css"/>
</abp-style-bundle>
}
@section scripts {
<abp-script-bundle>
<abp-script src="/Pages/Index.js" />
<abp-script src="/Pages/Index.js"/>
</abp-script-bundle>
}
HOME PAGE
<h2>Upcoming Events</h2>
<abp-row>
@foreach (var eventItem in Model.Events)
{
<abp-column size-lg="_4" size-md="_6">
<abp-card>
<img abp-card-image="Top" src="https://picsum.photos/seed/@eventItem.Id.ToString()/400/160?blur=8" alt="@eventItem.Title"/>
<abp-card-body>
<abp-card-title>@eventItem.Title</abp-card-title>
<abp-card-subtitle>@eventItem.StartTime.ToLongDateString(), @eventItem.StartTime.ToString("hh:mm")</abp-card-subtitle>
<abp-card-text>
@eventItem.Description.TruncateWithPostfix(100)
</abp-card-text>
<a abp-button="Primary" href="#"> @L["SeeEvent"]</a>
</abp-card-body>
</abp-card>
</abp-column>
}
</abp-row>

26
eventhub/src/EventHub.Web/Pages/Index.cshtml.cs

@ -1,13 +1,31 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using EventHub.Events;
using Microsoft.AspNetCore.Authentication;
namespace EventHub.Web.Pages
{
public class IndexModel : EventHubPageModel
{
public void OnGet()
public IReadOnlyList<EventInListDto> Events { get; private set; }
private readonly IEventAppService _eventAppService;
public IndexModel(IEventAppService eventAppService)
{
_eventAppService = eventAppService;
}
public async Task OnGetAsync()
{
var result = await _eventAppService.GetListAsync(
new EventListFilterDto
{
MinDate = Clock.Now
}
);
Events = result.Items;
}
public async Task OnPostLoginAsync()
@ -15,4 +33,4 @@ namespace EventHub.Web.Pages
await HttpContext.ChallengeAsync("oidc");
}
}
}
}

43
eventhub/test/EventHub.Application.Tests/Events/EventAppServiceTests.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp;
using Volo.Abp.Timing;
using Xunit;
namespace EventHub.Events
@ -55,8 +56,48 @@ namespace EventHub.Events
}
);
});
exception.Code.ShouldBe(EventHubErrorCodes.NotAuthorizedToCreateEventInThisOrganization);
}
[Fact]
public async Task Should_Get_Upcoming_Events()
{
var now = GetRequiredService<IClock>().Now;
var result = await _eventAppService.GetListAsync(
new EventListFilterDto
{
MinDate = now
}
);
result.TotalCount.ShouldBeGreaterThanOrEqualTo(1);
result.Items.ShouldContain(x =>
x.Id == _testData.AbpMicroservicesFutureEventId &&
x.Title == _testData.AbpMicroservicesFutureEventTitle
);
result.Items.ShouldAllBe(x => x.EndTime >= now);
}
[Fact]
public async Task Should_Get_Past_Events()
{
var now = GetRequiredService<IClock>().Now;
var result = await _eventAppService.GetListAsync(
new EventListFilterDto
{
MaxDate = now
}
);
result.TotalCount.ShouldBeGreaterThanOrEqualTo(1);
result.Items.ShouldContain(x =>
x.Id == _testData.AbpBlazorPastEventId &&
x.Title == _testData.AbpBlazorPastEventTitle
);
result.Items.ShouldAllBe(x => x.EndTime <= now);
}
}
}

12
eventhub/test/EventHub.TestBase/EventHubTestData.cs

@ -7,10 +7,18 @@ namespace EventHub
{
/* ORGANIZATIONS *****************************************************/
public Guid OrganizationVolosoftId { get; internal set; }
public Guid OrganizationVolosoftId { get; } = Guid.NewGuid();
public string OrganizationVolosoftName { get; } = "volosoft";
public Guid OrganizationDotnetEuropeId { get; internal set; }
public Guid OrganizationDotnetEuropeId { get; } = Guid.NewGuid();
public string OrganizationDotnetEuropeName { get; } = "dotnet-europe";
/* EVENTS ************************************************************/
public Guid AbpBlazorPastEventId { get; } = Guid.NewGuid();
public string AbpBlazorPastEventTitle { get; internal set; } = "ABP Framework Blazor UI Introduction";
public Guid AbpMicroservicesFutureEventId { get;} = Guid.NewGuid();
public string AbpMicroservicesFutureEventTitle { get; internal set; } = "ABP Framework Microservice Solution Development";
}
}

53
eventhub/test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

@ -1,58 +1,89 @@
using System;
using System.Threading.Tasks;
using EventHub.Events;
using EventHub.Organizations;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Timing;
using Volo.Abp.Users;
namespace EventHub
{
public class EventHubTestDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly OrganizationManager _organizationManager;
private readonly IRepository<Organization, Guid> _organizationRepository;
private readonly IRepository<Event, Guid> _eventRepository;
private readonly ICurrentUser _currentUser;
private readonly EventHubTestData _eventHubTestData;
private readonly IClock _clock;
public EventHubTestDataSeedContributor(
EventHubTestData eventHubTestData,
OrganizationManager organizationManager,
ICurrentUser currentUser,
IRepository<Organization, Guid> organizationRepository)
IRepository<Organization, Guid> organizationRepository,
IRepository<Event, Guid> eventRepository,
IClock clock)
{
_eventHubTestData = eventHubTestData;
_organizationManager = organizationManager;
_currentUser = currentUser;
_organizationRepository = organizationRepository;
_eventRepository = eventRepository;
_clock = clock;
}
public async Task SeedAsync(DataSeedContext context)
{
await CreateOrganizationsAsync();
await CreateEvents();
}
private async Task CreateOrganizationsAsync()
{
var volosoft = await _organizationRepository.InsertAsync(
await _organizationManager.CreateAsync(
await _organizationRepository.InsertAsync(
new Organization(
_eventHubTestData.OrganizationVolosoftId,
_currentUser.GetId(),
_eventHubTestData.OrganizationVolosoftName,
"Volosoft",
"Volosoft is producing software development tools for developers. We are organizing events related to the ABP.IO platform and general software development topic."
)
);
_eventHubTestData.OrganizationVolosoftId = volosoft.Id;
var dotnetEurope = await _organizationRepository.InsertAsync(
await _organizationManager.CreateAsync(
Guid.NewGuid(), //TODO: create a second user and set its id!
await _organizationRepository.InsertAsync(
new Organization(
_eventHubTestData.OrganizationDotnetEuropeId,
Guid.NewGuid(),
_eventHubTestData.OrganizationDotnetEuropeName,
"Dotnet Europe",
"Organizing events on Microsoft's .NET Platform in European Countries."
)
);
_eventHubTestData.OrganizationDotnetEuropeId = dotnetEurope.Id;
}
private async Task CreateEvents()
{
await _eventRepository.InsertAsync(
new Event(
_eventHubTestData.AbpBlazorPastEventId,
_eventHubTestData.OrganizationVolosoftId,
_eventHubTestData.AbpBlazorPastEventTitle,
_clock.Now.ClearTime().AddDays(-2).AddHours(15),
_clock.Now.ClearTime().AddDays(-2).AddHours(17),
"This is a past event about Blazor and the ABP Framework."
)
);
await _eventRepository.InsertAsync(
new Event(
_eventHubTestData.AbpMicroservicesFutureEventId,
_eventHubTestData.OrganizationVolosoftId,
_eventHubTestData.AbpMicroservicesFutureEventTitle,
_clock.Now.ClearTime().AddDays(1).AddHours(15),
_clock.Now.ClearTime().AddDays(1).AddHours(17),
"This is a future event about the ABP Framework and Microservices that is set for tomorrow."
)
);
}
}
}

Loading…
Cancel
Save