mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
expose some functions of file package, add more MIME types to file download function to cover result file formats
This commit is contained in:
parent
77d02ec7a7
commit
6689c858d6
3 changed files with 19 additions and 10 deletions
|
@ -104,7 +104,7 @@ func addFile(c *gin.Context) {
|
|||
}
|
||||
|
||||
var newFile File
|
||||
err = newFile.register(file_header, so.ID)
|
||||
err = newFile.Register(file_header, so.ID)
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"file": newFile.File})
|
||||
}
|
||||
|
@ -116,6 +116,15 @@ func addFile(c *gin.Context) {
|
|||
// @ID getFile
|
||||
// @Tags files
|
||||
// @Produce text/plain
|
||||
// @Produce text/csv
|
||||
// @Produce application/gzip
|
||||
// @Produce application/x-gtar
|
||||
// @Produce application/x-tar
|
||||
// @Produce application/x-ustar
|
||||
// @Produce application/zip
|
||||
// @Produce application/msexcel
|
||||
// @Produce application/xml
|
||||
// @Produce application/x-bag
|
||||
// @Produce png
|
||||
// @Produce jpeg
|
||||
// @Produce gif
|
||||
|
@ -132,7 +141,7 @@ func addFile(c *gin.Context) {
|
|||
func getFile(c *gin.Context) {
|
||||
|
||||
// check access
|
||||
ok, f := checkPermissions(c, database.Read)
|
||||
ok, f := CheckPermissions(c, database.Read)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
@ -165,7 +174,7 @@ func getFile(c *gin.Context) {
|
|||
func updateFile(c *gin.Context) {
|
||||
|
||||
// check access
|
||||
ok, f := checkPermissions(c, database.Update)
|
||||
ok, f := CheckPermissions(c, database.Update)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
@ -199,12 +208,12 @@ func updateFile(c *gin.Context) {
|
|||
func deleteFile(c *gin.Context) {
|
||||
|
||||
// check access
|
||||
ok, f := checkPermissions(c, database.Delete)
|
||||
ok, f := CheckPermissions(c, database.Delete)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
err := f.delete()
|
||||
err := f.Delete()
|
||||
if !helper.DBError(c, err) {
|
||||
c.JSON(http.StatusOK, gin.H{"file": f.File})
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ type File struct {
|
|||
database.File
|
||||
}
|
||||
|
||||
func (f *File) byID(id uint) error {
|
||||
func (f *File) ByID(id uint) error {
|
||||
db := database.GetDB()
|
||||
err := db.Find(f, id).Error
|
||||
if err != nil {
|
||||
|
@ -74,7 +74,7 @@ func (f *File) download(c *gin.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *File) register(fileHeader *multipart.FileHeader, scenarioID uint) error {
|
||||
func (f *File) Register(fileHeader *multipart.FileHeader, scenarioID uint) error {
|
||||
|
||||
// Obtain properties of file
|
||||
f.Type = fileHeader.Header.Get("Content-Type")
|
||||
|
@ -179,7 +179,7 @@ func (f *File) update(fileHeader *multipart.FileHeader) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (f *File) delete() error {
|
||||
func (f *File) Delete() error {
|
||||
|
||||
db := database.GetDB()
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func checkPermissions(c *gin.Context, operation database.CRUD) (bool, File) {
|
||||
func CheckPermissions(c *gin.Context, operation database.CRUD) (bool, File) {
|
||||
|
||||
var f File
|
||||
|
||||
|
@ -44,7 +44,7 @@ func checkPermissions(c *gin.Context, operation database.CRUD) (bool, File) {
|
|||
return false, f
|
||||
}
|
||||
|
||||
err = f.byID(uint(fileID))
|
||||
err = f.ByID(uint(fileID))
|
||||
if helper.DBError(c, err) {
|
||||
return false, f
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue