package com.hc.web.controller.browser.back;

import com.hc.business.model.ZccmAreaDistrict;
import com.hc.business.service.ZccmAreaDistrictService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * (ZccmAreaDistrict)表控制层
 *
 * @author java
 * @since 2020-11-20 16:06:50
 */

@RestController
@RequestMapping("/new/api/back/areaDistrict")
public class BackAreaDistrictController {

    /**
     * 服务对象
     */
    private final ZccmAreaDistrictService areaDistrictService;

    public BackAreaDistrictController(ZccmAreaDistrictService areaDistrictService) {
        this.areaDistrictService = areaDistrictService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 ZccmAreaDistrict", response = Result.class)
    public Result selectBackAreaDistrict(@PathVariable("id") Integer id) {
        return Result.success(areaDistrictService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmAreaDistrict", response = Result.class)
    public Result addBackAreaDistrict(@Valid @RequestBody ZccmAreaDistrict areaDistrict) {
        return Result.success(areaDistrictService.insert(areaDistrict));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmAreaDistrict", response = Result.class)
    public Result updateBackAreaDistrict(@RequestBody ZccmAreaDistrict areaDistrict) {
        return Result.success(areaDistrictService.update(areaDistrict));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 ZccmAreaDistrict列表(分页)", response = Result.class)
    public Result listBackAreaDistrict(@RequestParam(defaultValue = "0") Integer page,
                                       @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(areaDistrictService.queryAllByLimit(page, size));
    }

}