package com.bocloud.ims.booter.controller.resource.azure.db;

import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.entity.resource.azure.db.DbFirewallRule;
import com.bocloud.ims.interfaces.resource.azure.db.DbFirewallRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: DbFirewallRuleController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/2/1 15:10
 */
@Api(value = "DatabaseFirewallRule", tags = "DatabaseFirewallRule管理")
@RestController
@RequestMapping("/v1/cloud/database/server/firewall/rules")
public class DbFirewallRuleController {

    @Autowired
    private DbFirewallRuleService service;

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */

    @ApiOperation(tags = {"CMC", "CSC"}, value = "列表DatabaseFirewallRule", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "DatabaseFirewallRule", operation = "列表DatabaseFirewallRule")
    @GetMapping
    public BocloudResult list(Pager pager,
                              @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.list(pager, context);
    }


    /**
     * 创建
     *
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建DatabaseFirewallRule", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "DatabaseFirewallRule", operation = "创建DatabaseFirewallRule")
    @PostMapping
    public BocloudResult create(@RequestBody DbFirewallRule entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(entityParams, context);
    }


    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除DatabaseFirewallRule", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "DatabaseFirewallRule", operation = "删除DatabaseFirewallRule")
    @DeleteMapping("/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.remove(id, context);
    }
}