Browse Source

Refactor after review

pull/79/head
berkansasmaz 5 years ago
parent
commit
5ad83d7556
No known key found for this signature in database GPG Key ID: 884D815C3F32BE00
  1. 2
      src/EventHub.Application.Contracts/Events/AddTrackDto.cs
  2. 2
      src/EventHub.Application.Contracts/Events/IEventAppService.cs
  3. 9
      src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs
  4. 21
      src/EventHub.Application/Events/EventAppService.cs
  5. 7
      src/EventHub.Domain/Events/Event.cs
  6. 7
      src/EventHub.Domain/Events/Speaker.cs
  7. 2
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContextModelCreatingExtensions.cs
  8. 2831
      src/EventHub.EntityFrameworkCore/Migrations/20211224141912_Removed_Unnecessary_Index.Designer.cs
  9. 104
      src/EventHub.EntityFrameworkCore/Migrations/20211224141912_Removed_Unnecessary_Index.cs
  10. 20
      src/EventHub.EntityFrameworkCore/Migrations/EventHubDbContextModelSnapshot.cs
  11. 2
      src/EventHub.HttpApi/Controllers/Events/EventController.cs
  12. 2
      src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml
  13. 4
      src/EventHub.Web/Pages/Events/Detail.cshtml
  14. 4
      test/EventHub.Application.Tests/Events/EventAppServiceTests.cs
  15. 34
      test/EventHub.Domain.Tests/Events/EventTests.cs

2
src/EventHub.Application.Contracts/Events/AddTractDto.cs → src/EventHub.Application.Contracts/Events/AddTrackDto.cs

@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
namespace EventHub.Events;
public class AddTractDto
public class AddTrackDto
{
[Required]
[StringLength(TrackConsts.MaxNameLength)]

2
src/EventHub.Application.Contracts/Events/IEventAppService.cs

@ -27,7 +27,7 @@ namespace EventHub.Events
Task<string> PublishAsync(Guid id);
Task AddTrackAsync(Guid id, AddTractDto input);
Task AddTrackAsync(Guid id, AddTrackDto input);
Task UpdateTrackAsync(Guid id, Guid trackId, UpdateTrackDto input);

9
src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs

@ -27,17 +27,14 @@ namespace EventHub
.Ignore(x => x.OrganizationDisplayName)
.Ignore(x => x.IsLiveNow);
CreateMap<Event, EventDetailDto>()
.ForMember(x => x.Tracks, memberOptions => memberOptions.MapFrom(m => m.Tracks))
.Ignore(x => x.OrganizationId)
.Ignore(x => x.OrganizationName)
.Ignore(x => x.OrganizationDisplayName);
CreateMap<Track, TrackDto>()
.ForMember(x => x.Sessions, memberOptions => memberOptions.MapFrom(m => m.Sessions));
CreateMap<Track, TrackDto>();
CreateMap<Session, SessionDto>()
.ForMember(x => x.Speakers, memberOptions => memberOptions.MapFrom(m => m.Speakers));
CreateMap<Session, SessionDto>();
CreateMap<Speaker, SpeakerDto>()
.Ignore(x => x.UserName);

21
src/EventHub.Application/Events/EventAppService.cs

@ -294,12 +294,12 @@ namespace EventHub.Events
}
[Authorize]
public async Task AddTrackAsync(Guid id, AddTractDto input)
public async Task AddTrackAsync(Guid id, AddTrackDto input)
{
var @event = await _eventRepository.GetAsync(id, true);
await CheckIfValidOwnerAsync(@event);
@event.AddTract(
@event.AddTrack(
GuidGenerator.Create(),
input.Name
);
@ -328,12 +328,13 @@ namespace EventHub.Events
await CheckIfValidOwnerAsync(@event);
@event.RemoveTrack(trackId);
await _eventRepository.UpdateAsync(@event);
}
[Authorize]
public async Task AddSessionAsync(Guid id, Guid trackId, AddSessionDto input)
{
await CheckIfValidUserNamesAsync(input.SpeakerUserNames);
var @event = await _eventRepository.GetAsync(id);
await CheckIfValidOwnerAsync(@event);
@ -354,7 +355,6 @@ namespace EventHub.Events
[Authorize]
public async Task UpdateSessionAsync(Guid id, Guid trackId, Guid sessionId, UpdateSessionDto input)
{
await CheckIfValidUserNamesAsync(input.SpeakerUserNames);
var @event = await _eventRepository.GetAsync(id);
await CheckIfValidOwnerAsync(@event);
@ -379,6 +379,8 @@ namespace EventHub.Events
await CheckIfValidOwnerAsync(@event);
@event.RemoveSession(trackId, sessionId);
await _eventRepository.UpdateAsync(@event);
}
public async Task<IRemoteStreamContent> GetCoverImageAsync(Guid id)
@ -410,7 +412,14 @@ namespace EventHub.Events
.Where(u => userNames.Any(p => p == u.UserName))
.Select(x => x.Id);
return await AsyncExecuter.ToListAsync(query);
var userIds = await AsyncExecuter.ToListAsync(query);
if (userIds.Count != userNames.Count)
{
await CheckIfValidUserNamesAsync(userNames);
}
return userIds;
}
private async Task CheckIfValidOwnerAsync(Event @event)
@ -448,7 +457,7 @@ namespace EventHub.Events
var dto = ObjectMapper.Map<Event, EventInListDto>(i.@event);
dto.OrganizationName = i.organization.Name;
dto.OrganizationDisplayName = i.organization.DisplayName;
dto.IsLiveNow = now.IsBetween(i.@event.StartTime, i.@event.EndTime);
dto.IsLiveNow = i.@event.IsLive(now);
dto.Country = i.@event.CountryName;
return dto;
}

