package cn.reghao.oss.console.app.controller.page;

import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.account.model.po.DiskFile;
import cn.reghao.oss.console.util.DefaultSetting;
import cn.reghao.oss.console.util.db.PageSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author reghao
 * @date 2024-02-27 09:12:14
 */
@Api(tags = "存储对象页面")
@Controller
@RequestMapping("/store/object")
public class StoreObjectPageController {
    @ApiOperation(value = "文件列表页面")
    @GetMapping(value = "/list")
    public String index(@RequestParam(value = "env", required = false) String env,
                        @RequestParam(value = "type", required = false) String type,
                        @RequestParam(value = "appName", required = false) String appName, Model model) throws Exception {
        if (env == null) {
            env = DefaultSetting.getDefaultAppEnv();
        }

        if (type == null) {
            type = DefaultSetting.getDefaultAppType();
        }

        PageRequest pageRequest = PageSort.pageRequest();
        Page<DiskFile> page = Page.empty();

        model.addAttribute("env", env);
        model.addAttribute("type", type);
        model.addAttribute("page", page);
        model.addAttribute("list", page.getContent());
        return "/object/index";
    }

    @ApiOperation(value = "文件上传页面")
    @GetMapping(value = "/upload")
    public String uploadPage(Model model) {
        return "/object/upload";
    }

    @ApiOperation(value = "文件上传接口")
    @PostMapping(value = "/upload")
    @ResponseBody
    public String uploadFile(MultipartFile[] files) {
        return WebResult.success();
    }
}
