Add FluentValidation to application services
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m45s

This commit is contained in:
2026-07-07 16:31:29 +09:00
parent 68cc97eda6
commit c54599304b
9 changed files with 110 additions and 38 deletions
@@ -1,13 +1,14 @@
namespace TaxBaik.Application.Services;
using System.Text.RegularExpressions;
using FluentValidation;
using TaxBaik.Application.DTOs;
using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;
using Microsoft.Extensions.Caching.Memory;
public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCache)
public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCache, IValidator<CreateBlogPostDto> validator)
{
public async Task<BlogPost?> GetByIdAsync(int id, CancellationToken ct = default) =>
await repository.GetByIdAsync(id, ct);
@@ -60,6 +61,7 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
public async Task<BlogPost> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default)
{
validator.ValidateAndThrow(dto);
var post = new BlogPost
{
Title = dto.Title,
@@ -87,6 +89,7 @@ public class BlogService(IBlogPostRepository repository, IMemoryCache memoryCach
public async Task<BlogPost?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
{
validator.ValidateAndThrow(dto);
var post = await repository.GetByIdAsync(id, ct);
if (post == null)
return null;