feat: 添加oss api
This commit is contained in:
@@ -9,6 +9,7 @@ type ApiGroup struct {
|
||||
RoleApi
|
||||
MenuApi
|
||||
OperationRecordApi
|
||||
OssApi
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -18,4 +19,5 @@ var (
|
||||
roleService = service.ServiceGroupApp.SystemServiceGroup.RoleService
|
||||
menuService = service.ServiceGroupApp.SystemServiceGroup.MenuService
|
||||
operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService
|
||||
ossService = service.ServiceGroupApp.SystemServiceGroup.OssService
|
||||
)
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
sysReq "sundynix-go/model/system/request"
|
||||
sysResp "sundynix-go/model/system/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OssApi struct {
|
||||
}
|
||||
|
||||
// UploadFile
|
||||
// @tags 文件相关
|
||||
// @Summary 文件上传
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "上传文件"
|
||||
// @Success 200 {object} response.Response{msg=string} "上传文件"
|
||||
// @router /api/oss/upload [post]
|
||||
func (o *OssApi) UploadFile(c *gin.Context) {
|
||||
var file system.Oss
|
||||
_, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
global.Logger.Error("接收文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("接收文件失败!", c)
|
||||
return
|
||||
}
|
||||
file, err = ossService.Upload(header) //上传完成后拿到文件信息
|
||||
if err != nil {
|
||||
global.Logger.Error("上传文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("上传文件失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(sysResp.UploadFileResponse{File: file}, c)
|
||||
}
|
||||
|
||||
// DeleteFile
|
||||
// @tags 文件相关
|
||||
// @Summary 删除文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除文件"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除文件"
|
||||
// @router /api/oss/delete [post]
|
||||
func (o *OssApi) DeleteFile(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = ossService.DeleteFileByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("删除文件失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除文件成功!", c)
|
||||
}
|
||||
|
||||
// GetFileList
|
||||
// @tags 文件相关
|
||||
// @Summary 文件列表
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body sysReq.GetOssFileList true "文件列表"
|
||||
// @Success 200 {object} response.Response{data=string} "文件列表"
|
||||
// @router /api/oss/getFileList [post]
|
||||
func (o *OssApi) GetFileList(c *gin.Context) {
|
||||
var pageInfo sysReq.GetOssFileList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := ossService.GetFileList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取文件列表失败!", zap.Error(err))
|
||||
response.FailWithMsg("获取文件列表失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @tags 文件相关
|
||||
// @Summary 文件详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "文件id"
|
||||
// @Success 200 {object} response.Response{data=string} "文件详情"
|
||||
// @router /api/oss/detail [get]
|
||||
func (o *OssApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
file, err := ossService.GetById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取文件详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(file, c)
|
||||
}
|
||||
Reference in New Issue
Block a user