Browse Source

Implement IHasCreationTime and IMustHaveCreator for the UserReaction.

pull/4809/head
Halil İbrahim Kalkan 6 years ago
parent
commit
8592ed3f32
  1. 14
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200719204212_Added_Reactions.Designer.cs
  2. 10
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200719204212_Added_Reactions.cs
  3. 10
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs
  4. 7
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/ReactionManager.cs
  5. 13
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/UserReaction.cs
  6. 2
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  7. 4
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs

14
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200715191733_Added_UserReactions.Designer.cs → modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200719204212_Added_Reactions.Designer.cs

@ -11,8 +11,8 @@ using Volo.CmsKit.EntityFrameworkCore;
namespace Volo.CmsKit.Migrations
{
[DbContext(typeof(UnifiedDbContext))]
[Migration("20200715191733_Added_UserReactions")]
partial class Added_UserReactions
[Migration("20200719204212_Added_Reactions")]
partial class Added_Reactions
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -921,8 +921,13 @@ namespace Volo.CmsKit.Migrations
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("uniqueidentifier");
b.Property<string>("EntityId")
.IsRequired()
.HasColumnType("nvarchar(64)")
@ -938,14 +943,11 @@ namespace Volo.CmsKit.Migrations
.HasColumnType("nvarchar(32)")
.HasMaxLength(32);
b.Property<Guid>("UserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("EntityType", "EntityId");
b.HasIndex("UserId", "EntityType", "EntityId", "ReactionName");
b.HasIndex("CreatorId", "EntityType", "EntityId", "ReactionName");
b.ToTable("CmsUserReactions");
});

10
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200715191733_Added_UserReactions.cs → modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200719204212_Added_Reactions.cs

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.CmsKit.Migrations
{
public partial class Added_UserReactions : Migration
public partial class Added_Reactions : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@ -15,8 +15,8 @@ namespace Volo.CmsKit.Migrations
EntityType = table.Column<string>(maxLength: 64, nullable: false),
EntityId = table.Column<string>(maxLength: 64, nullable: false),
ReactionName = table.Column<string>(maxLength: 32, nullable: false),
CreationTime = table.Column<DateTime>(nullable: false),
UserId = table.Column<Guid>(nullable: false)
CreatorId = table.Column<Guid>(nullable: false),
CreationTime = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
@ -29,9 +29,9 @@ namespace Volo.CmsKit.Migrations
columns: new[] { "EntityType", "EntityId" });
migrationBuilder.CreateIndex(
name: "IX_CmsUserReactions_UserId_EntityType_EntityId_ReactionName",
name: "IX_CmsUserReactions_CreatorId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions",
columns: new[] { "UserId", "EntityType", "EntityId", "ReactionName" });
columns: new[] { "CreatorId", "EntityType", "EntityId", "ReactionName" });
}
protected override void Down(MigrationBuilder migrationBuilder)

10
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs

@ -919,8 +919,13 @@ namespace Volo.CmsKit.Migrations
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("uniqueidentifier");
b.Property<string>("EntityId")
.IsRequired()
.HasColumnType("nvarchar(64)")
@ -936,14 +941,11 @@ namespace Volo.CmsKit.Migrations
.HasColumnType("nvarchar(32)")
.HasMaxLength(32);
b.Property<Guid>("UserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("EntityType", "EntityId");
b.HasIndex("UserId", "EntityType", "EntityId", "ReactionName");
b.HasIndex("CreatorId", "EntityType", "EntityId", "ReactionName");
b.ToTable("CmsUserReactions");
});

7
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/ReactionManager.cs

@ -51,7 +51,7 @@ namespace Volo.CmsKit.Reactions
}
public virtual async Task<UserReaction> CreateAsync(
Guid userId,
Guid creatorId,
[NotNull] string entityType,
[NotNull] string entityId,
[NotNull] string reactionName)
@ -60,7 +60,7 @@ namespace Volo.CmsKit.Reactions
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName));
var existingReaction = await UserReactionRepository.FindAsync(userId, entityType, entityId, reactionName);
var existingReaction = await UserReactionRepository.FindAsync(creatorId, entityType, entityId, reactionName);
if (existingReaction != null)
{
return existingReaction;
@ -69,11 +69,10 @@ namespace Volo.CmsKit.Reactions
return await UserReactionRepository.InsertAsync(
new UserReaction(
GuidGenerator.Create(),
userId,
entityType,
entityId,
reactionName,
Clock.Now
creatorId
)
);
}

13
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/UserReaction.cs

@ -1,11 +1,12 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
namespace Volo.CmsKit.Reactions
{
public class UserReaction : Entity<Guid>, IAggregateRoot<Guid>
public class UserReaction : Entity<Guid>, IAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator
{
public virtual string EntityType { get; protected set; }
@ -13,9 +14,9 @@ namespace Volo.CmsKit.Reactions
public virtual string ReactionName { get; protected set; }
public virtual DateTime CreationTime { get; protected set; }
public virtual Guid CreatorId { get; set; }
public virtual Guid UserId { get; protected set; }
public virtual DateTime CreationTime { get; set; }
protected UserReaction()
{
@ -24,18 +25,16 @@ namespace Volo.CmsKit.Reactions
internal UserReaction(
Guid id,
Guid userId,
[NotNull] string entityType,
[NotNull] string entityId,
[NotNull] string reactionName,
DateTime creationTime)
Guid creatorId)
: base(id)
{
EntityType = Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
ReactionName = Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName));
UserId = userId;
CreationTime = creationTime;
CreatorId = creatorId;
}
}
}

2
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -32,7 +32,7 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.CreationTime);
b.HasIndex(x => new { x.EntityType, x.EntityId });
b.HasIndex(x => new { x.UserId, x.EntityType, x.EntityId, x.ReactionName });
b.HasIndex(x => new { x.CreatorId, x.EntityType, x.EntityId, x.ReactionName });
});
}
}

4
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Reactions/EfCoreUserReactionRepository.cs

@ -30,7 +30,7 @@ namespace Volo.CmsKit.Reactions
return await DbSet
.Where(x =>
x.UserId == userId &&
x.CreatorId == userId &&
x.EntityType == entityType &&
x.EntityId == entityId &&
x.ReactionName == reactionName)
@ -47,7 +47,7 @@ namespace Volo.CmsKit.Reactions
return await DbSet
.Where(x =>
x.UserId == userId &&
x.CreatorId == userId &&
x.EntityType == entityType &&
x.EntityId == entityId)
.ToListAsync();

Loading…
Cancel
Save