package com.huimv.lamp.controller;


import com.huimv.lamp.service.LampService;
import com.huimv.lamp.utils.Result;
import com.huimv.lamp.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zn
 * @since 2022-08-02
 */
@CrossOrigin
@RestController
@RequestMapping("/lamp")
public class LampController {
    @Autowired
    private LampService lampService;

    @PostMapping("/getLightness")
    public Result getLightness(){
        Integer lightness = lampService.getLighteness();
        return new Result(ResultCode.SUCCESS,lightness);
    }

    @PostMapping("/updateLightness")
    public Result updateLightness(@RequestBody Map<String, Object> params){
        Integer lightness = 0;
        if(params.get("lightness") != null){
            lightness = Integer.parseInt(params.get("lightness")+"");
        }
        //
        lampService.updateLightness(lightness);
        return new Result(ResultCode.SUCCESS);
    }
}

