package com.template.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.template.annotation.DESRespondSecret;
import com.template.api.SmartVisitorRestsConfigControllerAPI;
import com.template.model.pojo.SmartVisitorRestsConfig;
import com.template.model.result.CommonResult;
import com.template.services.SmartVisitorRestsConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ceshi
 * @since 2024-05-30
 */
@RestController
@DESRespondSecret
public class SmartVisitorRestsConfigController implements SmartVisitorRestsConfigControllerAPI {

    @Autowired
    SmartVisitorRestsConfigService smartVisitorRestsConfigService;

    @Override
    @DESRespondSecret(validated = true)
    public CommonResult list() {
        List<SmartVisitorRestsConfig> list = smartVisitorRestsConfigService.list(new LambdaQueryWrapper<>());
        SmartVisitorRestsConfig smartVisitorRestsConfig = list.get(0);
        return CommonResult.ok(smartVisitorRestsConfig);
    }

    @Override
    @DESRespondSecret(validated = true)
    public CommonResult update(SmartVisitorRestsConfig smartVisitorRestsConfig) {
        boolean update = smartVisitorRestsConfigService.updateById(smartVisitorRestsConfig);
        if (update) {
            return CommonResult.ok();
        }
        return CommonResult.fail();
    }
}

