using Easy.Admin.Application.Blog.Dtos; namespace Easy.Admin.Application.Blog; /// /// 文章栏目管理 /// public class CategoryService : BaseService { private readonly ISqlSugarRepository _repository; public CategoryService(ISqlSugarRepository repository) : base(repository) { _repository = repository; } /// /// 文章栏目列表 /// /// /// [DisplayName("文章栏目列表")] [HttpGet] public async Task> Page([FromQuery] string name) { if (!string.IsNullOrWhiteSpace(name)) { var list = await _repository.AsQueryable().Where(x => x.Name.Contains(name)).ToListAsync(); return list.Adapt>(); } var tree = await _repository.AsQueryable().OrderBy(x => x.Sort) .OrderBy(x => x.Id) .WithCache() .ToTreeAsync(x => x.Children, x => x.ParentId, null); return tree.Adapt>(); } /// /// 添加文章栏目 /// /// /// [DisplayName("添加文章栏目")] [HttpPost("add")] public async Task Add(AddCategoryInput dto) { var entity = dto.Adapt(); await _repository.InsertAsync(entity); } /// /// 更新文章栏目 /// /// [DisplayName("更新文章栏目")] [HttpPut("edit")] public async Task Update(UpdateCategoryInput dto) { var entity = await _repository.GetByIdAsync(dto.Id); if (entity == null) throw Oops.Bah("无效参数"); dto.Adapt(entity); await _repository.UpdateAsync(entity); } /// /// 获取文章栏目下拉选项 /// /// [DisplayName("获取文章栏目下拉选项")] [HttpGet] public async Task> TreeSelect() { var list = await _repository.AsQueryable().WithCache().ToTreeAsync(x => x.Children, x => x.ParentId, null); return list.Adapt>(); } }