package com.chuanxia.mcp.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chuanxia.mcp.aop.Login;
import com.chuanxia.mcp.bean.dto.DomainOperatorBindDto;
import com.chuanxia.mcp.bean.dto.OperatorQueryDto;
import com.chuanxia.mcp.bean.model.CdnOperator;
import com.chuanxia.mcp.bean.vo.CdnOperatorVo;
import com.chuanxia.mcp.bean.vo.Result;
import com.chuanxia.mcp.service.CdnOperatorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liyuntian
 */
@RestController
@Api("cdn运营商管理")
@RequestMapping("cdnOperator")
@RequiredArgsConstructor
public class CdnOperatorController {
    private final CdnOperatorService operatorService;

    @GetMapping("getList")
    @ApiOperation("获取所有运营商列表(不分页)")
    @Login
    public Result<List<CdnOperator>> getList() {
        return Result.success(operatorService.list());
    }

    @PostMapping("bindCdn")
    @ApiOperation("域名绑定运营商")
    @Login
    public Result<String> bindCdn(@RequestBody DomainOperatorBindDto bindDto) {
        return operatorService.bindCdn(bindDto);
    }

    @PostMapping("listPage")
    @ApiOperation("运营商分页列表")
    @Login
    public Result<IPage<CdnOperatorVo>> listPage(@RequestBody OperatorQueryDto queryDto) {
        return operatorService.listPage(queryDto);
    }

    @GetMapping("removeBind")
    @ApiOperation("删除某一条绑定运营商记录")
    @Login
    public Result<String> removeBind(@RequestParam("id") Integer id) {
        return operatorService.removeBind(id);
    }

}
