using Easy.Admin.Application.Auth;
using Easy.Admin.Application.Blog.Dtos;
namespace Easy.Admin.Application.Blog;
///
/// 相册图片管理
///
public class PicturesService : IDynamicApiController
{
private readonly ISqlSugarRepository _repository;
private readonly AuthManager _authManager;
public PicturesService(ISqlSugarRepository repository,
AuthManager authManager)
{
_repository = repository;
_authManager = authManager;
}
///
/// 相册图片分页
///
///
///
[DisplayName("相册图片分页")]
[HttpGet]
[AllowAnonymous]
public async Task> Page([FromQuery] PicturesPageQueryInput dto)
{
return await _repository.AsQueryable().InnerJoin((pictures, albums) => pictures.AlbumId == albums.Id)
.Where(pictures => pictures.AlbumId == dto.Id)
.WhereIF(_authManager.AuthPlatformType is null or AuthPlatformType.Blog, (pictures, albums) => albums.IsVisible)
.Select(pictures => new PicturesPageOutput { Id = pictures.Id, Url = pictures.Url })
.ToPagedListAsync(dto);
}
///
/// 上传图片到相册
///
///
///
[DisplayName("上传图片到相册")]
[HttpPost("add")]
public async Task Add(AddPictureInput dto)
{
var list = dto.Adapt();
await _repository.InsertAsync(list);
}
///
/// 删除上册图片
///
///
///
[DisplayName("删除相册图片")]
[HttpDelete("delete")]
public async Task Delete(KeyDto dto)
{
await _repository.DeleteAsync(x => x.Id == dto.Id);
}
}