Search in sources :

Example 16 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method likeTopic.

/**
 * 点赞话题
 *      - 需要 command 命令(inc - 点赞 | dec - 取消)
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/like", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO likeTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
    String command = (String) requestBodyParamsMap.get(ParamConst.COMMAND);
    validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
    validationService.checkCommand(command, SetConst.COMMAND_INC, SetConst.COMMAND_DEC);
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    // judge current user like topic, according the command('inc', 'dec'), alter like of topic
    boolean isCurrentUserLikeTopic = userService.isUserLikeTopic(cookieUser.getId(), topicId);
    // record user like topic id array of user action
    userService.operateLikeTopic(cookieUser.getId(), topicId, command);
    int latestTopicLike = topicService.alterTopicLikeByCommand(isCurrentUserLikeTopic, topicId, cookieUser.getId(), command);
    return new ApiJsonDTO().success().buildMap(ParamConst.LIKE, latestTopicLike);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method getTopicInfo.

/**
 * 获取话题信息
 *      - 能够获取当前用户是否点赞该文章信息(访客用户默认为 false)
 *      - hadread 参数决定是否增加阅读数(0 - 不增加, 1 - 增加)
 *
 * @param topicId 话题 id
 * @param hadRead 阅读数是否增加(0 - 不增加,1 - 增加)
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@RequestMapping(value = "/topic", method = RequestMethod.GET)
public ApiJsonDTO getTopicInfo(@RequestParam(value = "topicid", required = false) String topicId, @RequestParam(value = "hadread", required = false) String hadRead) {
    validationService.check(ParamConst.ID, topicId);
    // judge whether to increase read count
    boolean isAddTopicRead = false;
    if (hadRead != null) {
        validationService.checkCommand(hadRead, "0", "1");
        isAddTopicRead = SetConst.COMMAND_ONE.equals(hadRead);
    }
    int topicIdInt = Integer.parseInt(topicId);
    Map<String, Object> topicContentPageModelMap = topicService.getTopicContentModelMap(topicIdInt);
    // judge current user is like this topic (visit user default value of 'false')
    boolean isLikeTopicForCurrentUser = false;
    if (httpService.isUserLoginState()) {
        UserDO currentUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
        isLikeTopicForCurrentUser = userService.isUserLikeTopic(currentUser.getId(), topicIdInt);
    }
    topicContentPageModelMap.put(ParamConst.IS_LIKE_TOPIC, isLikeTopicForCurrentUser);
    // read + 1 (default no add)
    if (isAddTopicRead) {
        topicService.increaseTopicRead(topicIdInt);
        topicContentPageModelMap.put(ParamConst.READ, (int) topicContentPageModelMap.get(ParamConst.READ) + 1);
    }
    return new ApiJsonDTO().success().model(topicContentPageModelMap);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method releaseTopicReply.

/**
 * 发布回复
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/reply", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO releaseTopicReply(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
    String replyContent = (String) requestBodyParamsMap.get(ParamConst.CONTENT);
    validationService.check(ParamConst.ID, String.valueOf(topicId)).check(ParamConst.REPLY_CONTENT, replyContent);
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    return new ApiJsonDTO().success().model(topicService.saveReply(cookieUser.getId(), topicId, replyContent));
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class TopicController method newLikeTopic.

/**
 * 点赞话题(新接口)
 *      - 自动处理用户喜欢话题状态,取反(已喜欢 -> 未喜欢, 未喜欢 -> 已喜欢)
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/newlike", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO newLikeTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
    validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    Map<String, Object> resultMap = new LinkedHashMap<>(SetConst.SIZE_TWO);
    resultMap.put(ParamConst.USER_LIKE_TOPIC_ID, topicService.operateLikeTopic(cookieUser.getId(), topicId));
    resultMap.put(ParamConst.LIKE, topicService.countTopicContentLike(topicId));
    return new ApiJsonDTO().success().model(resultMap);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) LinkedHashMap(java.util.LinkedHashMap) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with ApiJsonDTO

use of org.neusoft.neubbs.dto.ApiJsonDTO in project neubbs by nuitcoder.

the class AccountController method validateActivateToken.

/**
 * 激活 token 验证
 *      - 验证 token
 *      - 数据库激活用户
 *      - 修改客户端 cookie (重新保存用户信息)
 *
 * @param token 传入的 token
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@RequestMapping(value = "/validate", method = RequestMethod.GET)
public ApiJsonDTO validateActivateToken(@RequestParam(value = "token", required = false) String token) {
    validationService.check(ParamConst.TOKEN, token);
    UserDO activatedUser = userService.alterUserActivateStateByEmailToken(token);
    httpService.saveAuthenticationCookie(secretService.generateUserInfoAuthentication(activatedUser));
    return new ApiJsonDTO().success();
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiJsonDTO (org.neusoft.neubbs.dto.ApiJsonDTO)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 LoginAuthorization (org.neusoft.neubbs.controller.annotation.LoginAuthorization)16 UserDO (org.neusoft.neubbs.entity.UserDO)15 AccountActivation (org.neusoft.neubbs.controller.annotation.AccountActivation)14 LinkedHashMap (java.util.LinkedHashMap)3 AdminRank (org.neusoft.neubbs.controller.annotation.AdminRank)2 HashMap (java.util.HashMap)1