Search in sources :

Example 6 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class UserServiceImpl method alterUserEmail.

@Override
public void alterUserEmail(String username, String newEmail) {
    this.getUserInfoByName(username);
    this.confirmUserNotOccupiedByEmail(newEmail);
    if (userDAO.updateUserEmailByName(username, newEmail) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.US2);
    }
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException)

Example 7 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class UserServiceImpl method alterUserProfile.

@Override
public Map<String, Object> alterUserProfile(String username, int sex, String birthday, String position, String description) {
    this.getUserInfoByName(username);
    UserDO updateUser = new UserDO();
    updateUser.setName(username);
    updateUser.setSex(sex);
    updateUser.setBirthday(birthday == null ? "" : birthday);
    updateUser.setPosition(position == null ? "" : position);
    updateUser.setDescription(description == null ? "" : description);
    // update forum_user by username, if 4 fields not null, will be updated
    if (userDAO.updateUser(updateUser) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.US2);
    }
    return this.getUserInfoModelMap(userDAO.getUserByName(username));
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) UserDO(org.neusoft.neubbs.entity.UserDO)

Example 8 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class UserServiceImpl method operateLikeTopic.

@Override
public void operateLikeTopic(int userId, int topicId, String command) {
    // input 'inc'
    int effectRow;
    if (command.equals(SetConst.COMMAND_INC)) {
        effectRow = userActionDAO.updateLikeTopicIdJsonArrayByOneTopicIdToAppendEnd(userId, topicId);
    } else {
        // input `dec`
        String likeTopicIdArrayString = userActionDAO.getUserAction(userId).getLikeTopicIdJsonArray();
        int indexTopicId = JSON.parseArray(likeTopicIdArrayString).indexOf(topicId);
        if (indexTopicId == SetConst.INDEX_NO) {
            throw new ServiceException(ApiMessage.USER_NO_LIKE_THIS_TOPIC).log(LogWarnEnum.TS21);
        }
        effectRow = userActionDAO.updateLikeTopicIdJsonArrayByIndexToRemoveOneTopicId(userId, indexTopicId);
    }
    if (effectRow == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.US3);
    }
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException)

Example 9 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class TopicServiceImpl method saveTopic.

@Override
public Map<String, Object> saveTopic(int userId, String categoryNick, String title, String topicContent) {
    // judge whether exist category(nick)
    TopicCategoryDO category = this.getTopicCategoryNotNullByNick(categoryNick);
    // build TopicDO, TopicContentDO, TopicActionDO
    TopicDO topic = new TopicDO();
    topic.setUserid(userId);
    topic.setCategoryid(category.getId());
    topic.setTitle(title);
    // insert forum_topic, get new topic id
    if (topicDAO.saveTopic(topic) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS1);
    }
    // insert forum_topic_content
    TopicContentDO topicContentDO = new TopicContentDO();
    topicContentDO.setTopicid(topic.getId());
    topicContentDO.setContent(topicContent);
    if (topicContentDAO.saveTopicContent(topicContentDO) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS2);
    }
    // insert forum_topic_action
    TopicActionDO topicAction = new TopicActionDO();
    topicAction.setTopicId(topic.getId());
    if (topicActionDAO.saveTopicAction(topicAction) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS24);
    }
    return MapFilterUtil.generateMap(ParamConst.TOPIC_ID, topic.getId());
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) TopicDO(org.neusoft.neubbs.entity.TopicDO) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) TopicActionDO(org.neusoft.neubbs.entity.TopicActionDO)

Example 10 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class TopicServiceImpl method saveCategory.

@Override
public Map<String, Object> saveCategory(String categoryNick, String categoryName) {
    if (topicCategoryDAO.getTopicCategoryByNick(categoryNick) != null) {
        throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NICK).log(LogWarnEnum.TS14);
    }
    if (topicCategoryDAO.getTopicCategoryByName(categoryName) != null) {
        throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NAME).log(LogWarnEnum.TS15);
    }
    TopicCategoryDO category = new TopicCategoryDO();
    category.setNick(categoryNick);
    category.setName(categoryName);
    topicCategoryDAO.saveTopicCategory(category);
    return this.getTopicCategoryInfoMap(category);
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO)

Aggregations

ServiceException (org.neusoft.neubbs.exception.ServiceException)16 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 UserDO (org.neusoft.neubbs.entity.UserDO)3 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)2 TopicDO (org.neusoft.neubbs.entity.TopicDO)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)1 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)1 UserActionDO (org.neusoft.neubbs.entity.UserActionDO)1