use of top.hcode.hoj.pojo.vo.DiscussionVo in project HOJ by HimitZH.
the class DiscussionController method getDiscussion.
@GetMapping("/discussion")
public CommonResult getDiscussion(@RequestParam(value = "did", required = true) Integer did, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
String uid = null;
if (userRolesVo != null) {
uid = userRolesVo.getUid();
}
DiscussionVo discussion = discussionService.getDiscussion(did, uid);
if (discussion == null) {
return CommonResult.errorResponse("对不起,该讨论不存在!", CommonResult.STATUS_NOT_FOUND);
}
if (discussion.getStatus() == 1) {
return CommonResult.errorResponse("对不起,该讨论已被封禁!", CommonResult.STATUS_FORBIDDEN);
}
// 浏览量+1
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.setSql("view_num=view_num+1").eq("id", discussion.getId());
discussionService.update(discussionUpdateWrapper);
discussion.setViewNum(discussion.getViewNum() + 1);
return CommonResult.successResponse(discussion, "获取成功");
}
use of top.hcode.hoj.pojo.vo.DiscussionVo in project HOJ by HimitZH.
the class DiscussionManager method getDiscussion.
public DiscussionVo getDiscussion(Integer did) throws StatusNotFoundException, StatusForbiddenException, AccessException {
// 获取当前登录的用户
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Discussion discussion = discussionEntityService.getById(did);
if (discussion.getGid() != null) {
accessValidator.validateAccess(HOJAccessEnum.GROUP_DISCUSSION);
if (!isRoot && !discussion.getUid().equals(userRolesVo.getUid()) && !groupValidator.isGroupMember(userRolesVo.getUid(), discussion.getGid())) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
} else {
accessValidator.validateAccess(HOJAccessEnum.PUBLIC_DISCUSSION);
}
String uid = null;
if (userRolesVo != null) {
uid = userRolesVo.getUid();
}
DiscussionVo discussionVo = discussionEntityService.getDiscussion(did, uid);
if (discussionVo == null) {
throw new StatusNotFoundException("对不起,该讨论不存在!");
}
if (discussionVo.getStatus() == 1) {
throw new StatusForbiddenException("对不起,该讨论已被封禁!");
}
// 浏览量+1
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.setSql("view_num=view_num+1").eq("id", discussionVo.getId());
discussionEntityService.update(discussionUpdateWrapper);
discussionVo.setViewNum(discussionVo.getViewNum() + 1);
return discussionVo;
}
Aggregations