Search in sources :

Example 1 with DiscussionVo

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, "获取成功");
}
Also used : DiscussionVo(top.hcode.hoj.pojo.vo.DiscussionVo) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion)

Example 2 with DiscussionVo

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;
}
Also used : DiscussionVo(top.hcode.hoj.pojo.vo.DiscussionVo) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) Session(org.apache.shiro.session.Session)

Aggregations

UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)2 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)2 DiscussionVo (top.hcode.hoj.pojo.vo.DiscussionVo)2 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)2 HttpSession (javax.servlet.http.HttpSession)1 Session (org.apache.shiro.session.Session)1 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)1 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)1