Skip to content

Commit a0eb924

Browse files
committed
Add last comment fields for claims
1 parent f2cca9c commit a0eb924

File tree

8 files changed

+244
-15
lines changed

8 files changed

+244
-15
lines changed

src/JoinRpg.Dal.Impl/Migrations/202106200922043_LastCommentDates.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace JoinRpg.Dal.Impl.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
6+
public partial class LastCommentDates : DbMigration
7+
{
8+
public override void Up()
9+
{
10+
AddColumn("dbo.Claims", "LastMasterCommentAt", c => c.DateTimeOffset(precision: 7));
11+
AddColumn("dbo.Claims", "LastMasterCommentBy_Id", c => c.Int());
12+
AddColumn("dbo.Claims", "LastVisibleMasterCommentAt", c => c.DateTimeOffset(precision: 7));
13+
AddColumn("dbo.Claims", "LastVisibleMasterCommentBy_Id", c => c.Int());
14+
AddColumn("dbo.Claims", "LastPlayerCommentAt", c => c.DateTimeOffset(precision: 7));
15+
CreateIndex("dbo.Claims", "LastMasterCommentBy_Id");
16+
CreateIndex("dbo.Claims", "LastVisibleMasterCommentBy_Id");
17+
AddForeignKey("dbo.Claims", "LastMasterCommentBy_Id", "dbo.Users", "UserId");
18+
AddForeignKey("dbo.Claims", "LastVisibleMasterCommentBy_Id", "dbo.Users", "UserId");
19+
}
20+
21+
public override void Down()
22+
{
23+
DropForeignKey("dbo.Claims", "LastVisibleMasterCommentBy_Id", "dbo.Users");
24+
DropForeignKey("dbo.Claims", "LastMasterCommentBy_Id", "dbo.Users");
25+
DropIndex("dbo.Claims", new[] { "LastVisibleMasterCommentBy_Id" });
26+
DropIndex("dbo.Claims", new[] { "LastMasterCommentBy_Id" });
27+
DropColumn("dbo.Claims", "LastPlayerCommentAt");
28+
DropColumn("dbo.Claims", "LastVisibleMasterCommentBy_Id");
29+
DropColumn("dbo.Claims", "LastVisibleMasterCommentAt");
30+
DropColumn("dbo.Claims", "LastMasterCommentBy_Id");
31+
DropColumn("dbo.Claims", "LastMasterCommentAt");
32+
}
33+
}
34+
}

src/JoinRpg.Dal.Impl/Migrations/202106200922043_LastCommentDates.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/JoinRpg.DataModel/Claim.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ public IEnumerable<FinanceOperation> ApprovedFinanceOperations
133133

134134
#endregion
135135

136-
136+
public DateTimeOffset? LastMasterCommentAt { get; set; }
137+
[ForeignKey(nameof(LastMasterCommentBy_Id))]
138+
public User? LastMasterCommentBy { get; set; }
139+
public int? LastMasterCommentBy_Id { get; set; }
140+
141+
public DateTimeOffset? LastVisibleMasterCommentAt { get; set; }
142+
[ForeignKey(nameof(LastVisibleMasterCommentBy_Id))]
143+
public User? LastVisibleMasterCommentBy { get; set; }
144+
public int? LastVisibleMasterCommentBy_Id { get; set; }
145+
public DateTimeOffset? LastPlayerCommentAt { get; set; }
137146

138147
#region ILinkable impl
139148

