feat: file upload and remove
This commit is contained in:
+22
-1
@@ -1,8 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"crm/models"
|
||||
"crm/response"
|
||||
"crm/service"
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -21,4 +23,23 @@ func NewCommonApi() *CommonApi {
|
||||
func (c *CommonApi) InitDatabase(context *gin.Context) {
|
||||
errCode := c.commonService.InitDatabase()
|
||||
response.Result(errCode, nil, context)
|
||||
}
|
||||
}
|
||||
|
||||
// 文件上传
|
||||
func (c *CommonApi) FileUpload(context *gin.Context) {
|
||||
file, _ := context.FormFile("file")
|
||||
fileInfo, errCode := c.commonService.FileUpload(file)
|
||||
response.Result(errCode, fileInfo, context)
|
||||
}
|
||||
|
||||
// 文件移除
|
||||
func (c *CommonApi) FileRemove(context *gin.Context) {
|
||||
var param models.FileParam
|
||||
if err := context.ShouldBind(¶m); err != nil {
|
||||
response.Result(response.ErrCodeParamInvalid, nil, context)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
errCode := c.commonService.FileRemove(¶m)
|
||||
response.Result(errCode, nil, context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user