Skip to content

Commit

Permalink
add log for create edit post
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed May 7, 2024
1 parent 15f5521 commit 521013d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Moonglade.Core/PostFeature/CreatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public async Task<PostEntity> Handle(CreatePostCommand request, CancellationToke

await postRepo.AddAsync(post, ct);

logger.LogInformation($"Created post Id: {post.Id}, Title: '{post.Title}'");
return post;
}

Expand All @@ -104,6 +105,8 @@ private async Task<TagEntity> CreateTag(string item)
};

var tag = await tagRepo.AddAsync(newTag);

logger.LogInformation($"Created tag: {tag.DisplayName}");
return tag;
}
}
9 changes: 8 additions & 1 deletion src/Moonglade.Core/PostFeature/UpdatePostCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Edi.CacheAside.InMemory;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Moonglade.Configuration;
using Moonglade.Data;
using Moonglade.Data.Specifications;
Expand All @@ -18,6 +19,7 @@ public class UpdatePostCommandHandler : IRequestHandler<UpdatePostCommand, PostE
private readonly ICacheAside _cache;
private readonly IBlogConfig _blogConfig;
private readonly IConfiguration _configuration;
private readonly ILogger<UpdatePostCommandHandler> _logger;
private readonly bool _useMySqlWorkaround;

public UpdatePostCommandHandler(
Expand All @@ -26,7 +28,9 @@ public class UpdatePostCommandHandler : IRequestHandler<UpdatePostCommand, PostE
MoongladeRepository<TagEntity> tagRepo,
MoongladeRepository<PostEntity> postRepo,
ICacheAside cache,
IBlogConfig blogConfig, IConfiguration configuration)
IBlogConfig blogConfig,
IConfiguration configuration,
ILogger<UpdatePostCommandHandler> logger)
{
_ptRepository = ptRepository;
_pcRepository = pcRepository;
Expand All @@ -35,6 +39,7 @@ public class UpdatePostCommandHandler : IRequestHandler<UpdatePostCommand, PostE
_cache = cache;
_blogConfig = blogConfig;
_configuration = configuration;
_logger = logger;

string dbType = configuration.GetConnectionString("DatabaseType");
_useMySqlWorkaround = dbType!.ToLower().Trim() == "mysql";
Expand Down Expand Up @@ -150,6 +155,8 @@ await _tagRepo.AddAsync(new()
await _postRepo.UpdateAsync(post, ct);

_cache.Remove(BlogCachePartition.Post.ToString(), checkSum.ToString());

_logger.LogInformation($"Post updated: {post.Id}");
return post;
}
}

0 comments on commit 521013d

Please sign in to comment.