NewsDetailController.java 2.4 KB
Newer Older
门心叼龙's avatar
门心叼龙 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
package com.fly.news.web;

import com.fly.common.annotation.SysLogger;
import com.fly.common.dto.RespDTO;
import com.fly.news.entity.NewsDetail;
import com.fly.news.service.NewsDetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: <><br>
 * Author:    门心叼龙<br>
 * Date:      2019/2/19<br>
 * Version:    V1.0.0<br>
 * Update:     <br>
 */
@RestController
@RequestMapping("/newsdetail")
public class NewsDetailController {

    @Autowired
    NewsDetailService newsDetailService;

    @ApiOperation(value = "添加新闻详情", notes = "添加新闻详情")
    @PreAuthorize("hasRole('USER')")
    @PostMapping("/save")
    @SysLogger("addNewsDetail")
    public RespDTO saveNewsDetail(@RequestBody NewsDetail newsDetail){
        NewsDetail newsDetail1 = newsDetailService.saveNewsDetail(newsDetail);
        return RespDTO.onSuc(newsDetail1);
    }

门心叼龙's avatar
门心叼龙 已提交
37
    @ApiOperation(value = "获取指定类型的新闻列表", notes = "获取指定类型的新闻列表")
门心叼龙's avatar
门心叼龙 已提交
38 39 40 41 42 43 44 45
    @PreAuthorize("hasAuthority('ROLE_USER')")
    @PostMapping("/query/all")
    @SysLogger("getListNewsDetail")
    public RespDTO getListNewsDetail(int typid){
        List<NewsDetail> newsDetails = newsDetailService.findListByTypeid(typid);
        return RespDTO.onSuc(newsDetails);
    }

门心叼龙's avatar
门心叼龙 已提交
46 47 48 49 50 51 52 53
    @ApiOperation(value = "根据id查询新闻详情", notes = "根据id查询新闻详情")
    @PreAuthorize("hasAuthority('ROLE_USER')")
    @GetMapping("/{id}/detail")
    @SysLogger("queryNewsDetail")
    public RespDTO getNewsDetail(@PathVariable Long id){
        return RespDTO.onSuc(newsDetailService.findNewsDetailById(id));
    }

门心叼龙's avatar
门心叼龙 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    @ApiOperation(value = "根据id删除新闻详情", notes = "根据id删除新闻详情")
    @PreAuthorize("hasAuthority('ROLE_USER')")
    @GetMapping("/{id}/delete")
    @SysLogger("deleteNewsDetail")
    public RespDTO deleteNewsDetail(@PathVariable Long id){
        RespDTO respDTO = new RespDTO();
        try {
            newsDetailService.deleteNewsDetail(id);
            respDTO.setError("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            respDTO.setCode(1);
            respDTO.setError("删除失败");
        }
        return respDTO;
    }
}