package com.xydl.cac.controller;

import com.xydl.cac.entity.ModevTypePoint;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.ModevTypePointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Api(tags = {"监测设备类型属性点相关接口"})
@RequestMapping("modevtypepoint")
@Slf4j
public class ModevTypePointController extends BasicController {

    @Resource
    ModevTypePointService service;

    @GetMapping("listAll")
    @ApiOperation("查询列表")
    public Response<List<ModevTypePoint>> listAll(Integer modevtypeId) {
        List<ModevTypePoint> result = service.listAll(modevtypeId);
        return Response.success(result);
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public Response<ModevTypePoint> add(@Validated @RequestBody ModevTypePoint item) throws Exception {
        ModevTypePoint result = service.add(item);
        return Response.success(result);
    }

    @PostMapping("delete")
    @ApiOperation("删除")
    public Response<String> delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
        if (id == null) {
            throw new BusinessException("id不能为空!");
        }
        service.delete(id);
        return Response.success("OK");
    }

}
