using YD_Event.Application.Auth;
using YD_Event.Application.Blog.Dtos;
namespace YD_Event.Application.Blog;
///
/// 说说管理
///
public class TalksService : BaseService
{
private readonly ISqlSugarRepository _repository;
private readonly AuthManager _authManager;
public TalksService(ISqlSugarRepository repository, AuthManager authManager) : base(repository)
{
_repository = repository;
_authManager = authManager;
}
///
/// 说说分页查询
///
///
///
[DisplayName("说说分页查询")]
[HttpGet]
public async Task> Page([FromQuery] TalksPageQueryInput dto)
{
long userId = _authManager.UserId;
return await _repository.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(dto.Keyword), x => x.Content.Contains(dto.Keyword))
.OrderByDescending(x => x.Id)
.Select(x => new TalksPageOutput
{
Id = x.Id,
Status = x.Status,
Content = x.Content,
Images = x.Images,
IsAllowComments = x.IsAllowComments,
IsTop = x.IsTop,
IsPraise = SqlFunc.Subqueryable().Where(p => p.ObjectId == x.Id && p.AccountId == userId).Any(),
CreatedTime = x.CreatedTime
}).ToPagedListAsync(dto);
}
///
/// 添加说说
///
///
///
[DisplayName("添加说说")]
[HttpPost("add")]
public async Task Add(AddTalksInput dto)
{
var talks = dto.Adapt();
await _repository.InsertAsync(talks);
}
///
/// 更新说说
///
///
///
[DisplayName("更新说说")]
[HttpPut("edit")]
public async Task Update(UpdateTalksInput dto)
{
var talks = await _repository.GetByIdAsync(dto.Id);
dto.Adapt(talks);
await _repository.UpdateAsync(talks);
}
}