package ink.wgink.module.file.controller.api.filedownload;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.file.pojo.dtos.filedownload.FileDownloadDTO;
import ink.wgink.module.file.service.filedownload.IFileDownloadService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: FileDownloadController
 * @Description: 文件下载
 * @Author: wanggeng
 * @Date: 2022/8/2 16:21
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "文件下载接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/file-download")
public class FileDownloadController extends DefaultBaseController {

    @Autowired
    private IFileDownloadService fileDownloadService;

    @ApiOperation(value = "下载分页列表", notes = "下载分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage/file-id/{fileId}")
    public SuccessResultList<List<FileDownloadDTO>> listPageByFileId(@PathVariable("fileId") String fileId, ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return fileDownloadService.listPageByFileId(fileId, page);
    }

}