src/JoinRpg.Services.Impl/ClaimImplBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,13 @@ protected Comment AddCommentImpl(Claim claim,
3333
bool isVisibleToPlayer,
3434
CommentExtraAction? extraAction = null)
3535
{
36-
37-
38-
var comment = CommentHelper.CreateCommentForDiscussion(claim.CommentDiscussion,
36+
var comment = CommentHelper.CreateCommentForClaim(claim,
3937
CurrentUserId,
4038
Now,
4139
commentText,
4240
isVisibleToPlayer,
4341
parentComment,
4442
extraAction);
45-
46-
claim.LastUpdateDateTime = Now;
47-
4843
return comment;
4944
}
5045

src/JoinRpg.Services.Impl/CommentHelper.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,42 @@ namespace JoinRpg.Services.Impl
77
{
88
internal static class CommentHelper
99
{
10+
public static Comment CreateCommentForClaim(
11+
Claim claim,
12+
int currentUserId,
13+
DateTime createdAt,
14+
string commentText,
15+
bool isVisibleToPlayer,
16+
Comment? parentComment,
17+
CommentExtraAction? extraAction = null)
18+
{
19+
var comment = CreateCommentForDiscussion(claim.CommentDiscussion,
20+
currentUserId,
21+
createdAt,
22+
commentText,
23+
isVisibleToPlayer,
24+
parentComment,
25+
extraAction);
26+
27+
claim.LastUpdateDateTime = createdAt;
28+
if (claim.Player.UserId == currentUserId)
29+
{
30+
claim.LastPlayerCommentAt = createdAt;
31+
}
32+
else
33+
{
34+
claim.LastMasterCommentAt = createdAt;
35+
claim.LastMasterCommentBy_Id = currentUserId;
36+
37+
if (isVisibleToPlayer)
38+
{
39+
claim.LastVisibleMasterCommentAt = createdAt;
40+
claim.LastVisibleMasterCommentBy_Id = currentUserId;
41+
}
42+
}
43+
44+
return comment;
45+
}
1046
public static Comment CreateCommentForDiscussion([NotNull]
1147
CommentDiscussion commentDiscussion,
1248
int currentUserId,

src/JoinRpg.Services.Impl/FinanceOperationsImpl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ private async Task<Tuple<Comment, Comment>> AddTransferCommentsAsync(
334334
ClaimPaymentTransferRequest request)
335335
{
336336
// Comment to source claim
337-
Comment commentFrom = CommentHelper.CreateCommentForDiscussion(
338-
claimFrom.CommentDiscussion,
337+
Comment commentFrom = CommentHelper.CreateCommentForClaim(
338+
claimFrom,
339339
CurrentUserId,
340340
Now,
341341
request.CommentText,
@@ -356,8 +356,8 @@ private async Task<Tuple<Comment, Comment>> AddTransferCommentsAsync(
356356
_ = UnitOfWork.GetDbSet<Comment>().Add(commentFrom);
357357

358358
// Comment to destination claim
359-
Comment commentTo = CommentHelper.CreateCommentForDiscussion(
360-
claimTo.CommentDiscussion,
359+
Comment commentTo = CommentHelper.CreateCommentForClaim(
360+
claimTo,
361361
CurrentUserId,
362362
Now,
363363
request.CommentText,

src/JoinRpg.Services.Impl/PaymentsService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public async Task<ClaimPaymentContext> InitiateClaimPaymentAsync(ClaimPaymentReq
133133
PaymentRequestDescriptor result = await GetApi(request.ProjectId, request.ClaimId)
134134
.BuildPaymentRequestAsync(
135135
message,
136-
async () => (await AddPaymentCommentAsync(claim.CommentDiscussion, onlinePaymentType, request))
136+
async () => (await AddPaymentCommentAsync(claim, onlinePaymentType, request))
137137
.CommentId
138138
.ToString()
139139
.PadLeft(10, '0')
@@ -147,12 +147,12 @@ public async Task<ClaimPaymentContext> InitiateClaimPaymentAsync(ClaimPaymentReq
147147
}
148148

149149
private async Task<Comment> AddPaymentCommentAsync(
150-
CommentDiscussion discussion,
150+
Claim claim,
151151
PaymentType paymentType,
152152
ClaimPaymentRequest request)
153153
{
154-
Comment comment = CommentHelper.CreateCommentForDiscussion(
155-
discussion,
154+
Comment comment = CommentHelper.CreateCommentForClaim(
155+
claim,
156156
CurrentUserId,
157157
Now,
158158
request.CommentText ?? "",

0 commit comments

Comments
 (0)