package com.yuchen.saas.park.service.controller.community;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.entity.park.CommunityInfo;
import com.yuchen.saas.park.service.service.CommunityInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "社区管理")
@RestController
@RequestMapping("/communityInfo")
public class CommunityInfoController {
    @Autowired
    private CommunityInfoService communityInfoService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "社区新增")
    public R save(@Valid @RequestBody CommunityInfo communityInfo) {
        return R.status(communityInfoService.save(communityInfo));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "社区列表")
    public R<List<CommunityInfo>> list() {
        return R.data(communityInfoService.getAll());
    }
    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "社区修改")
    public R update(@Valid @RequestBody CommunityInfo communityInfo) {
        return R.status(communityInfoService.save(communityInfo));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "社区删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(communityInfoService.removeById(param.getId()));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "详情", notes = "社区详情")
    public R<CommunityInfo> detail(@RequestParam("id") Long id) {
        return R.data(communityInfoService.getById(id));
    }




}
