Add FluentValidation to application services
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m45s
TaxBaik CI/CD / build-and-deploy (push) Successful in 2m45s
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user