Browse Source

Implemented event creation

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
040b5b529d
  1. 1
      eventhub/src/EventHub.Application.Contracts/Events/CreateEventDto.cs
  2. 39
      eventhub/src/EventHub.Application/Events/EventAppService.cs
  3. 4
      eventhub/src/EventHub.Application/Organizations/OrganizationAppService.cs
  4. 1
      eventhub/src/EventHub.Domain.Shared/EventHubErrorCodes.cs
  5. 1
      eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json
  6. 4
      eventhub/src/EventHub.Domain/EventHub.Domain.csproj
  7. 62
      eventhub/src/EventHub.Domain/Events/Event.cs
  8. 27
      eventhub/src/EventHub.Domain/Events/EventManager.cs
  9. 13
      eventhub/src/EventHub.Domain/Organizations/Organization.cs
  10. 4
      eventhub/src/EventHub.Domain/Organizations/OrganizationManager.cs
  11. 2356
      eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210123172353_Added_Events.Designer.cs
  12. 146
      eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210123172353_Added_Events.cs
  13. 114
      eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/EventHubMigrationsDbContextModelSnapshot.cs
  14. 5
      eventhub/src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContext.cs
  15. 16
      eventhub/src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContextModelCreatingExtensions.cs
  16. 30
      eventhub/test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

1
eventhub/src/EventHub.Application.Contracts/Events/CreateEventDto.cs

@ -5,6 +5,7 @@ namespace EventHub.Events
{
public class CreateEventDto
{
[Required]
public Guid OrganizationId { get; set; }
[Required]

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

@ -1,12 +1,49 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using EventHub.Organizations;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
namespace EventHub.Events
{
public class EventAppService : EventHubAppService, IEventAppService
{
private readonly IRepository<Organization, Guid> _organizationRepository;
private readonly EventManager _eventManager;
private readonly IRepository<Event, Guid> _eventRepository;
public EventAppService(
EventManager eventManager,
IRepository<Organization, Guid> organizationRepository,
IRepository<Event, Guid> eventRepository)
{
_eventManager = eventManager;
_organizationRepository = organizationRepository;
_eventRepository = eventRepository;
}
[Authorize]
public async Task CreateAsync(CreateEventDto input)
{
var organization = await _organizationRepository.GetAsync(input.OrganizationId);
if (organization.OwnerUserId != CurrentUser.GetId())
{
throw new BusinessException(EventHubErrorCodes.NotAuthorizedToCreateEventInThisOrganization)
.WithData("OrganizationName", organization.DisplayName);
}
var @event = await _eventManager.CreateAsync(
organization,
input.Title,
input.StartTime,
input.EndTime,
input.Description
);
await _eventRepository.InsertAsync(@event);
}
}
}

4
eventhub/src/EventHub.Application/Organizations/OrganizationAppService.cs

@ -25,12 +25,14 @@ namespace EventHub.Organizations
[Authorize]
public async Task CreateAsync(CreateOrganizationDto input)
{
await _organizationManager.CreateAsync(
var organization = await _organizationManager.CreateAsync(
CurrentUser.GetId(),
input.Name,
input.DisplayName,
input.Description
);
await _organizationRepository.InsertAsync(organization);
}
public async Task<PagedResultDto<OrganizationInListDto>> GetListAsync(PagedResultRequestDto input)

1
eventhub/src/EventHub.Domain.Shared/EventHubErrorCodes.cs

@ -3,5 +3,6 @@
public static class EventHubErrorCodes
{
public const string OrganizationNameAlreadyExists = "EventHub:OrganizationNameAlreadyExists";
public const string NotAuthorizedToCreateEventInThisOrganization = "EventHub:NotAuthorizedToCreateEventInThisOrganization";
}
}

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

@ -17,6 +17,7 @@
"DisplayName:IsOnline": "Is Online?",
"DisplayName:Capacity": "Capacity",
"EventHub:OrganizationNameAlreadyExists": "The organization {Name} already exists. Please use another name.",
"EventHub:NotAuthorizedToCreateEventInThisOrganization": "You are not authorized to create events for the organization {OrganizationName}",
"Events": "Events",
"Members": "Members",
"SeeOrganization": "See Organization",

4
eventhub/src/EventHub.Domain/EventHub.Domain.csproj

@ -22,8 +22,4 @@
<PackageReference Include="Volo.Abp.SettingManagement.Domain" Version="4.2.0-rc.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Events" />
</ItemGroup>
</Project>

62
eventhub/src/EventHub.Domain/Events/Event.cs

@ -0,0 +1,62 @@
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
namespace EventHub.Events
{
public class Event : FullAuditedAggregateRoot<Guid>
{
public Guid OrganizationId { get; private set; }
public string Title { get; private set; }
public DateTime StartTime { get; private set; }
public DateTime EndTime { get; private set; }
public string Description { get; private set; }
public bool IsOnline { get; set; }
public int? Capacity { get; set; }
private Event()
{
}
public Event(
Guid id,
Guid organizationId,
string title,
DateTime startTime,
DateTime endTime,
string description)
: base(id)
{
OrganizationId = organizationId;
SetTitle(title);
SetDescription(description);
SetTime(startTime, endTime);
}
public Event SetTitle(string title)
{
Title = Check.NotNullOrWhiteSpace(title, nameof(title), EventConsts.MaxTitleLength, EventConsts.MinTitleLength);
return this;
}
public Event SetDescription(string description)
{
Description = Check.NotNullOrWhiteSpace(description, nameof(description), EventConsts.MaxDescriptionLength, EventConsts.MinDescriptionLength);
return this;
}
public Event SetTime(DateTime startTime, DateTime endTime)
{
StartTime = startTime;
EndTime = endTime;
return this;
}
}
}

27
eventhub/src/EventHub.Domain/Events/EventManager.cs

@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using EventHub.Organizations;
using Volo.Abp.Domain.Services;
namespace EventHub.Events
{
public class EventManager : DomainService
{
public async Task<Event> CreateAsync(
Organization organization,
string title,
DateTime startTime,
DateTime endTime,
string description)
{
return new Event(
GuidGenerator.Create(),
organization.Id,
title,
startTime,
endTime,
description
);
}
}
}

13
eventhub/src/EventHub.Domain/Organizations/Organization.cs

@ -1,10 +1,10 @@
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
namespace EventHub.Organizations
{
public class Organization : AggregateRoot<Guid>
public class Organization : FullAuditedAggregateRoot<Guid>
{
public Guid OwnerUserId { get; set; }
@ -44,19 +44,22 @@ namespace EventHub.Organizations
SetDescription(description);
}
internal void SetName(string name)
internal Organization SetName(string name)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name), OrganizationConsts.MaxNameLength, OrganizationConsts.MinNameLength);
return this;
}
public void SetDisplayName(string displayName)
public Organization SetDisplayName(string displayName)
{
DisplayName = Check.NotNullOrWhiteSpace(displayName, nameof(displayName), OrganizationConsts.MaxDisplayNameLength, OrganizationConsts.MinDisplayNameLength);
return this;
}
public void SetDescription(string description)
public Organization SetDescription(string description)
{
Description = Check.NotNullOrWhiteSpace(description, nameof(description), OrganizationConsts.MaxDescriptionNameLength, OrganizationConsts.MinDescriptionNameLength);
return this;
}
}
}

