-
Notifications
You must be signed in to change notification settings - Fork 14
/
file_controller.go
54 lines (42 loc) · 1.21 KB
/
file_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package controller
import (
"github.com/gin-gonic/gin"
"github.com/coretrix/hitrix/pkg/binding"
"github.com/coretrix/hitrix/pkg/dto/file"
errorhandling "github.com/coretrix/hitrix/pkg/error_handling"
fileModel "github.com/coretrix/hitrix/pkg/model/file"
"github.com/coretrix/hitrix/pkg/response"
)
type FileController struct {
}
// @Description Upload
// @Tags File
// @Accept mpfd
// @Param body formData file.RequestDTOUploadFile true "Request in formData"
// @Param file formData file true "The file"
// @Router /file/upload/ [post]
// @Security BearerAuth
// @Success 200 {object} file.File
// @Failure 400 {object} response.Error
// @Failure 401 "Unauthorized"
// @Failure 403 "Forbidden"
// @Failure 500 "Something bad happened"
func (controller *FileController) PostUploadImageAction(c *gin.Context) {
req := &file.RequestDTOUploadFile{}
err := binding.ShouldBind(c, req)
if errorhandling.HandleError(c, err) {
return
}
request, closeFile, err := req.ToUploadImage()
if errorhandling.HandleError(c, err) {
return
}
defer func() {
_ = closeFile()
}()
res, err := fileModel.CreateFile(c.Request.Context(), request)
if errorhandling.HandleError(c, err) {
return
}
response.SuccessResponse(c, res)
}