103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
using LiveForum.Code.Base;
|
|
using LiveForum.Code.JwtInfrastructure;
|
|
using LiveForum.IService.Cdk;
|
|
using LiveForum.IService.Permission;
|
|
using LiveForum.IService.Posts;
|
|
using LiveForum.Model.Dto.PostComments;
|
|
using LiveForum.Model.Enum;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LiveForum.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 帖子评论相关接口
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class PostCommentsController : ControllerBase
|
|
{
|
|
private readonly IPostCommentsService _postComments;
|
|
private readonly ICdkService _cdkService;
|
|
private readonly IPermissionService _permissionService;
|
|
private readonly JwtUserInfoModel _userInfoModel;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public PostCommentsController(IPostCommentsService postComments, ICdkService cdkService, IPermissionService permissionService, JwtUserInfoModel userInfoModel)
|
|
{
|
|
_postComments = postComments;
|
|
_cdkService = cdkService;
|
|
_permissionService = permissionService;
|
|
_userInfoModel = userInfoModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取评论列表
|
|
/// </summary>
|
|
/// <param name="request">请求参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public Task<BaseResponse<GetPostCommentsRespDto>> GetPostComments([FromQuery] GetPostCommentsReq request) => _postComments.GetPostComments(request);
|
|
|
|
/// <summary>
|
|
/// 获取评论回复列表
|
|
/// </summary>
|
|
/// <param name="request">请求参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public Task<BaseResponse<GetCommentsRepliesRespDto>> GetCommentsReplies([FromQuery] GetCommentsRepliesReq request) => _postComments.GetCommentsReplies(request);
|
|
|
|
/// <summary>
|
|
/// 发表评论
|
|
/// </summary>
|
|
/// <param name="request">请求参数</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<BaseResponse<PublishPostCommentsRespDto>> PublishPostComments([FromBody] PublishPostCommentsReq request)
|
|
{
|
|
var userId = _userInfoModel.UserId;
|
|
|
|
// 权限校验:回贴权限
|
|
await _permissionService.CheckPermissionAsync(userId, PermissionType.Reply);
|
|
|
|
// CDK激活检查
|
|
if (await _cdkService.RequiresCdkActivationAsync(userId))
|
|
{
|
|
return new BaseResponse<PublishPostCommentsRespDto>(ResponseCode.CdkNotActivated, "需要激活 CDK");
|
|
}
|
|
return await _postComments.PublishPostComments(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除评论
|
|
/// </summary>
|
|
/// <param name="request">请求参数</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public Task<BaseResponseBool> DeletePostComments([FromBody] DeletePostCommentsReq request) => _postComments.DeletePostComments(request);
|
|
|
|
/// <summary>
|
|
/// 点赞/取消点赞评论
|
|
/// </summary>
|
|
/// <param name="request">请求参数</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<BaseResponse<LikeCommentRespDto>> LikeComment([FromBody] LikeCommentReq request)
|
|
{
|
|
var userId = _userInfoModel.UserId;
|
|
|
|
// 权限校验:点赞权限
|
|
await _permissionService.CheckPermissionAsync(userId, PermissionType.Like);
|
|
|
|
return await _postComments.LikeComment(request);
|
|
}
|
|
}
|
|
}
|