Files
hammond/server/controllers/reports.go
Alf Sebastian Houge 9da21b2192 Change go module name
2023-02-16 22:35:03 +01:00

39 lines
928 B
Go

package controllers
import (
"net/http"
"hammond/common"
"hammond/models"
"hammond/service"
"github.com/gin-gonic/gin"
)
func RegisterReportsController(router *gin.RouterGroup) {
router.GET("/vehicles/:id/mileage", getMileageForVehicle)
}
func getMileageForVehicle(c *gin.Context) {
var searchByIdQuery models.SearchByIdQuery
if err := c.ShouldBindUri(&searchByIdQuery); err == nil {
var model models.MileageQueryModel
err := c.BindQuery(&model)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
return
}
fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since, model.MileageOption)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
return
}
c.JSON(http.StatusOK, fillups)
} else {
c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err))
}
}