7
src/EventHub.Domain/Events/Event.cs

@ -129,7 +129,7 @@ namespace EventHub.Events
return this;
}
public Event AddTract(Guid trackId, string name)
public Event AddTrack(Guid trackId, string name)
{
if (Tracks.Any(x => x.Name == name))
{
@ -230,6 +230,11 @@ namespace EventHub.Events
return this;
}
public bool IsLive(DateTime now)
{
return now.IsBetween(StartTime, EndTime);
}
private Track GetTrack(Guid trackId)
{
return Tracks.FirstOrDefault(t => t.Id == trackId) ??

7
src/EventHub.Domain/Events/Speaker.cs

@ -9,6 +9,11 @@ namespace EventHub.Events
public Guid UserId { get; private set; }
private Speaker()
{
}
public Speaker(Guid sessionId, Guid userId)
{
SessionId = sessionId;
@ -20,4 +25,4 @@ namespace EventHub.Events
return new object[] {SessionId, UserId};
}
}
}
}

2
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContextModelCreatingExtensions.cs

@ -108,8 +108,6 @@ namespace EventHub.EntityFrameworkCore
b.HasKey(x => new {x.SessionId, x.UserId});
b.HasOne<IdentityUser>().WithMany().HasForeignKey(x => x.UserId).IsRequired();
b.HasIndex(x => new {x.UserId, x.SessionId});
});
builder.Entity<EventRegistration>(b =>

2831
src/EventHub.EntityFrameworkCore/Migrations/20211224141912_Removed_Unnecessary_Index.Designer.cs

File diff suppressed because it is too large

104
src/EventHub.EntityFrameworkCore/Migrations/20211224141912_Removed_Unnecessary_Index.cs

@ -0,0 +1,104 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EventHub.Migrations
{
public partial class Removed_Unnecessary_Index : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EhEventSpeakers_UserId_SessionId",
table: "EhEventSpeakers");
migrationBuilder.DropIndex(
name: "IX_AbpSettings_Name_ProviderName_ProviderKey",
table: "AbpSettings");
migrationBuilder.DropIndex(
name: "IX_AbpPermissionGrants_Name_ProviderName_ProviderKey",
table: "AbpPermissionGrants");
migrationBuilder.AlterColumn<DateTime>(
name: "StartTime",
table: "EhEventSessions",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "EndTime",
table: "EhEventSessions",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone");
migrationBuilder.CreateIndex(
name: "IX_EhEventSpeakers_UserId",
table: "EhEventSpeakers",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AbpSettings_Name_ProviderName_ProviderKey",
table: "AbpSettings",
columns: new[] { "Name", "ProviderName", "ProviderKey" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AbpPermissionGrants_TenantId_Name_ProviderName_ProviderKey",
table: "AbpPermissionGrants",
columns: new[] { "TenantId", "Name", "ProviderName", "ProviderKey" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EhEventSpeakers_UserId",
table: "EhEventSpeakers");
migrationBuilder.DropIndex(
name: "IX_AbpSettings_Name_ProviderName_ProviderKey",
table: "AbpSettings");
migrationBuilder.DropIndex(
name: "IX_AbpPermissionGrants_TenantId_Name_ProviderName_ProviderKey",
table: "AbpPermissionGrants");
migrationBuilder.AlterColumn<DateTime>(
name: "StartTime",
table: "EhEventSessions",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
migrationBuilder.AlterColumn<DateTime>(
name: "EndTime",
table: "EhEventSessions",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
migrationBuilder.CreateIndex(
name: "IX_EhEventSpeakers_UserId_SessionId",
table: "EhEventSpeakers",
columns: new[] { "UserId", "SessionId" });
migrationBuilder.CreateIndex(
name: "IX_AbpSettings_Name_ProviderName_ProviderKey",
table: "AbpSettings",
columns: new[] { "Name", "ProviderName", "ProviderKey" });
migrationBuilder.CreateIndex(
name: "IX_AbpPermissionGrants_Name_ProviderName_ProviderKey",
table: "AbpPermissionGrants",
columns: new[] { "Name", "ProviderName", "ProviderKey" });
}
}
}

20
src/EventHub.EntityFrameworkCore/Migrations/EventHubDbContextModelSnapshot.cs

@ -19,7 +19,7 @@ namespace EventHub.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql)
.HasAnnotation("ProductVersion", "6.0.0-rc.2.21480.5")
.HasAnnotation("ProductVersion", "6.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -222,7 +222,7 @@ namespace EventHub.Migrations
.HasColumnType("character varying(2000)");
b.Property<DateTime>("EndTime")
.HasColumnType("timestamp without time zone");
.HasColumnType("timestamp with time zone");
b.Property<string>("Language")
.IsRequired()
@ -230,7 +230,7 @@ namespace EventHub.Migrations
.HasColumnType("character varying(16)");
b.Property<DateTime>("StartTime")
.HasColumnType("timestamp without time zone");
.HasColumnType("timestamp with time zone");
b.Property<string>("Title")
.IsRequired()
@ -244,7 +244,7 @@ namespace EventHub.Migrations
b.HasIndex("TrackId");
b.ToTable("EhEventSessions");
b.ToTable("EhEventSessions", (string)null);
});
modelBuilder.Entity("EventHub.Events.Speaker", b =>
@ -257,9 +257,9 @@ namespace EventHub.Migrations
b.HasKey("SessionId", "UserId");
b.HasIndex("UserId", "SessionId");
b.HasIndex("UserId");
b.ToTable("EhEventSpeakers");
b.ToTable("EhEventSpeakers", (string)null);
});
modelBuilder.Entity("EventHub.Events.Track", b =>
@ -279,7 +279,7 @@ namespace EventHub.Migrations
b.HasIndex("EventId");
b.ToTable("EhEventTracks");
b.ToTable("EhEventTracks", (string)null);
});
modelBuilder.Entity("EventHub.Organizations.Memberships.OrganizationMembership", b =>
@ -2327,7 +2327,8 @@ namespace EventHub.Migrations
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");
b.HasIndex("TenantId", "Name", "ProviderName", "ProviderKey")
.IsUnique();
b.ToTable("AbpPermissionGrants", (string)null);
});
@ -2358,7 +2359,8 @@ namespace EventHub.Migrations
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");
b.HasIndex("Name", "ProviderName", "ProviderKey")
.IsUnique();
b.ToTable("AbpSettings", (string)null);
});

