Search in sources :

Example 6 with TopicActionDO

use of org.neusoft.neubbs.entity.TopicActionDO in project neubbs by nuitcoder.

the class TopicActionDAOTest method saveTestTopicActionDOToDatabase.

/**
 * 保存测试 TopicActionDO 对象至数据库
 *      - 新建测试话题
 *      - 保存,且重新查询数据库获得对象(根据话题 id,进行查询)
 *
 * @return TopicActionDO 话题行为对象
 */
private TopicActionDO saveTestTopicActionDOToDatabase() {
    TopicDO topic = new TopicDO();
    topic.setUserid(1);
    topic.setCategoryid(1);
    topic.setTitle("test title");
    Assert.assertEquals(1, topicDAO.saveTopic(topic));
    TopicActionDO topicAction = new TopicActionDO();
    topicAction.setTopicId(topic.getId());
    Assert.assertEquals(1, topicActionDAO.saveTopicAction(topicAction));
    return topicActionDAO.getTopicAction(topic.getId());
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) TopicActionDO(org.neusoft.neubbs.entity.TopicActionDO)

Example 7 with TopicActionDO

use of org.neusoft.neubbs.entity.TopicActionDO 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)

Aggregations

TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)7 Transactional (javax.transaction.Transactional)5 Test (org.junit.Test)5 TopicDO (org.neusoft.neubbs.entity.TopicDO)2 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)1 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)1 ServiceException (org.neusoft.neubbs.exception.ServiceException)1