package com.vctgo.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vctgo.file.domain.FileShare;
import com.vctgo.file.service.IFileShareService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 分享信息Controller
 *
 * @author caesar
 * @date 2023-08-04
 */
@Api(tags = "云盘分享业务")
@RestController
@RequestMapping("/share")
public class FileShareController extends BaseController {
    @Autowired
    private IFileShareService fileShareService;

    /**
     * 查询分享信息列表
     */
    @RequiresPermissions("toy:share:list")
    @GetMapping("/list")
    public AjaxResult list(FileShare fileShare) {
        IPage<FileShare> list = fileShareService.selectFileSharePage(fileShare);
        return AjaxResult.success(list);
    }

    /**
     * 导出分享信息列表
     */
    @RequiresPermissions("toy:share:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileShare fileShare) {
        List<FileShare> list = fileShareService.selectFileShareList(fileShare);
        ExcelUtil<FileShare> util = new ExcelUtil<FileShare>(FileShare.class);
        util.exportExcel(response, list, "分享信息数据");
    }

    /**
     * 获取分享信息详细信息
     */
    @RequiresPermissions("toy:share:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success((fileShareService.selectFileShareById(id)));
    }

    /**
     * 新增分享信息
     */
    @RequiresPermissions("toy:share:add")
    @PostMapping
    public AjaxResult add(@RequestBody FileShare fileShare) {
        return toAjax(fileShareService.insertFileShare(fileShare));
    }

    /**
     * 修改分享信息
     */
    @RequiresPermissions("toy:share:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody FileShare fileShare) {
        return toAjax(fileShareService.updateFileShare(fileShare));
    }

    /**
     * 删除分享信息
     */
    @RequiresPermissions("toy:share:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fileShareService.deleteFileShareByIds(ids));
    }
}
