package com.hotent.portal.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotent.base.model.CommonResult;
import com.hotent.portal.persistence.manager.MenuBookmarkManager;
import com.hotent.uc.api.impl.util.ContextUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hotent.base.controller.BaseController;
import com.hotent.portal.model.MenuBookmark;

import java.util.List;

/**
 * 菜单收藏 前端控制器
 *
 * @author zengst
 * @company 广州宏天软件股份有限公司
 * @since 2021-06-21
 */
@RestController
@RequestMapping("/portal/menuBookmark/v1/")
public class MenuBookmarkController extends BaseController<MenuBookmarkManager, MenuBookmark> {

    @RequestMapping("bookmark")
    @ApiOperation(value = "菜单收藏", httpMethod = "POST", notes = "菜单收藏")
    public CommonResult<String> bookmark(@ApiParam(name = "menuBookmark", value = "菜单收藏实体") @RequestBody MenuBookmark menuBookmark) {
        String msg = baseService.handleBookmarkChange(menuBookmark.getMenuId(), ContextUtil.getCurrentUserId());
        return new CommonResult<>(true, msg);
    }

    @RequestMapping("getAll")
    @ApiOperation(value = "获取用户菜单收藏", httpMethod = "GET", notes = "获取用户菜单收藏")
    public CommonResult<List<MenuBookmark>> getAll() {
        QueryWrapper<MenuBookmark> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("USER_ID_", ContextUtil.getCurrentUserId());
        List<MenuBookmark> list = baseService.list(queryWrapper);
        return new CommonResult<>(true, "获取成功", list);
    }

    @RequestMapping(value = "removeBookmarkByMenuIds", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "通过菜单ID集合删除收藏", httpMethod = "POST", notes = "通过菜单ID集合删除收藏")
    public CommonResult<String> removeBookmarkByMenuIds(@RequestBody List<String> menuIds) {
        baseService.removeBookmarkByMenuIds(menuIds);
        return new CommonResult<>(true, "删除成功");
    }
}
