fuelly api complete
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
@@ -116,6 +117,18 @@ func getAttachmentFile(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func getFileBytes(c *gin.Context, fileVariable string) ([]byte, error) {
|
||||
if fileVariable == "" {
|
||||
fileVariable = "file"
|
||||
}
|
||||
formFile, err := c.FormFile(fileVariable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
openedFile, _ := formFile.Open()
|
||||
return ioutil.ReadAll(openedFile)
|
||||
}
|
||||
|
||||
func saveUploadedFile(c *gin.Context, fileVariable string) (*db.Attachment, error) {
|
||||
if fileVariable == "" {
|
||||
fileVariable = "file"
|
||||
|
||||
26
server/controllers/import.go
Normal file
26
server/controllers/import.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/akhilrex/hammond/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisteImportController(router *gin.RouterGroup) {
|
||||
router.POST("/import/fuelly", fuellyImport)
|
||||
}
|
||||
|
||||
func fuellyImport(c *gin.Context) {
|
||||
bytes, err := getFileBytes(c, "file")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, err)
|
||||
return
|
||||
}
|
||||
err = service.FuellyImport(bytes, c.MustGet("userId").(string))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
}
|
||||
Reference in New Issue
Block a user