4
eventhub/src/EventHub.Domain/Organizations/OrganizationManager.cs

@ -27,15 +27,13 @@ namespace EventHub.Organizations
.WithData("Name", name);
}
var organization = new Organization(
return new Organization(
GuidGenerator.Create(),
ownerUserId,
name,
displayName,
description
);
return await _organizationRepository.InsertAsync(organization);
}
}
}

2356
eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210123172353_Added_Events.Designer.cs

File diff suppressed because it is too large

146
eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210123172353_Added_Events.cs

@ -0,0 +1,146 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace EventHub.Migrations
{
public partial class Added_Events : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "AppOrganizations",
type: "nvarchar(1000)",
maxLength: 1000,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "CreationTime",
table: "AppOrganizations",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<Guid>(
name: "CreatorId",
table: "AppOrganizations",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "DeleterId",
table: "AppOrganizations",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "DeletionTime",
table: "AppOrganizations",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
table: "AppOrganizations",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<DateTime>(
name: "LastModificationTime",
table: "AppOrganizations",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "LastModifierId",
table: "AppOrganizations",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.CreateTable(
name: "AppEvents",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
OrganizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Title = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
StartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
EndTime = table.Column<DateTime>(type: "datetime2", nullable: false),
Description = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
IsOnline = table.Column<bool>(type: "bit", nullable: false),
Capacity = table.Column<int>(type: "int", nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AppEvents", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AppEvents_OrganizationId_StartTime",
table: "AppEvents",
columns: new[] { "OrganizationId", "StartTime" });
migrationBuilder.CreateIndex(
name: "IX_AppEvents_StartTime",
table: "AppEvents",
column: "StartTime");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppEvents");
migrationBuilder.DropColumn(
name: "CreationTime",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "CreatorId",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "DeleterId",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "DeletionTime",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "IsDeleted",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "LastModificationTime",
table: "AppOrganizations");
migrationBuilder.DropColumn(
name: "LastModifierId",
table: "AppOrganizations");
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "AppOrganizations",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(1000)",
oldMaxLength: 1000);
}
}
}

114
eventhub/src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/EventHubMigrationsDbContextModelSnapshot.cs

