add fuel subtype to fillup
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ type Fillup struct {
|
||||
Currency string `json:"currency"`
|
||||
DistanceUnit DistanceUnit `json:"distanceUnit"`
|
||||
Source string `json:"source"`
|
||||
FuelSubType string `json:"fuelSubType"`
|
||||
}
|
||||
|
||||
func (v *Fillup) FuelUnitDetail() EnumDetail {
|
||||
|
||||
@@ -50,6 +50,7 @@ type CreateFillupRequest struct {
|
||||
FillingStation string `form:"fillingStation" json:"fillingStation"`
|
||||
UserID string `form:"userId" json:"userId" binding:"required"`
|
||||
Date time.Time `form:"date" json:"date" binding:"required" time_format:"2006-01-02"`
|
||||
FuelSubType string `form:"fuelSubType" json:"fuelSubType"`
|
||||
}
|
||||
|
||||
type UpdateFillupRequest struct {
|
||||
|
||||
@@ -139,6 +139,7 @@ func CreateFillup(model models.CreateFillupRequest) (*db.Fillup, error) {
|
||||
Date: model.Date,
|
||||
Currency: user.Currency,
|
||||
DistanceUnit: user.DistanceUnit,
|
||||
FuelSubType: model.FuelSubType,
|
||||
Source: "API",
|
||||
}
|
||||
|
||||
@@ -196,6 +197,7 @@ func UpdateFillup(fillupId string, model models.UpdateFillupRequest) error {
|
||||
Comments: model.Comments,
|
||||
FillingStation: model.FillingStation,
|
||||
UserID: model.UserID,
|
||||
FuelSubType: model.FuelSubType,
|
||||
Date: model.Date,
|
||||
}).Error
|
||||
}
|
||||
@@ -235,6 +237,11 @@ func GetVehicleAttachments(vehicleId string) (*[]db.Attachment, error) {
|
||||
|
||||
return db.GetVehicleAttachments(vehicleId)
|
||||
}
|
||||
func GetDistinctFuelSubtypesForVehicle(vehicleId string) ([]string, error) {
|
||||
var names []string
|
||||
tx := db.DB.Model(&db.Fillup{}).Where("vehicle_id=? and fuel_sub_type is not null", vehicleId).Distinct().Pluck("fuel_sub_type", &names)
|
||||
return names, tx.Error
|
||||
}
|
||||
|
||||
func GetUserStats(userId string, model models.UserStatsQueryModel) ([]models.VehicleStatsModel, error) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user