add skeletons for file endpoints

This commit is contained in:
Sonja Happ 2019-05-09 12:33:47 +02:00
parent 48a28ff932
commit eea765f707
4 changed files with 110 additions and 2 deletions

View file

@ -1 +1,48 @@
package file
import (
"github.com/gin-gonic/gin"
"net/http"
)
func FilesRegister(r *gin.RouterGroup) {
r.GET("/", filesReadEp)
//r.POST("/", fileRegistrationEp) // TODO to be added to API
//r.PUT("/:fileID", fileUpdateEp) // TODO to be added to API
r.GET("/:fileID", fileReadEp)
r.DELETE("/:fileID", fileDeleteEp)
}
func filesReadEp(c *gin.Context) {
allFiles, _, _ := FindAllFiles()
serializer := FilesSerializer{c, allFiles}
c.JSON(http.StatusOK, gin.H{
"users": serializer.Response(),
})
}
// TODO to be added to API
//func fileRegistrationEp(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "message": "NOT implemented",
// })
//}
// TODO to be added to API
//func fileUpdateEp(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "message": "NOT implemented",
// })
//}
func fileReadEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func fileDeleteEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}

View file

@ -1 +1,12 @@
package file
import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
func FindAllFiles() ([]common.File, int, error) {
db := common.GetDB()
var files []common.File
err := db.Find(&files).Error
return files, len(files), err
}

View file

@ -1 +1,53 @@
package file
import (
"time"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
type FilesSerializer struct {
Ctx *gin.Context
Files []common.File
}
func (self *FilesSerializer) Response() []FileResponse {
response := []FileResponse{}
for _, File := range self.Files {
serializer := FileSerializer{self.Ctx, File}
response = append(response, serializer.Response())
}
return response
}
type FileSerializer struct {
Ctx *gin.Context
common.File
}
type FileResponse struct {
Name string `json:"Name"`
ID uint `json:"FileID"`
Path string `json:"Path"`
Type string `json:"Type"` //MIME type?
Size uint `json:"Size"`
H uint `json:"ImageHeight"`
W uint `json:"ImageWidth"`
Date time.Time `json:"Date"`
}
func (self *FileSerializer) Response() FileResponse {
response := FileResponse{
Name: self.Name,
Path: self.Path,
Type: self.Type,
Size: self.Size,
Date: self.Date,
H: self.ImageHeight,
W: self.ImageWidth,
}
return response
}

View file

@ -2,8 +2,6 @@ package user
import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
//"github.com/jinzhu/gorm"
//"github.com/jinzhu/gorm/dialects/postgres"
)
func FindAllUsers() ([]common.User, int, error) {