package com.tofly.base.controller;

import com.tofly.base.dto.ShorcutMenuDto;
import com.tofly.base.entity.UserShortMenu;
import com.tofly.base.service.ShortcutMenuService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.oauth.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shortcutmenu")
@Api(tags = "快捷菜单")
public class ShortcutMenuController {

    @Autowired
    private ShortcutMenuService shortcutMenuService;

    @GetMapping("/list")
    @ApiOperation("当前用户快捷菜单列表")
    public ResultRespone<List<UserShortMenu>> menuList() {
        Long userId = SecurityUtils.getUserId();
        return ResultRespone.success(shortcutMenuService.menuList(userId));
    }

    @PostMapping("/save")
    @ApiOperation("添加快捷菜单")
    public ResultRespone<Void> saveMenu(@RequestBody ShorcutMenuDto shorcutMenuDto) {
        shortcutMenuService.saveMenu(shorcutMenuDto);
        return ResultRespone.success();
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("根据ID删除快捷菜单")
    public ResultRespone<Void> deleteMenu(@PathVariable("id") Long id) {
        shortcutMenuService.removeById(id);
        return ResultRespone.success();
    }

}
