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

com.leazxl.cms.web.CmsArticleWeb Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.leazxl.cms.web;

import com.leazxl.cms.model.CmsArticle;
import com.leazxl.cms.model.CmsLink;
import com.leazxl.cms.service.CmsArticleService;
import com.leazxl.core.dto.DataRet;
import com.leazxl.core.dto.PageRet;
import com.leazxl.core.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("cms")
public class CmsArticleWeb {
    @Autowired
    private CmsArticleService articleService;

    /**
     * 获取文章列表
     *
     * @param cmsArticle
     * @param pageable
     * @return
     */
    @GetMapping("article/list")
    public PageRet getArticleList(CmsArticle cmsArticle,
                                              @PageableDefault(page = 1) Pageable pageable) {
        Assert.notNull(cmsArticle.getCategoryId(), "栏目ID不能为空");
        return articleService.getArticleList(cmsArticle, pageable);
    }

    /**
     * 获取文章列表
     *
     * @param id 文章ID
     * @return
     */
    @GetMapping("article/get")
    public DataRet getArticle(String id) {
        Assert.notNull(id, "栏目ID不能为空");
        return new DataRet(articleService.getArticle(id));
    }

    /**
     * 获取文章列表
     *
     * @param cmsArticle
     * @return
     */
    @PostMapping("article/save")
    public DataRet save(@RequestBody CmsArticle cmsArticle) {
        Assert.notNull(cmsArticle.getCategoryId(), "栏目ID不能为空");
        articleService.saveArcticle(cmsArticle, cmsArticle.getArticleData());
        return new DataRet<>("保存成功");
    }

    /**
     * 删除链接信息
     *
     * @param id
     * @return
     */
    @PostMapping("article/delete")
    public DataRet articleDelete(String id) {
        Assert.notNull(id, "ID不能为空");
        articleService.deleteArticle(id);
        return new DataRet<>("删除成功");
    }
    /*****************************************链接模式************************************************/
    /**
     * 获取链接列表
     *
     * @param cmsLink
     * @param pageable
     * @return
     */
    @GetMapping("link/list")
    public PageRet getLinkList(CmsLink cmsLink,
                                        @PageableDefault(page = 1) Pageable pageable) {
        Assert.notNull(cmsLink.getCategoryId(), "栏目ID不能为空");
        return articleService.getLinkList(cmsLink, pageable);
    }

    /**
     * 获取链接
     *
     * @param id 文章ID
     * @return
     */
    @GetMapping("link/get")
    public DataRet getLink(String id) {
        Assert.notNull(id, "栏目ID不能为空");
        return new DataRet(articleService.getLink(id));
    }

    /**
     * 保存链接信息
     *
     * @param cmsLink
     * @return
     */
    @PostMapping("link/save")
    public DataRet linkSave(@RequestBody CmsLink cmsLink) {
        Assert.notNull(cmsLink.getCategoryId(), "ID不能为空");
        articleService.saveLink(cmsLink);
        return new DataRet<>("删除成功");
    }

    /**
     * 删除链接信息
     *
     * @param id
     * @return
     */
    @PostMapping("link/delete")
    public DataRet linkDelete(String id) {
        Assert.notNull(id, "栏目ID不能为空");
        articleService.delteLink(id);
        return new DataRet<>("保存成功");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy