net.guerlab.smart.article.web.controller.commons.ArticleController Maven / Gradle / Ivy
package net.guerlab.smart.article.web.controller.commons;
import io.swagger.annotations.Api;
import net.guerlab.smart.article.core.enums.AuditStatus;
import net.guerlab.smart.article.core.exception.ArticleInvalidException;
import net.guerlab.smart.article.core.searchparams.ArticleCategorySearchParams;
import net.guerlab.smart.article.core.searchparams.ArticleSearchParams;
import net.guerlab.smart.article.service.entity.Article;
import net.guerlab.smart.article.service.service.ArticleService;
import net.guerlab.smart.article.web.controller.AbstractArticleController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 文章
*
* @author guer
*/
@Api(tags = "文章")
@RestController("/commons/article")
@RequestMapping("/commons/article")
public class ArticleController extends AbstractArticleController {
@Override
protected void beforeFindList(ArticleSearchParams searchParams) {
searchParams.setPublished(true);
searchParams.setAuditStatus(AuditStatus.PASS);
}
@Override
protected Article findOne0(String id) {
Article article = super.findOne0(id);
if (!article.getPublished()) {
throw new ArticleInvalidException();
}
ArticleCategorySearchParams categorySearchParams = new ArticleCategorySearchParams();
categorySearchParams.setArticleCategoryIds(article.getArticleCategoryIds());
article.setCategories(getCategoryService().selectAll(categorySearchParams));
getService().addViewNumber(article.getArticleId());
article.setViewNumber(article.getViewNumber() + 1);
return article;
}
}