initial generic import backend code

This commit is contained in:
Alex H
2023-04-16 05:59:32 +00:00
parent 654087b990
commit 5208437ec2
4 changed files with 114 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
"net/http"
"strconv"
"hammond/models"
"hammond/service"
"github.com/gin-gonic/gin"
@@ -12,6 +13,7 @@ import (
func RegisteImportController(router *gin.RouterGroup) {
router.POST("/import/fuelly", fuellyImport)
router.POST("/import/drivvo", drivvoImport)
router.POST("/import/generic", genericImport)
}
func fuellyImport(c *gin.Context) {
@@ -52,3 +54,21 @@ func drivvoImport(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{})
}
func genericImport(c *gin.Context) {
var json models.ImportData
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if json.VehicleId == "" {
c.JSON(http.StatusUnprocessableEntity, "Missing Vehicle ID")
return
}
errors := service.GenericImport(json, c.MustGet("userId").(string))
if len(errors) > 0 {
c.JSON(http.StatusUnprocessableEntity, gin.H{"errors": errors})
return
}
c.JSON(http.StatusOK, gin.H{})
}