You've already forked FrameTour-BE
refactor(video): 重构视频审核服务异常处理
- 将 javax.servlet.http.HttpServletResponse 替换为 jakarta.servlet.http.HttpServletResponse - 使用 BaseException 替换 BizException 处理业务异常 - 修改视频查询方法 selectById 为 getEntity - 统一参数校验和用户登录状态检查的异常抛出方式
This commit is contained in:
@@ -7,11 +7,11 @@ import com.ycwl.basic.model.pc.videoreview.dto.VideoReviewRespDTO;
|
||||
import com.ycwl.basic.model.pc.videoreview.dto.VideoReviewStatisticsRespDTO;
|
||||
import com.ycwl.basic.service.VideoReviewService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.exception.BaseException;
|
||||
import com.ycwl.basic.exception.BizException;
|
||||
import com.ycwl.basic.mapper.VideoMapper;
|
||||
import com.ycwl.basic.mapper.VideoReviewMapper;
|
||||
@@ -51,22 +52,22 @@ public class VideoReviewServiceImpl implements VideoReviewService {
|
||||
public Long addReview(VideoReviewAddReqDTO reqDTO) {
|
||||
// 1. 参数校验
|
||||
if (reqDTO.getVideoId() == null) {
|
||||
throw new BizException("视频ID不能为空");
|
||||
throw new BaseException("视频ID不能为空");
|
||||
}
|
||||
if (reqDTO.getRating() == null || reqDTO.getRating() < 1 || reqDTO.getRating() > 5) {
|
||||
throw new BizException("评分必须在1-5之间");
|
||||
throw new BaseException("评分必须在1-5之间");
|
||||
}
|
||||
|
||||
// 2. 查询视频信息,获取景区ID
|
||||
VideoEntity video = videoMapper.selectById(reqDTO.getVideoId());
|
||||
VideoEntity video = videoMapper.getEntity(reqDTO.getVideoId());
|
||||
if (video == null) {
|
||||
throw new BizException("视频不存在");
|
||||
throw new BaseException("视频不存在");
|
||||
}
|
||||
|
||||
// 3. 获取当前登录用户(管理员)
|
||||
String userIdStr = BaseContextHandler.getUserId();
|
||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
||||
throw new BizException("未登录或登录已过期");
|
||||
throw new BaseException("未登录或登录已过期");
|
||||
}
|
||||
Long creator = Long.valueOf(userIdStr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user