e22cfb1ac5
TaxBaik CI/CD / build-and-deploy (push) Failing after 43s
4개 API 컨트롤러 구현: ✅ AuthController: POST /api/auth/login ✅ BlogController: GET/POST/PUT/DELETE /api/blog ✅ CategoryController: GET/POST/PUT/DELETE /api/category ✅ InquiryController: POST/GET/PUT /api/inquiry 아키텍처 개선: - Application 서비스 레이어 확장 (CategoryService 추가) - Repository 인터페이스 CRUD 지원 추가 - Program.cs에 MapControllers() 추가 - 비즈니스 로직과 UI 완전 분리 장점: - 향후 UI 리뉴얼 시 API 변경 불필요 - 모바일 앱, 데스크톱 클라이언트 추가 가능 - 테스트 가능한 API 엔드포인트 테스트 결과: ✅ 블로그 API: 5개 포스트 조회 ✅ 카테고리 API: 5개 카테고리 조회 ✅ 문의 API: 문의 제출 성공 ⚠️ 인증 API: 예정된 수정 대기 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
namespace TaxBaik.Application.Services;
|
|
|
|
using System.Text.RegularExpressions;
|
|
using TaxBaik.Domain.Entities;
|
|
using TaxBaik.Domain.Interfaces;
|
|
|
|
public class CategoryService(ICategoryRepository repository)
|
|
{
|
|
public async Task<IEnumerable<Category>> GetAllAsync(CancellationToken ct = default) =>
|
|
await repository.GetAllAsync(ct);
|
|
|
|
public async Task<Category?> GetBySlugAsync(string slug, CancellationToken ct = default) =>
|
|
await repository.GetBySlugAsync(slug, ct);
|
|
|
|
public async Task<Category?> GetByIdAsync(int id, CancellationToken ct = default) =>
|
|
await repository.GetByIdAsync(id, ct);
|
|
|
|
public async Task<Category> CreateAsync(string name, string? description, CancellationToken ct = default)
|
|
{
|
|
var slug = GenerateSlug(name);
|
|
var category = new Category
|
|
{
|
|
Name = name.Trim(),
|
|
Slug = slug,
|
|
SortOrder = 0
|
|
};
|
|
|
|
var id = await repository.CreateAsync(category, ct);
|
|
return new Category { Id = id, Name = category.Name, Slug = category.Slug, SortOrder = category.SortOrder };
|
|
}
|
|
|
|
public async Task<Category?> UpdateAsync(int id, string name, string? description, CancellationToken ct = default)
|
|
{
|
|
var category = await repository.GetByIdAsync(id, ct);
|
|
if (category == null)
|
|
return null;
|
|
|
|
category.Name = name.Trim();
|
|
category.Slug = GenerateSlug(name);
|
|
await repository.UpdateAsync(category, ct);
|
|
return category;
|
|
}
|
|
|
|
public async Task DeleteAsync(int id, CancellationToken ct = default) =>
|
|
await repository.DeleteAsync(id, ct);
|
|
|
|
private static string GenerateSlug(string name)
|
|
{
|
|
var slug = Regex.Replace(name.ToLowerInvariant(), @"[^\w\s-]", "");
|
|
slug = Regex.Replace(slug, @"\s+", "-");
|
|
slug = Regex.Replace(slug, @"-+", "-").Trim('-');
|
|
return slug.Length > 100 ? slug[..100] : slug;
|
|
}
|
|
}
|