@ -21,6 +21,86 @@ namespace EventHub.Migrations
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.2");
modelBuilder.Entity("EventHub.Events.Event", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<int?>("Capacity")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("uniqueidentifier")
.HasColumnName("CreatorId");
b.Property<Guid?>("DeleterId")
.HasColumnType("uniqueidentifier")
.HasColumnName("DeleterId");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("nvarchar(2000)");
b.Property<DateTime>("EndTime")
.HasColumnType("datetime2");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<bool>("IsOnline")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");
b.Property<Guid>("OrganizationId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("StartTime")
.HasColumnType("datetime2");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.HasKey("Id");
b.HasIndex("StartTime");
b.HasIndex("OrganizationId", "StartTime");
b.ToTable("AppEvents");
});
modelBuilder.Entity("EventHub.Organizations.Organization", b =>
{
b.Property<Guid>("Id")
@ -33,8 +113,26 @@ namespace EventHub.Migrations
.HasColumnType("nvarchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("uniqueidentifier")
.HasColumnName("CreatorId");
b.Property<Guid?>("DeleterId")
.HasColumnType("uniqueidentifier")
.HasColumnName("DeleterId");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("nvarchar(1000)");
b.Property<string>("DisplayName")
.IsRequired()
@ -54,6 +152,20 @@ namespace EventHub.Migrations
b.Property<string>("InstagramUsername")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");
b.Property<string>("MediumUsername")
.HasColumnType("nvarchar(max)");

5
eventhub/src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContext.cs

@ -1,4 +1,5 @@
using EventHub.Organizations;
using EventHub.Events;
using EventHub.Organizations;
using Microsoft.EntityFrameworkCore;
using EventHub.Users;
using Volo.Abp.Data;
@ -22,8 +23,8 @@ namespace EventHub.EntityFrameworkCore
public class EventHubDbContext : AbpDbContext<EventHubDbContext>
{
public DbSet<AppUser> Users { get; set; }
public DbSet<Organization> Organizations { get; set; }
public DbSet<Event> Events { get; set; }
public EventHubDbContext(DbContextOptions<EventHubDbContext> options)
: base(options)

16
eventhub/src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContextModelCreatingExtensions.cs

@ -1,4 +1,5 @@
using EventHub.Organizations;
using EventHub.Events;
using EventHub.Organizations;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
@ -26,6 +27,19 @@ namespace EventHub.EntityFrameworkCore
b.HasIndex(x => x.Name);
b.HasIndex(x => x.DisplayName);
});
builder.Entity<Event>(b =>
{
b.ToTable(EventHubConsts.DbTablePrefix + "Events", EventHubConsts.DbSchema);
b.ConfigureByConvention();
b.Property(x => x.Title).IsRequired().HasMaxLength(EventConsts.MaxTitleLength);
b.Property(x => x.Description).IsRequired().HasMaxLength(EventConsts.MaxDescriptionLength);
b.HasIndex(x => new {x.OrganizationId, x.StartTime});
b.HasIndex(x => x.StartTime);
});
}
}
}

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

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using EventHub.Organizations;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
namespace EventHub
@ -10,17 +11,20 @@ namespace EventHub
public class EventHubTestDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly OrganizationManager _organizationManager;
private readonly IRepository<Organization, Guid> _organizationRepository;
private readonly ICurrentUser _currentUser;
private readonly EventHubTestData _eventHubTestData;
public EventHubTestDataSeedContributor(
EventHubTestData eventHubTestData,
OrganizationManager organizationManager,
ICurrentUser currentUser)
ICurrentUser currentUser,
IRepository<Organization, Guid> organizationRepository)
{
_eventHubTestData = eventHubTestData;
_organizationManager = organizationManager;
_currentUser = currentUser;
_organizationRepository = organizationRepository;
}
public async Task SeedAsync(DataSeedContext context)
@ -30,19 +34,23 @@ namespace EventHub
private async Task CreateOrganizationsAsync()
{
var volosoft = await _organizationManager.CreateAsync(
_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."
var volosoft = await _organizationRepository.InsertAsync(
await _organizationManager.CreateAsync(
_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 _organizationManager.CreateAsync(
_currentUser.GetId(),
_eventHubTestData.OrganizationDotnetEuropeName,
"Dotnet Europe",
"Organizing events on Microsoft's .NET Platform in European Countries."
var dotnetEurope = await _organizationRepository.InsertAsync(
await _organizationManager.CreateAsync(
_currentUser.GetId(),
_eventHubTestData.OrganizationDotnetEuropeName,
"Dotnet Europe",
"Organizing events on Microsoft's .NET Platform in European Countries."
)
);
_eventHubTestData.OrganizationDotnetEuropeId = dotnetEurope.Id;
}

Loading…
Cancel
Save