CsdnController.java 1.5 KB
Newer Older
1 2 3
package com.kwan.springbootkwan.controller;

import com.kwan.springbootkwan.entity.Result;
4
import com.kwan.springbootkwan.entity.resp.BusinessInfo;
5 6 7
import com.kwan.springbootkwan.service.CsdnService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
8
import org.apache.commons.lang3.StringUtils;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/csdn")
public class CsdnController {

    @Autowired
    private CsdnService service;

    @ApiOperation(value = "获取数据", notes = "获取数据")
    @GetMapping("/list")
    public Result get() {
25 26 27 28 29 30 31
        final BusinessInfo.ArticleData.Article article = service.list();
        final String type = article.getType();
        if (!StringUtils.equals("blog", type)) {
            return Result.ok("非博客不能评论");
        }
        final String urlInfo = article.getUrl();
        String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
32
        System.out.println(articleId);
33 34 35 36 37
        final Boolean articleInfo = service.getArticleInfo(articleId);
        if (!articleInfo) {
            //进行点赞和评论
            service.like(articleId);
            service.comment(articleId);
38 39 40
            return Result.ok("三连完成");
        } else {
            return Result.ok("文章已经评论过,不能再次评论");
41
        }
42 43
    }
}