package com.ho.business.controller;

import com.ho.business.entity.HomeConfig;
import com.ho.business.entity.Station;
import com.ho.business.service.HomeConfigService;
import com.ho.business.vo.req.HomeConfigAddReqVO;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author gyan
 * @desc: TODO
 * @DateTime: 2023/11/16 14:46
 */
@RestController
@RequestMapping(ContextConstant.BUSINESS + "homeConfig")
@Api(tags = "页面元素配置")
public class HomeConfigController {

    @Autowired
    private HomeConfigService homeConfigService;

    @PostMapping("add")
    @ApiOperation(value = "新增页面元素配置接口")
    public DataResult add(@RequestBody @Valid HomeConfigAddReqVO vo) {
        DataResult<Station> result = new DataResult<>();
        homeConfigService.inserthomeConfig(vo);
        return result;
    }

    @PostMapping("/{stationId}")
    @ApiOperation(value = "根据电站id查询页面元素信息接口")
    public DataResult<List<HomeConfig>> selectByStationId(@PathVariable @Valid Integer stationId) {
        DataResult<List<HomeConfig>> result = DataResult.success();
        List<HomeConfig> HomeConfig = homeConfigService.selectByStationId(stationId);
        result.setData(HomeConfig);
        return result;
    }


}
