43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
namespace TaxBaik.Application.Services;
|
|
|
|
using TaxBaik.Domain.Entities;
|
|
using TaxBaik.Domain.Interfaces;
|
|
|
|
public class FaqService(IFaqRepository repository)
|
|
{
|
|
public static readonly string[] Categories =
|
|
["기장세금신고", "부동산", "증여상속", "기타"];
|
|
|
|
public async Task<IEnumerable<Faq>> GetActiveAsync(CancellationToken ct = default) =>
|
|
await repository.GetActiveAsync(ct);
|
|
|
|
public async Task<IEnumerable<Faq>> GetAllAsync(CancellationToken ct = default) =>
|
|
await repository.GetAllAsync(ct);
|
|
|
|
public async Task<Faq?> GetByIdAsync(int id, CancellationToken ct = default) =>
|
|
await repository.GetByIdAsync(id, ct);
|
|
|
|
public async Task<int> CreateAsync(Faq faq, CancellationToken ct = default)
|
|
{
|
|
Validate(faq);
|
|
return await repository.CreateAsync(faq, ct);
|
|
}
|
|
|
|
public async Task UpdateAsync(Faq faq, CancellationToken ct = default)
|
|
{
|
|
Validate(faq);
|
|
await repository.UpdateAsync(faq, ct);
|
|
}
|
|
|
|
public async Task DeleteAsync(int id, CancellationToken ct = default) =>
|
|
await repository.DeleteAsync(id, ct);
|
|
|
|
private static void Validate(Faq faq)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(faq.Question))
|
|
throw new ValidationException("질문을 입력하세요.");
|
|
if (string.IsNullOrWhiteSpace(faq.Answer))
|
|
throw new ValidationException("답변을 입력하세요.");
|
|
}
|
|
}
|