Merge branch 'master' into feat/state_mileage_option

This commit is contained in:
Alf Sebastian Houge
2023-01-28 22:19:02 +01:00
committed by GitHub
42 changed files with 40921 additions and 12688 deletions

4
server/.gitignore vendored
View File

@@ -12,6 +12,10 @@
*.out
*.db
# MS VSCode
.vscode
__debug_bin
# Dependency directories (remove the comment below to include it)
# vendor/
assets/*

View File

@@ -16,7 +16,7 @@ RUN go build -o ./app ./main.go
FROM alpine:latest
LABEL org.opencontainers.image.source="https://github.com/akhilrex/hammond"
LABEL org.opencontainers.image.source="https://github.com/alfhou/hammond"
ENV CONFIG=/config
ENV DATA=/assets
@@ -38,4 +38,4 @@ COPY dist ./dist
EXPOSE 3000
ENTRYPOINT ["./app"]
ENTRYPOINT ["./app"]

View File

@@ -115,7 +115,7 @@ func userLogin(c *gin.Context) {
Email: user.Email,
Token: token,
RefreshToken: refreshToken,
Role: user.RoleDetail().Long,
Role: user.RoleDetail().Key,
}
c.JSON(http.StatusOK, response)
}
@@ -149,7 +149,7 @@ func refresh(c *gin.Context) {
Email: user.Email,
Token: token,
RefreshToken: refreshToken,
Role: user.RoleDetail().Long,
Role: user.RoleDetail().Key,
}
c.JSON(http.StatusOK, response)
} else {

View File

@@ -60,6 +60,7 @@ type Vehicle struct {
Base
Nickname string `json:"nickname"`
Registration string `json:"registration"`
VIN string `json:"vin"`
Make string `json:"make"`
Model string `json:"model"`
YearOfManufacture int `json:"yearOfManufacture"`

View File

@@ -52,75 +52,58 @@ const (
)
type EnumDetail struct {
Short string `json:"short"`
Long string `json:"long"`
Key string `json:"key"`
}
var FuelUnitDetails map[FuelUnit]EnumDetail = map[FuelUnit]EnumDetail{
LITRE: {
Short: "Lt",
Long: "Litre",
Key: "litre",
},
GALLON: {
Short: "Gal",
Long: "Gallon",
Key: "gallon",
}, KILOGRAM: {
Short: "Kg",
Long: "Kilogram",
Key: "kilogram",
}, KILOWATT_HOUR: {
Short: "KwH",
Long: "Kilowatt Hour",
Key: "kilowatthour",
}, US_GALLON: {
Short: "US Gal",
Long: "US Gallon",
Key: "usgallon",
},
MINUTE: {
Short: "Mins",
Long: "Minutes",
Key: "minutes",
},
}
var FuelTypeDetails map[FuelType]EnumDetail = map[FuelType]EnumDetail{
PETROL: {
Short: "Petrol",
Long: "Petrol",
Key: "petrol",
},
DIESEL: {
Short: "Diesel",
Long: "Diesel",
Key: "diesel",
}, CNG: {
Short: "CNG",
Long: "CNG",
Key: "cng",
}, LPG: {
Short: "LPG",
Long: "LPG",
Key: "lpg",
}, ELECTRIC: {
Short: "Electric",
Long: "Electric",
Key: "electric",
}, ETHANOL: {
Short: "Ethanol",
Long: "Ethanol",
Key: "ethanol",
},
}
var DistanceUnitDetails map[DistanceUnit]EnumDetail = map[DistanceUnit]EnumDetail{
KILOMETERS: {
Short: "Km",
Long: "Kilometers",
Key: "kilometers",
},
MILES: {
Short: "Mi",
Long: "Miles",
Key: "miles",
},
}
var RoleDetails map[Role]EnumDetail = map[Role]EnumDetail{
ADMIN: {
Short: "Admin",
Long: "ADMIN",
Key: "ADMIN",
},
USER: {
Short: "User",
Long: "USER",
Key: "USER",
},
}

View File

@@ -21,6 +21,11 @@ var migrations = []localMigration{
{
Name: "2021_02_07_00_09_LowerCaseEmails",
Query: "update users set email=lower(email)",
},
{
Name: "2022_03_08_13_16_AddVIN",
Query: "ALTER TABLE vehicles ADD COLUMN vin text",
},
}

View File

@@ -17,6 +17,7 @@ type SubItemQuery struct {
type CreateVehicleRequest struct {
Nickname string `form:"nickname" json:"nickname" binding:"required"`
Registration string `form:"registration" json:"registration" binding:"required"`
VIN string `form:"vin" json:"vin"`
Make string `form:"make" json:"make" binding:"required"`
Model string `form:"model" json:"model" binding:"required"`
YearOfManufacture int `form:"yearOfManufacture" json:"yearOfManufacture"`

View File

@@ -14,6 +14,7 @@ func CreateVehicle(model models.CreateVehicleRequest, userId string) (*db.Vehicl
Nickname: model.Nickname,
Registration: model.Registration,
Model: model.Model,
VIN: model.VIN,
Make: model.Make,
YearOfManufacture: model.YearOfManufacture,
EngineSize: model.EngineSize,
@@ -100,6 +101,7 @@ func UpdateVehicle(vehicleID string, model models.UpdateVehicleRequest) error {
//return db.DB.Model(&toUpdate).Updates(db.Vehicle{
toUpdate.Nickname = model.Nickname
toUpdate.Registration = model.Registration
toUpdate.VIN = model.VIN
toUpdate.Model = model.Model
toUpdate.Make = model.Make
toUpdate.YearOfManufacture = model.YearOfManufacture