using YD_Event.Application.Blog.Dtos; namespace YD_Event.Application.Blog; /// /// 相册管理 /// public class AlbumsService : BaseService { private readonly ISqlSugarRepository _repository; public AlbumsService(ISqlSugarRepository repository) : base(repository) { _repository = repository; } [DisplayName("相册列表分页查询")] [HttpGet] public async Task> Page([FromQuery] AlbumsPageQueryInput dto) { return await _repository.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(dto.Name), x => x.Name.Contains(dto.Name)) .WhereIF(dto.Type.HasValue, x => x.Type == dto.Type) .OrderBy(x => x.Sort) .Select(x => new AlbumsPageOutput { Id = x.Id, Name = x.Name, Type = x.Type, Status = x.Status, IsVisible = x.IsVisible, Sort = x.Sort, Remark = x.Remark, Cover = x.Cover, CreatedTime = x.CreatedTime }).ToPagedListAsync(dto); } /// /// 新增相册 /// /// /// [DisplayName("新增相册")] [HttpPost("add")] public async Task Add(AddAlbumsInput dto) { var albums = dto.Adapt(); await _repository.InsertAsync(albums); } /// /// 更新相册 /// /// /// [DisplayName("更新相册信息")] [HttpPut("edit")] public async Task Update(UpdateAlbumsInput dto) { var albums = await _repository.GetByIdAsync(dto.Id); if (albums == null) throw Oops.Bah("无效参数"); dto.Adapt(albums); await _repository.UpdateAsync(albums); } }