黑马头条 作业+解答 day03-自媒体文章发布 自媒体接口

感觉是非常适合新手的练手接口;花了不到半小时吧,主要是因为接口描述很清晰!

建议大家仔细自己做了一遍再对照,有更好的写法欢迎留言!

1)素材管理

1.1)图片删除

接口描述

说明

接口路径

/api/v1/material/del_picture/{id}

请求方式

GET

参数

Integer id

响应结果

ResponseResult

返回结果实例:

测试成功!


@ApiOperation("图片删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer   id){
        if(id==null)
            return ResponseResult.errorResult(PARAM_REQUIRE);
        WmMaterial wmMaterial = wmMaterialService.getById(id);
        if(wmMaterial==null){
            return ResponseResult.errorResult(DATA_NOT_EXIST);
        }
        boolean b = wmMaterialService.removeById(id);
        if(b){
            return ResponseResult.okResult(wmMaterial);
        }else{
            return ResponseResult.errorResult(501,"文件删除失败");
        }
    }

1.2)收藏与取消

接口描述

取消收藏

说明

接口路径

/api/v1/material/cancel_collect/{id}

请求方式

GET

参数

Integer id

响应结果

ResponseResult

收藏

说明

接口路径

/api/v1/material/collect/{id}

请求方式

GET

参数

Integer id

响应结果

ResponseResult

返回结果实例:


@ApiOperation("收藏文章")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        if(id==null)
            return ResponseResult.errorResult(0,"传输的收藏id为空");
        WmMaterial wmMaterial = wmMaterialService.getById(id);
//        System.out.println(wmMaterial);
        wmMaterial.setIsCollection((short) 1);
        wmMaterialService.updateById(wmMaterial);

        return ResponseResult.okResult(SUCCESS);
    }

    @ApiOperation("取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id){
        if(id==null)
            return ResponseResult.errorResult(PARAM_REQUIRE);
        WmMaterial wmMaterial = wmMaterialService.getById(id);
//        System.out.println(wmMaterial);
        wmMaterial.setIsCollection((short) 0);
        wmMaterialService.updateById(wmMaterial);

        return ResponseResult.okResult(SUCCESS);
    }

2)文章管理

2.1)查看详情

接口描述

说明

接口路径

/api/v1/news/one/{id}

请求方式

GET

参数

文章id

响应结果

ResponseResult

返回结果实例:

这个位置是不是应该要有加这个结果的构造函数啊;


public static ResponseResult okResult(int code, String msg,Object data) {
        ResponseResult result = new ResponseResult();
        return result.ok(code, data, msg);
    }

测试的时候就是编辑功能,测试成功


@ApiOperation("news文章查看详情")
    @GetMapping("/one/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        if(id==null)
            return ResponseResult.errorResult(DATA_NOT_EXIST);
        WmNews wmNews = wmNewsService.getById(id);

        return ResponseResult.okResult(200,"操作成功",wmNews);
    }

2.2)文章删除

接口描述

说明

接口路径

/api/v1/news/del_news/{id}

请求方式

GET

参数

文章id

响应结果

ResponseResult

返回结果实例


@ApiOperation("news文章删除")
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id){
        if(id==null)
            return ResponseResult.errorResult(501,"文章Id不可缺少");
        WmNews wmNews = wmNewsService.getById(id);

        if(wmNews==null){
            return ResponseResult.errorResult(1002,"文章不存在");
        }
        if(wmNews.getStatus()==9){
            return ResponseResult.errorResult(501,"文章已发布,不能删除");
        }
        wmNewsService.removeById(id);
        return ResponseResult.okResult(SUCCESS);
    }

2.3)文章上下架

接口描述

说明

接口路径

/api/v1/news/down_or_up

请求方式

POST

参数

WmNewsDto

响应结果

ResponseResult

WmNewsDto

返回结果实例


@ApiOperation("news文章上下架")
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        //1.检查参数
        Integer id=dto.getId();
        if(dto == null||id==null){
            return ResponseResult.errorResult(501,"文章Id不可缺少");
        }
        WmNews wmNews =new WmNews();
        BeanUtils.copyProperties(dto,wmNews);
        wmNews = wmNewsService.getById(id);
        System.out.println("----------"+wmNews);

        if(wmNews==null){
            return ResponseResult.errorResult(1002,"文章不存在");
        }
        if(wmNews.getStatus()!=9){// 状态 9为发布
            return ResponseResult.errorResult(501,"当前文章不是发布状态,不能上下架");
        }
        if(wmNews.getEnable()==0){// 0 下架  1 上架
            wmNews.setEnable((short) 1);
        }else if(wmNews.getEnable()==1){
            wmNews.setEnable((short) 0);
        }
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult(SUCCESS);
    }

测试成功!

创作不易! 你的支持和三连是我创作的最大动力!

  • 11
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软工菜鸡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值