mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
add skeletons for file endpoints
This commit is contained in:
parent
48a28ff932
commit
eea765f707
4 changed files with 110 additions and 2 deletions
|
@ -1 +1,48 @@
|
||||||
package file
|
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",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,12 @@
|
||||||
package file
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,53 @@
|
||||||
package file
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
"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) {
|
func FindAllUsers() ([]common.User, int, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue