using YD_Event.Application.Auth;
using YD_Event.Application.Client.Dtos;
namespace YD_Event.Application.Client;
///
/// 博客说说
///
[ApiDescriptionSettings("博客前端接口")]
[AllowAnonymous]
public class TalksController : IDynamicApiController
{
private readonly ISqlSugarRepository _talksRepository;
private readonly AuthManager _authManager;
public TalksController(ISqlSugarRepository talksRepository,
AuthManager authManager)
{
_talksRepository = talksRepository;
_authManager = authManager;
}
///
/// 说说列表
///
///
///
[HttpGet]
public async Task> Get([FromQuery] Pagination dto)
{
long userId = _authManager.UserId;
return await _talksRepository.AsQueryable().Where(x => x.Status == AvailabilityStatus.Enable)
.OrderByDescending(x => x.IsTop)
.OrderByDescending(x => x.Id)
.Select(x => new TalksOutput
{
Id = x.Id,
IsTop = x.IsTop,
Content = x.Content,
Images = x.Images,
Upvote = SqlFunc.Subqueryable().Where(p => p.ObjectId == x.Id).Count(),
Comments = SqlFunc.Subqueryable().Where(c => c.ModuleId == x.Id && c.RootId == null).Count(),
IsPraise = SqlFunc.Subqueryable().Where(p => p.ObjectId == x.Id && p.AccountId == userId).Any(),
CreatedTime = x.CreatedTime
}).ToPagedListAsync(dto);
}
///
/// 说说详情
///
///
///
[HttpGet]
public async Task TalkDetail([FromQuery] long id)
{
long userId = _authManager.UserId;
return await _talksRepository.AsQueryable()
.Where(x => x.Id == id)
.Select(x => new TalkDetailOutput
{
Id = x.Id,
Content = x.Content,
Images = x.Images,
IsTop = x.IsTop,
IsAllowComments = x.IsAllowComments,
IsPraise = SqlFunc.Subqueryable().Where(p => p.ObjectId == x.Id && p.AccountId == userId).Any(),
Comments = SqlFunc.Subqueryable().Where(c => c.ModuleId == x.Id && c.RootId == null).Count(),
Upvote = SqlFunc.Subqueryable().Where(p => p.ObjectId == x.Id).Count(),
CreatedTime = x.CreatedTime
}).FirstAsync();
}
}