Skip to content

Commit

Permalink
logging for friend link CUD
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed May 8, 2024
1 parent 47a8bfe commit a1569de
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Moonglade.Comments/DeleteCommentsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Moonglade.Comments;
public record DeleteCommentsCommand(Guid[] Ids) : IRequest;

public class DeleteCommentsCommandHandler(
MoongladeRepository<CommentEntity> commentRepo,
MoongladeRepository<CommentEntity> commentRepo,
ILogger<DeleteCommentsCommandHandler> logger) : IRequestHandler<DeleteCommentsCommand>
{
public async Task Handle(DeleteCommentsCommand request, CancellationToken ct)
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Comments/ToggleApprovalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Moonglade.Comments;
public record ToggleApprovalCommand(Guid[] CommentIds) : IRequest;

public class ToggleApprovalCommandHandler(
MoongladeRepository<CommentEntity> repo,
MoongladeRepository<CommentEntity> repo,
ILogger<ToggleApprovalCommandHandler> logger) : IRequestHandler<ToggleApprovalCommand>
{
public async Task Handle(ToggleApprovalCommand request, CancellationToken ct)
Expand Down
6 changes: 3 additions & 3 deletions src/Moonglade.FriendLink/AddLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using MediatR;
using Microsoft.Extensions.Logging;
using Moonglade.Data;
using Moonglade.Data.Entities;
using Moonglade.Utils;
using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Logging;

namespace Moonglade.FriendLink;

Expand Down Expand Up @@ -35,7 +35,7 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
public record AddLinkCommand(EditLinkRequest Payload) : IRequest;

public class AddLinkCommandHandler(
MoongladeRepository<FriendLinkEntity> repo,
MoongladeRepository<FriendLinkEntity> repo,
ILogger<AddLinkCommandHandler> logger) : IRequestHandler<AddLinkCommand>
{
public async Task Handle(AddLinkCommand request, CancellationToken ct)
Expand All @@ -49,7 +49,7 @@ public async Task Handle(AddLinkCommand request, CancellationToken ct)
};

await repo.AddAsync(link, ct);

logger.LogInformation("Added a new friend link: {Title}", link.Title);
}
}
7 changes: 6 additions & 1 deletion src/Moonglade.FriendLink/DeleteLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using MediatR;
using Microsoft.Extensions.Logging;
using Moonglade.Data;
using Moonglade.Data.Entities;

namespace Moonglade.FriendLink;

public record DeleteLinkCommand(Guid Id) : IRequest;

public class DeleteLinkCommandHandler(MoongladeRepository<FriendLinkEntity> repo) : IRequestHandler<DeleteLinkCommand>
public class DeleteLinkCommandHandler(
MoongladeRepository<FriendLinkEntity> repo,
ILogger<DeleteLinkCommandHandler> logger) : IRequestHandler<DeleteLinkCommand>
{
public async Task Handle(DeleteLinkCommand request, CancellationToken ct)
{
Expand All @@ -15,5 +18,7 @@ public async Task Handle(DeleteLinkCommand request, CancellationToken ct)
{
await repo.DeleteAsync(link, ct);
}

logger.LogInformation("Deleted a friend link: {Title}", link?.Title);
}
}
7 changes: 6 additions & 1 deletion src/Moonglade.FriendLink/UpdateLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Microsoft.Extensions.Logging;
using Moonglade.Data;
using Moonglade.Data.Entities;
using Moonglade.Utils;
Expand All @@ -7,7 +8,9 @@ namespace Moonglade.FriendLink;

public record UpdateLinkCommand(Guid Id, EditLinkRequest Payload) : IRequest;

public class UpdateLinkCommandHandler(MoongladeRepository<FriendLinkEntity> repo) : IRequestHandler<UpdateLinkCommand>
public class UpdateLinkCommandHandler(
MoongladeRepository<FriendLinkEntity> repo,
ILogger<UpdateLinkCommandHandler> logger) : IRequestHandler<UpdateLinkCommand>
{
public async Task Handle(UpdateLinkCommand request, CancellationToken ct)
{
Expand All @@ -25,5 +28,7 @@ public async Task Handle(UpdateLinkCommand request, CancellationToken ct)

await repo.UpdateAsync(link, ct);
}

logger.LogInformation("Updated link: {LinkId}", request.Id);
}
}

0 comments on commit a1569de

Please sign in to comment.