package com.goomood.tableConfig.controller;


import com.goomood.common.core.domain.AjaxResult;
import com.goomood.tableConfig.domain.UserTableConfig;
import com.goomood.tableConfig.service.IUserTableConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.goomood.common.core.domain.AjaxResult.success;

/**
 * 前端控制器
 *
 * @author zuoyou
 * @since 2025-03-03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tableConfig/userTableConfig")
public class UserTableConfigController {

    private final IUserTableConfigService configService;

    /**
     * 获取用户配置
     *
     * @return
     */
    @PostMapping("getUserTableConfig")
    public AjaxResult getUserTableConfig(@RequestBody UserTableConfig config) {
        UserTableConfig userTableConfig = configService.getUserTableConfig(config);
        return  success(userTableConfig);
    }

    /**
     * 修改用户配置
     *
     * @param config
     * @return
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody UserTableConfig config) {
        configService.saveUserTableConfig(config);
        return success();
    }

    /**
     * 初始化用户配置
     *
     * @param config
     * @return
     */
    @PostMapping("initUserTableConfig")
    public AjaxResult initUserTableConfig(@RequestBody UserTableConfig config) {
        configService.initUserTableConfig(config);
        return success();
    }
}
