All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.guerlab.smart.article.web.controller.commons.ArticleController Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2018-2021 guerlab.net and other contributors.
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.guerlab.smart.article.web.controller.commons;

import io.swagger.v3.oas.annotations.tags.Tag;
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
 */
@Tag(name = "文章")
@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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy