Add functions for parsing drivvo CSVs.

This commit is contained in:
Alf Sebastian Houge
2022-04-04 14:55:22 +02:00
parent 15f6539bf7
commit bfaebf17d0
5 changed files with 368 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ import (
func RegisteImportController(router *gin.RouterGroup) {
router.POST("/import/fuelly", fuellyImport)
router.POST("/import/drivvo", drivvoImport)
}
func fuellyImport(c *gin.Context) {
@@ -24,3 +25,17 @@ func fuellyImport(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{})
}
func drivvoImport(c *gin.Context) {
bytes, err := getFileBytes(c, "file")
if err != nil {
c.JSON(http.StatusUnprocessableEntity, err)
return
}
errors := service.DrivvoImport(bytes, c.MustGet("userId").(string))
if len(errors) > 0 {
c.JSON(http.StatusUnprocessableEntity, gin.H{"errors": errors})
return
}
c.JSON(http.StatusOK, gin.H{})
}