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);
}
}
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));
}
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);
}
}
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());
}
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);
}
Aggregations