add fuel subtype to fillup

This commit is contained in:
Akhil Gupta
2021-07-23 16:30:55 +05:30
parent 19ab2a59dd
commit 4ee44fb1f1
10 changed files with 69 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ func RegisterVehicleController(router *gin.RouterGroup) {
router.GET("/me/stats", getMystats)
router.GET("/vehicles/:id/fillups", getFillupsByVehicleId)
router.GET("/vehicles/:id/fuelSubTypes", getFuelSubTypesByVehicleId)
router.POST("/vehicles/:id/fillups", createFillup)
router.GET("/vehicles/:id/fillups/:subId", getFillupById)
router.PUT("/vehicles/:id/fillups/:subId", updateFillup)
@@ -121,6 +122,22 @@ func getFillupsByVehicleId(c *gin.Context) {
c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err))
}
}
func getFuelSubTypesByVehicleId(c *gin.Context) {
var searchByIdQuery models.SearchByIdQuery
if err := c.ShouldBindUri(&searchByIdQuery); err == nil {
fuelSubtypes, err := service.GetDistinctFuelSubtypesForVehicle(searchByIdQuery.Id)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getFuelSubTypesByVehicleId", err))
return
}
c.JSON(http.StatusOK, fuelSubtypes)
} else {
c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err))
}
}
func getExpensesByVehicleId(c *gin.Context) {