package com.jiayue.ipp.idp.controller.an;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.an.ParsingUrl;
import com.jiayue.ipp.idp.service.an.ParsingUrlService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/parsingUrl")
@AllArgsConstructor
public class ParsingUrlController {

    private final ParsingUrlService parsingUrlService;


    @ApiOperation(value = "添加路径", notes = "添加路径")
    @PostMapping()
    public Boolean add(@RequestBody ParsingUrl parsingUrl) {
        return parsingUrlService.save(parsingUrl);
    }

    @ApiOperation(value = "修改路径", notes = "修改路径")
    @PutMapping()
    public Boolean update(@RequestBody ParsingUrl parsingUrl) {
        return parsingUrlService.updateById(parsingUrl);

    }


    @ApiOperation(value = "根据id删除路径", notes = "根据id删除路径")
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id) {
        return parsingUrlService.removeById(id);

    }

    @ApiOperation(value = "查询所有路径", notes = "查询所有路径")
    @GetMapping()
    public List<ParsingUrl> getAll() {
         return parsingUrlService.list();
    }

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R page(ParsingUrl parsingUrl, Page page) {

        return R.ok(parsingUrlService.page(page, Wrappers.query(parsingUrl)));
    }
}
