using YD_Event.Application.User.Dtos;
namespace YD_Event.Application.User;
///
/// 博客授权用户
///
public class AuthAccountService : IDynamicApiController
{
private readonly ISqlSugarRepository _repository;
public AuthAccountService(ISqlSugarRepository repository)
{
_repository = repository;
}
///
/// 博客授权用户列表
///
///
///
[DisplayName("博客授权用户列表")]
[HttpGet]
public async Task> List([FromQuery] AuthAccountPageQueryInput dto)
{
return await _repository.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(dto.Name), x => x.Name.Contains(dto.Name))
.OrderByDescending(x => x.Id)
.Select(x => new AuthAccountPageOutput
{
Id = x.Id,
Name = x.Name,
Gender = x.Gender,
Type = x.Type,
IsBlogger = x.IsBlogger,
Avatar = x.Avatar,
CreatedTime = x.CreatedTime
}).ToPagedListAsync(dto);
}
///
/// 设置博主
///
///
///
[DisplayName("设置博主")]
[HttpPatch("SetBlogger")]
public async Task SetBlogger(KeyDto dto)
{
await _repository.UpdateAsync(x => new AuthAccount()
{
IsBlogger = !x.IsBlogger
}, x => x.Id == dto.Id);
}
///
/// 删除博客用户
///
///
///
[DisplayName("删除博客用户")]
[HttpDelete("delete")]
public async Task Delete(KeyDto dto)
{
await _repository.UpdateAsync(x => new AuthAccount()
{
DeleteMark = true
}, x => x.Id == dto.Id);
}
}