2
src/EventHub.HttpApi/Controllers/Events/EventController.cs

@ -91,7 +91,7 @@ namespace EventHub.Controllers.Events
[HttpPost]
[Route("{id}/tracks")]
public async Task AddTrackAsync(Guid id, AddTractDto input)
public async Task AddTrackAsync(Guid id, AddTrackDto input)
{
await _eventAppService.AddTrackAsync(id, input);
}

2
src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml

@ -180,7 +180,7 @@
@foreach (var session in track.Sessions)
{
<div class="track-item">
<span class="track-name">@session.Title.TruncateWithPostfix(25)</span>
<span class="track-name">@session.Title.TruncateWithPostfix(55)</span>
<small class="text-primary d-block my-2">@EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(session.StartTime), TimeOnly.FromDateTime(session.EndTime)) | @session.Language</small>
@foreach (var speaker in session.Speakers)
{

4
src/EventHub.Web/Pages/Events/Detail.cshtml

@ -90,7 +90,7 @@
@await Component.InvokeAsync(typeof(AttendeesAreaViewComponent), new { eventId = Model.Event.Id })
</abp-tab>
<abp-tab class="tab" title=" Track / Session">
<table class="table">
<table class="table mt-3">
<thead>
<tr>
@foreach (var track in Model.Event.Tracks)
@ -112,7 +112,7 @@
@foreach (var session in track.Sessions)
{
<div class="track-item">
<span class="track-name">@session.Title.TruncateWithPostfix(25)</span>
<span class="track-name">@session.Title.TruncateWithPostfix(55)</span>
<small class="text-primary d-block my-2">@EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(session.StartTime), TimeOnly.FromDateTime(session.EndTime)) | @session.Language</small>
@foreach (var speaker in session.Speakers)
{

4
test/EventHub.Application.Tests/Events/EventAppServiceTests.cs

@ -238,7 +238,7 @@ namespace EventHub.Events
var eventDetailDto = await _eventAppService.GetByUrlCodeAsync(_testData.AbpMicroservicesFutureEventUrlCode);
await _eventAppService.AddTrackAsync(eventDetailDto.Id, new AddTractDto
await _eventAppService.AddTrackAsync(eventDetailDto.Id, new AddTrackDto
{
Name = "Track-1"
});
@ -256,7 +256,7 @@ namespace EventHub.Events
var eventDetailDto = await _eventAppService.GetByUrlCodeAsync(_testData.AbpMicroservicesFutureEventUrlCode);
await _eventAppService.AddTrackAsync(eventDetailDto.Id, new AddTractDto
await _eventAppService.AddTrackAsync(eventDetailDto.Id, new AddTrackDto
{
Name = "Track-1"
});

34
test/EventHub.Domain.Tests/Events/EventTests.cs

@ -49,7 +49,7 @@ namespace EventHub.Events
"In this event, we will introduce the ABP Framework and explore the fundamental features."
);
@event.AddTract(Guid.NewGuid(), "Track-1");
@event.AddTrack(Guid.NewGuid(), "Track-1");
@event.Tracks.ShouldContain(x => x.Name == "Track-1");
}
@ -67,9 +67,9 @@ namespace EventHub.Events
"In this event, we will introduce the ABP Framework and explore the fundamental features."
);
@event.AddTract(Guid.NewGuid(), "Track-1");
@event.AddTrack(Guid.NewGuid(), "Track-1");
var exception = Assert.Throws<BusinessException>(() => { @event.AddTract(Guid.NewGuid(), "Track-1"); });
var exception = Assert.Throws<BusinessException>(() => { @event.AddTrack(Guid.NewGuid(), "Track-1"); });
exception.Code.ShouldBe(EventHubErrorCodes.TrackNameAlreadyExist);
}
@ -87,8 +87,8 @@ namespace EventHub.Events
"In this event, we will introduce the ABP Framework and explore the fundamental features."
);
@event.AddTract(Guid.NewGuid(), "Track-1");
@event.AddTract(Guid.NewGuid(), "Track-2");
@event.AddTrack(Guid.NewGuid(), "Track-1");
@event.AddTrack(Guid.NewGuid(), "Track-2");
@event.Tracks.ShouldContain(x => x.Name == "Track-2");
}
@ -107,8 +107,8 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTract(Guid.NewGuid(), "Track-2");
@event.AddTrack(track1Id, "Track-1");
@event.AddTrack(Guid.NewGuid(), "Track-2");
var exception = Assert.Throws<BusinessException>(() => { @event.UpdateTrack(track1Id, "Track-2"); });
@ -147,8 +147,8 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTract(Guid.NewGuid(), "Track-2");
@event.AddTrack(track1Id, "Track-1");
@event.AddTrack(Guid.NewGuid(), "Track-2");
@event.RemoveTrack(track1Id);
@ -187,7 +187,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var session1Id = Guid.NewGuid();
@event.AddSession(track1Id, session1Id, "Session-1 Title", "Session-1 desc".PadLeft(50, 't'), DateTime.Now, DateTime.Now, "en", new List<Guid>());
@ -210,7 +210,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
@event.AddSession(track1Id, Guid.NewGuid(), "Session-1 Title", "Session-1 desc".PadLeft(50, 't'), DateTime.Now, DateTime.Now.AddHours(1), "en", new List<Guid>());
var exception = Assert.Throws<BusinessException>(() =>
@ -235,7 +235,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var exception = Assert.Throws<BusinessException>(() =>
{
@event.AddSession(track1Id, Guid.NewGuid(), "Session-1 Title", "Session-1 desc".PadLeft(50, 't'), DateTime.Now.AddHours(2), DateTime.Now.AddHours(1), "en", new List<Guid>());
@ -258,7 +258,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var exception = Assert.Throws<BusinessException>(() =>
{
@event.AddSession(track1Id, Guid.NewGuid(), "Session-1 Title", "Session-1 desc".PadLeft(50, 't'), DateTime.Now.AddHours(2), DateTime.Now.AddDays(3), "en", new List<Guid>());
@ -281,7 +281,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
@event.AddSession(track1Id, Guid.NewGuid(), "Session-1 Title", "Session-1 desc".PadLeft(50, 't'), DateTime.Now, DateTime.Now.AddDays(1), "en", new List<Guid>());
@ -307,7 +307,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var speakerUserIds = new List<Guid>();
speakerUserIds.Add(_testData.UserAdminId);
@ -337,7 +337,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var speakerUserIds = new List<Guid>();
speakerUserIds.Add(_testData.UserAdminId);
@ -376,7 +376,7 @@ namespace EventHub.Events
);
var track1Id = Guid.NewGuid();
@event.AddTract(track1Id, "Track-1");
@event.AddTrack(track1Id, "Track-1");
var speakerUserIds = new List<Guid>();
speakerUserIds.Add(_testData.UserAdminId);

Loading…
Cancel
Save