first commit

This commit is contained in:
Akhil Gupta
2021-05-29 15:20:50 +05:30
commit d25c30a7b2
194 changed files with 49873 additions and 0 deletions

30
server/models/auth.go Normal file
View File

@@ -0,0 +1,30 @@
package models
import "github.com/akhilrex/hammond/db"
type LoginResponse struct {
Name string `json:"name"`
Email string `json:"email"`
Token string `json:"token"`
RefreshToken string `json:"refreshToken"`
Role string `json:"role"`
}
type LoginRequest struct {
Email string `form:"email" json:"email" binding:"required,email"`
Password string `form:"password" json:"password" binding:"required,min=6,max=255"`
}
type RegisterRequest struct {
Name string `form:"name" json:"name"`
Email string `form:"email" json:"email" binding:"required,email"`
Password string `form:"password" json:"password" binding:"required,min=8,max=255"`
Currency string `json:"currency" form:"currency" query:"currency"`
DistanceUnit *db.DistanceUnit `json:"distanceUnit" form:"distanceUnit" query:"distanceUnit" `
Role *db.Role `json:"role" form:"role" query:"role" `
}
type ChangePasswordRequest struct {
OldPassword string `form:"oldPassword" json:"oldPassword" binding:"required,min=8,max=255"`
NewPassword string `form:"newPassword" json:"newPassword" binding:"required,min=8,max=255"`
}

849
server/models/currency.go Normal file
View File

@@ -0,0 +1,849 @@
package models
type CurrencyModel struct {
Symbol string `json:"symbol"`
SymbolNative string `json:"symbolNative"`
DecimalDigits string `json:"decimalDigits"`
Rounding string `json:"rounding"`
Code string `json:"code"`
NamePlural string `json:"namePlural"`
}
func GetCurrencyMasterList() []CurrencyModel {
return []CurrencyModel{
{
Symbol: "$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "USD",
NamePlural: "US dollars",
}, {
Symbol: "CA$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "CAD",
NamePlural: "Canadian dollars",
}, {
Symbol: "€",
SymbolNative: "€",
DecimalDigits: "2",
Rounding: "0",
Code: "EUR",
NamePlural: "euros",
}, {
Symbol: "AED",
SymbolNative: "د.إ.",
DecimalDigits: "2",
Rounding: "0",
Code: "AED",
NamePlural: "UAE dirhams",
}, {
Symbol: "Af",
SymbolNative: "؋",
DecimalDigits: "0",
Rounding: "0",
Code: "AFN",
NamePlural: "Afghan Afghanis",
}, {
Symbol: "ALL",
SymbolNative: "Lek",
DecimalDigits: "0",
Rounding: "0",
Code: "ALL",
NamePlural: "Albanian lekë",
}, {
Symbol: "AMD",
SymbolNative: "դր.",
DecimalDigits: "0",
Rounding: "0",
Code: "AMD",
NamePlural: "Armenian drams",
}, {
Symbol: "AR$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "ARS",
NamePlural: "Argentine pesos",
}, {
Symbol: "AU$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "AUD",
NamePlural: "Australian dollars",
}, {
Symbol: "man.",
SymbolNative: "ман.",
DecimalDigits: "2",
Rounding: "0",
Code: "AZN",
NamePlural: "Azerbaijani manats",
}, {
Symbol: "KM",
SymbolNative: "KM",
DecimalDigits: "2",
Rounding: "0",
Code: "BAM",
NamePlural: "Bosnia-Herzegovina convertible marks",
}, {
Symbol: "Tk",
SymbolNative: "৳",
DecimalDigits: "2",
Rounding: "0",
Code: "BDT",
NamePlural: "Bangladeshi takas",
}, {
Symbol: "BGN",
SymbolNative: "лв.",
DecimalDigits: "2",
Rounding: "0",
Code: "BGN",
NamePlural: "Bulgarian leva",
}, {
Symbol: "BD",
SymbolNative: "د.ب.",
DecimalDigits: "3",
Rounding: "0",
Code: "BHD",
NamePlural: "Bahraini dinars",
}, {
Symbol: "FBu",
SymbolNative: "FBu",
DecimalDigits: "0",
Rounding: "0",
Code: "BIF",
NamePlural: "Burundian francs",
}, {
Symbol: "BN$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "BND",
NamePlural: "Brunei dollars",
}, {
Symbol: "Bs",
SymbolNative: "Bs",
DecimalDigits: "2",
Rounding: "0",
Code: "BOB",
NamePlural: "Bolivian bolivianos",
}, {
Symbol: "R$",
SymbolNative: "R$",
DecimalDigits: "2",
Rounding: "0",
Code: "BRL",
NamePlural: "Brazilian reals",
}, {
Symbol: "BWP",
SymbolNative: "P",
DecimalDigits: "2",
Rounding: "0",
Code: "BWP",
NamePlural: "Botswanan pulas",
}, {
Symbol: "Br",
SymbolNative: "руб.",
DecimalDigits: "2",
Rounding: "0",
Code: "BYN",
NamePlural: "Belarusian rubles",
}, {
Symbol: "BZ$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "BZD",
NamePlural: "Belize dollars",
}, {
Symbol: "CDF",
SymbolNative: "FrCD",
DecimalDigits: "2",
Rounding: "0",
Code: "CDF",
NamePlural: "Congolese francs",
}, {
Symbol: "CHF",
SymbolNative: "CHF",
DecimalDigits: "2",
Rounding: "0.05",
Code: "CHF",
NamePlural: "Swiss francs",
}, {
Symbol: "CL$",
SymbolNative: "$",
DecimalDigits: "0",
Rounding: "0",
Code: "CLP",
NamePlural: "Chilean pesos",
}, {
Symbol: "CN¥",
SymbolNative: "CN¥",
DecimalDigits: "2",
Rounding: "0",
Code: "CNY",
NamePlural: "Chinese yuan",
}, {
Symbol: "CO$",
SymbolNative: "$",
DecimalDigits: "0",
Rounding: "0",
Code: "COP",
NamePlural: "Colombian pesos",
}, {
Symbol: "₡",
SymbolNative: "₡",
DecimalDigits: "0",
Rounding: "0",
Code: "CRC",
NamePlural: "Costa Rican colóns",
}, {
Symbol: "CV$",
SymbolNative: "CV$",
DecimalDigits: "2",
Rounding: "0",
Code: "CVE",
NamePlural: "Cape Verdean escudos",
}, {
Symbol: "Kč",
SymbolNative: "Kč",
DecimalDigits: "2",
Rounding: "0",
Code: "CZK",
NamePlural: "Czech Republic korunas",
}, {
Symbol: "Fdj",
SymbolNative: "Fdj",
DecimalDigits: "0",
Rounding: "0",
Code: "DJF",
NamePlural: "Djiboutian francs",
}, {
Symbol: "Dkr",
SymbolNative: "kr",
DecimalDigits: "2",
Rounding: "0",
Code: "DKK",
NamePlural: "Danish kroner",
}, {
Symbol: "RD$",
SymbolNative: "RD$",
DecimalDigits: "2",
Rounding: "0",
Code: "DOP",
NamePlural: "Dominican pesos",
}, {
Symbol: "DA",
SymbolNative: "د.ج.",
DecimalDigits: "2",
Rounding: "0",
Code: "DZD",
NamePlural: "Algerian dinars",
}, {
Symbol: "Ekr",
SymbolNative: "kr",
DecimalDigits: "2",
Rounding: "0",
Code: "EEK",
NamePlural: "Estonian kroons",
}, {
Symbol: "EGP",
SymbolNative: "ج.م.",
DecimalDigits: "2",
Rounding: "0",
Code: "EGP",
NamePlural: "Egyptian pounds",
}, {
Symbol: "Nfk",
SymbolNative: "Nfk",
DecimalDigits: "2",
Rounding: "0",
Code: "ERN",
NamePlural: "Eritrean nakfas",
}, {
Symbol: "Br",
SymbolNative: "Br",
DecimalDigits: "2",
Rounding: "0",
Code: "ETB",
NamePlural: "Ethiopian birrs",
}, {
Symbol: "£",
SymbolNative: "£",
DecimalDigits: "2",
Rounding: "0",
Code: "GBP",
NamePlural: "British pounds sterling",
}, {
Symbol: "GEL",
SymbolNative: "GEL",
DecimalDigits: "2",
Rounding: "0",
Code: "GEL",
NamePlural: "Georgian laris",
}, {
Symbol: "GH₵",
SymbolNative: "GH₵",
DecimalDigits: "2",
Rounding: "0",
Code: "GHS",
NamePlural: "Ghanaian cedis",
}, {
Symbol: "FG",
SymbolNative: "FG",
DecimalDigits: "0",
Rounding: "0",
Code: "GNF",
NamePlural: "Guinean francs",
}, {
Symbol: "GTQ",
SymbolNative: "Q",
DecimalDigits: "2",
Rounding: "0",
Code: "GTQ",
NamePlural: "Guatemalan quetzals",
}, {
Symbol: "HK$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "HKD",
NamePlural: "Hong Kong dollars",
}, {
Symbol: "HNL",
SymbolNative: "L",
DecimalDigits: "2",
Rounding: "0",
Code: "HNL",
NamePlural: "Honduran lempiras",
}, {
Symbol: "kn",
SymbolNative: "kn",
DecimalDigits: "2",
Rounding: "0",
Code: "HRK",
NamePlural: "Croatian kunas",
}, {
Symbol: "Ft",
SymbolNative: "Ft",
DecimalDigits: "0",
Rounding: "0",
Code: "HUF",
NamePlural: "Hungarian forints",
}, {
Symbol: "Rp",
SymbolNative: "Rp",
DecimalDigits: "0",
Rounding: "0",
Code: "IDR",
NamePlural: "Indonesian rupiahs",
}, {
Symbol: "₪",
SymbolNative: "₪",
DecimalDigits: "2",
Rounding: "0",
Code: "ILS",
NamePlural: "Israeli new sheqels",
}, {
Symbol: "Rs",
SymbolNative: "টকা",
DecimalDigits: "2",
Rounding: "0",
Code: "INR",
NamePlural: "Indian rupees",
}, {
Symbol: "IQD",
SymbolNative: "د.ع.",
DecimalDigits: "0",
Rounding: "0",
Code: "IQD",
NamePlural: "Iraqi dinars",
}, {
Symbol: "IRR",
SymbolNative: "﷼",
DecimalDigits: "0",
Rounding: "0",
Code: "IRR",
NamePlural: "Iranian rials",
}, {
Symbol: "Ikr",
SymbolNative: "kr",
DecimalDigits: "0",
Rounding: "0",
Code: "ISK",
NamePlural: "Icelandic krónur",
}, {
Symbol: "J$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "JMD",
NamePlural: "Jamaican dollars",
}, {
Symbol: "JD",
SymbolNative: "د.أ.",
DecimalDigits: "3",
Rounding: "0",
Code: "JOD",
NamePlural: "Jordanian dinars",
}, {
Symbol: "¥",
SymbolNative: "¥",
DecimalDigits: "0",
Rounding: "0",
Code: "JPY",
NamePlural: "Japanese yen",
}, {
Symbol: "Ksh",
SymbolNative: "Ksh",
DecimalDigits: "2",
Rounding: "0",
Code: "KES",
NamePlural: "Kenyan shillings",
}, {
Symbol: "KHR",
SymbolNative: "៛",
DecimalDigits: "2",
Rounding: "0",
Code: "KHR",
NamePlural: "Cambodian riels",
}, {
Symbol: "CF",
SymbolNative: "FC",
DecimalDigits: "0",
Rounding: "0",
Code: "KMF",
NamePlural: "Comorian francs",
}, {
Symbol: "₩",
SymbolNative: "₩",
DecimalDigits: "0",
Rounding: "0",
Code: "KRW",
NamePlural: "South Korean won",
}, {
Symbol: "KD",
SymbolNative: "د.ك.",
DecimalDigits: "3",
Rounding: "0",
Code: "KWD",
NamePlural: "Kuwaiti dinars",
}, {
Symbol: "KZT",
SymbolNative: "тңг.",
DecimalDigits: "2",
Rounding: "0",
Code: "KZT",
NamePlural: "Kazakhstani tenges",
}, {
Symbol: "LB£",
SymbolNative: "ل.ل.",
DecimalDigits: "0",
Rounding: "0",
Code: "LBP",
NamePlural: "Lebanese pounds",
}, {
Symbol: "SLRs",
SymbolNative: "SL Re",
DecimalDigits: "2",
Rounding: "0",
Code: "LKR",
NamePlural: "Sri Lankan rupees",
}, {
Symbol: "Lt",
SymbolNative: "Lt",
DecimalDigits: "2",
Rounding: "0",
Code: "LTL",
NamePlural: "Lithuanian litai",
}, {
Symbol: "Ls",
SymbolNative: "Ls",
DecimalDigits: "2",
Rounding: "0",
Code: "LVL",
NamePlural: "Latvian lati",
}, {
Symbol: "LD",
SymbolNative: "د.ل.",
DecimalDigits: "3",
Rounding: "0",
Code: "LYD",
NamePlural: "Libyan dinars",
}, {
Symbol: "MAD",
SymbolNative: "د.م.",
DecimalDigits: "2",
Rounding: "0",
Code: "MAD",
NamePlural: "Moroccan dirhams",
}, {
Symbol: "MDL",
SymbolNative: "MDL",
DecimalDigits: "2",
Rounding: "0",
Code: "MDL",
NamePlural: "Moldovan lei",
}, {
Symbol: "MGA",
SymbolNative: "MGA",
DecimalDigits: "0",
Rounding: "0",
Code: "MGA",
NamePlural: "Malagasy Ariaries",
}, {
Symbol: "MKD",
SymbolNative: "MKD",
DecimalDigits: "2",
Rounding: "0",
Code: "MKD",
NamePlural: "Macedonian denari",
}, {
Symbol: "MMK",
SymbolNative: "K",
DecimalDigits: "0",
Rounding: "0",
Code: "MMK",
NamePlural: "Myanma kyats",
}, {
Symbol: "MOP$",
SymbolNative: "MOP$",
DecimalDigits: "2",
Rounding: "0",
Code: "MOP",
NamePlural: "Macanese patacas",
}, {
Symbol: "MURs",
SymbolNative: "MURs",
DecimalDigits: "0",
Rounding: "0",
Code: "MUR",
NamePlural: "Mauritian rupees",
}, {
Symbol: "MX$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "MXN",
NamePlural: "Mexican pesos",
}, {
Symbol: "RM",
SymbolNative: "RM",
DecimalDigits: "2",
Rounding: "0",
Code: "MYR",
NamePlural: "Malaysian ringgits",
}, {
Symbol: "MTn",
SymbolNative: "MTn",
DecimalDigits: "2",
Rounding: "0",
Code: "MZN",
NamePlural: "Mozambican meticals",
}, {
Symbol: "N$",
SymbolNative: "N$",
DecimalDigits: "2",
Rounding: "0",
Code: "NAD",
NamePlural: "Namibian dollars",
}, {
Symbol: "₦",
SymbolNative: "₦",
DecimalDigits: "2",
Rounding: "0",
Code: "NGN",
NamePlural: "Nigerian nairas",
}, {
Symbol: "C$",
SymbolNative: "C$",
DecimalDigits: "2",
Rounding: "0",
Code: "NIO",
NamePlural: "Nicaraguan córdobas",
}, {
Symbol: "Nkr",
SymbolNative: "kr",
DecimalDigits: "2",
Rounding: "0",
Code: "NOK",
NamePlural: "Norwegian kroner",
}, {
Symbol: "NPRs",
SymbolNative: "नेरू",
DecimalDigits: "2",
Rounding: "0",
Code: "NPR",
NamePlural: "Nepalese rupees",
}, {
Symbol: "NZ$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "NZD",
NamePlural: "New Zealand dollars",
}, {
Symbol: "OMR",
SymbolNative: "ر.ع.",
DecimalDigits: "3",
Rounding: "0",
Code: "OMR",
NamePlural: "Omani rials",
}, {
Symbol: "B/.",
SymbolNative: "B/.",
DecimalDigits: "2",
Rounding: "0",
Code: "PAB",
NamePlural: "Panamanian balboas",
}, {
Symbol: "S/.",
SymbolNative: "S/.",
DecimalDigits: "2",
Rounding: "0",
Code: "PEN",
NamePlural: "Peruvian nuevos soles",
}, {
Symbol: "₱",
SymbolNative: "₱",
DecimalDigits: "2",
Rounding: "0",
Code: "PHP",
NamePlural: "Philippine pesos",
}, {
Symbol: "PKRs",
SymbolNative: "₨",
DecimalDigits: "0",
Rounding: "0",
Code: "PKR",
NamePlural: "Pakistani rupees",
}, {
Symbol: "zł",
SymbolNative: "zł",
DecimalDigits: "2",
Rounding: "0",
Code: "PLN",
NamePlural: "Polish zlotys",
}, {
Symbol: "₲",
SymbolNative: "₲",
DecimalDigits: "0",
Rounding: "0",
Code: "PYG",
NamePlural: "Paraguayan guaranis",
}, {
Symbol: "QR",
SymbolNative: "ر.ق.",
DecimalDigits: "2",
Rounding: "0",
Code: "QAR",
NamePlural: "Qatari rials",
}, {
Symbol: "RON",
SymbolNative: "RON",
DecimalDigits: "2",
Rounding: "0",
Code: "RON",
NamePlural: "Romanian lei",
}, {
Symbol: "din.",
SymbolNative: "дин.",
DecimalDigits: "0",
Rounding: "0",
Code: "RSD",
NamePlural: "Serbian dinars",
}, {
Symbol: "RUB",
SymbolNative: "₽.",
DecimalDigits: "2",
Rounding: "0",
Code: "RUB",
NamePlural: "Russian rubles",
}, {
Symbol: "RWF",
SymbolNative: "FR",
DecimalDigits: "0",
Rounding: "0",
Code: "RWF",
NamePlural: "Rwandan francs",
}, {
Symbol: "SR",
SymbolNative: "ر.س.",
DecimalDigits: "2",
Rounding: "0",
Code: "SAR",
NamePlural: "Saudi riyals",
}, {
Symbol: "SDG",
SymbolNative: "SDG",
DecimalDigits: "2",
Rounding: "0",
Code: "SDG",
NamePlural: "Sudanese pounds",
}, {
Symbol: "Skr",
SymbolNative: "kr",
DecimalDigits: "2",
Rounding: "0",
Code: "SEK",
NamePlural: "Swedish kronor",
}, {
Symbol: "S$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "SGD",
NamePlural: "Singapore dollars",
}, {
Symbol: "Ssh",
SymbolNative: "Ssh",
DecimalDigits: "0",
Rounding: "0",
Code: "SOS",
NamePlural: "Somali shillings",
}, {
Symbol: "SY£",
SymbolNative: "ل.س.",
DecimalDigits: "0",
Rounding: "0",
Code: "SYP",
NamePlural: "Syrian pounds",
}, {
Symbol: "฿",
SymbolNative: "฿",
DecimalDigits: "2",
Rounding: "0",
Code: "THB",
NamePlural: "Thai baht",
}, {
Symbol: "DT",
SymbolNative: "د.ت.",
DecimalDigits: "3",
Rounding: "0",
Code: "TND",
NamePlural: "Tunisian dinars",
}, {
Symbol: "T$",
SymbolNative: "T$",
DecimalDigits: "2",
Rounding: "0",
Code: "TOP",
NamePlural: "Tongan paʻanga",
}, {
Symbol: "TL",
SymbolNative: "TL",
DecimalDigits: "2",
Rounding: "0",
Code: "TRY",
NamePlural: "Turkish Lira",
}, {
Symbol: "TT$",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "TTD",
NamePlural: "Trinidad and Tobago dollars",
}, {
Symbol: "NT$",
SymbolNative: "NT$",
DecimalDigits: "2",
Rounding: "0",
Code: "TWD",
NamePlural: "New Taiwan dollars",
}, {
Symbol: "TSh",
SymbolNative: "TSh",
DecimalDigits: "0",
Rounding: "0",
Code: "TZS",
NamePlural: "Tanzanian shillings",
}, {
Symbol: "₴",
SymbolNative: "₴",
DecimalDigits: "2",
Rounding: "0",
Code: "UAH",
NamePlural: "Ukrainian hryvnias",
}, {
Symbol: "USh",
SymbolNative: "USh",
DecimalDigits: "0",
Rounding: "0",
Code: "UGX",
NamePlural: "Ugandan shillings",
}, {
Symbol: "$U",
SymbolNative: "$",
DecimalDigits: "2",
Rounding: "0",
Code: "UYU",
NamePlural: "Uruguayan pesos",
}, {
Symbol: "UZS",
SymbolNative: "UZS",
DecimalDigits: "0",
Rounding: "0",
Code: "UZS",
NamePlural: "Uzbekistan som",
}, {
Symbol: "Bs.F.",
SymbolNative: "Bs.F.",
DecimalDigits: "2",
Rounding: "0",
Code: "VEF",
NamePlural: "Venezuelan bolívars",
}, {
Symbol: "₫",
SymbolNative: "₫",
DecimalDigits: "0",
Rounding: "0",
Code: "VND",
NamePlural: "Vietnamese dong",
}, {
Symbol: "FCFA",
SymbolNative: "FCFA",
DecimalDigits: "0",
Rounding: "0",
Code: "XAF",
NamePlural: "CFA francs BEAC",
}, {
Symbol: "CFA",
SymbolNative: "CFA",
DecimalDigits: "0",
Rounding: "0",
Code: "XOF",
NamePlural: "CFA francs BCEAO",
}, {
Symbol: "YR",
SymbolNative: "ر.ي.",
DecimalDigits: "0",
Rounding: "0",
Code: "YER",
NamePlural: "Yemeni rials",
}, {
Symbol: "R",
SymbolNative: "R",
DecimalDigits: "2",
Rounding: "0",
Code: "ZAR",
NamePlural: "South African rand",
}, {
Symbol: "ZK",
SymbolNative: "ZK",
DecimalDigits: "0",
Rounding: "0",
Code: "ZMK",
NamePlural: "Zambian kwachas",
}, {
Symbol: "ZWL$",
SymbolNative: "ZWL$",
DecimalDigits: "0",
Rounding: "0",
Code: "ZWL",
NamePlural: "Zimbabwean Dollar",
},
}
}

11
server/models/errors.go Normal file
View File

@@ -0,0 +1,11 @@
package models
import "fmt"
type VehicleAlreadyExistsError struct {
Registration string
}
func (e *VehicleAlreadyExistsError) Error() string {
return fmt.Sprintf("Vehicle with this url already exists")
}

5
server/models/files.go Normal file
View File

@@ -0,0 +1,5 @@
package models
type CreateQuickEntryModel struct {
Comments string `json:"comments" form:"comments"`
}

12
server/models/misc.go Normal file
View File

@@ -0,0 +1,12 @@
package models
import "github.com/akhilrex/hammond/db"
type UpdateSettingModel struct {
Currency string `json:"currency" form:"currency" query:"currency"`
DistanceUnit *db.DistanceUnit `json:"distanceUnit" form:"distanceUnit" query:"distanceUnit" `
}
type ClarksonMigrationModel struct {
Url string `json:"url" form:"url" query:"url"`
}

150
server/models/vehicle.go Normal file
View File

@@ -0,0 +1,150 @@
package models
import (
"time"
"github.com/akhilrex/hammond/db"
_ "github.com/go-playground/validator/v10"
)
type SearchByIdQuery struct {
Id string `binding:"required" uri:"id" json:"id" form:"id"`
}
type SubItemQuery struct {
Id string `binding:"required" uri:"id" json:"id" form:"id"`
SubId string `binding:"required" uri:"subId" json:"subId" form:"subId"`
}
type CreateVehicleRequest struct {
Nickname string `form:"nickname" json:"nickname" binding:"required"`
Registration string `form:"registration" json:"registration" binding:"required"`
Make string `form:"make" json:"make" binding:"required"`
Model string `form:"model" json:"model" binding:"required"`
YearOfManufacture int `form:"yearOfManufacture" json:"yearOfManufacture"`
EngineSize float32 `form:"engineSize" json:"engineSize"`
FuelUnit *db.FuelUnit `form:"fuelUnit" json:"fuelUnit" binding:"required"`
FuelType *db.FuelType `form:"fuelType" json:"fuelType" binding:"required"`
}
type UpdateVehicleRequest struct {
CreateVehicleRequest
}
type UserVehicleSimpleModel struct {
ID string `json:"id"`
UserID string `json:"userId"`
VehicleID string `json:"vehicleId"`
IsOwner bool `json:"isOwner"`
Name string `json:"name"`
}
type CreateFillupRequest struct {
VehicleID string `form:"vehicleId" json:"vehicleId" binding:"required"`
FuelUnit *db.FuelUnit `form:"fuelUnit" json:"fuelUnit" binding:"required"`
FuelQuantity float32 `form:"fuelQuantity" json:"fuelQuantity" binding:"required"`
PerUnitPrice float32 `form:"perUnitPrice" json:"perUnitPrice" binding:"required"`
TotalAmount float32 `form:"totalAmount" json:"totalAmount" binding:"required"`
OdoReading int `form:"odoReading" json:"odoReading" binding:"required"`
IsTankFull *bool `form:"isTankFull" json:"isTankFull" binding:"required"`
HasMissedFillup *bool `form:"hasMissedFillup" json:"HasMissedFillup"`
Comments string `form:"comments" json:"comments" `
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"`
}
type UpdateFillupRequest struct {
CreateFillupRequest
}
type UpdateExpenseRequest struct {
CreateExpenseRequest
}
type CreateExpenseRequest struct {
VehicleID string `form:"vehicleId" json:"vehicleId" binding:"required"`
Amount float32 `form:"amount" json:"amount" binding:"required"`
OdoReading int `form:"odoReading" json:"odoReading"`
Comments string `form:"comments" json:"comments" `
ExpenseType string `form:"expenseType" json:"expenseType"`
UserID string `form:"userId" json:"userId" binding:"required"`
Date time.Time `form:"date" json:"date" binding:"required" time_format:"2006-01-02"`
}
type CreateVehicleAttachmentModel struct {
Title string `form:"title" json:"title" binding:"required"`
}
type VehicleStatsModel struct {
CountFillups int `json:"countFillups"`
CountExpenses int `json:"countExpenses"`
ExpenditureFillups float32 `json:"expenditureFillups"`
ExpenditureExpenses float32 `json:"expenditureExpenses"`
ExpenditureTotal float32 `json:"expenditureTotal"`
AvgFillupCost float32 `json:"avgFillupCost"`
AvgExpenseCost float32 `json:"avgExpenseCost"`
AvgFuelQty float32 `json:"avgFuelQty"`
AvgFuelPrice float32 `json:"avgFuelPrice"`
Currency string `json:"currency"`
}
func (m *VehicleStatsModel) SetStats(fillups *[]db.Fillup, expenses *[]db.Expense) []VehicleStatsModel {
currencyMap := make(map[string]int)
for _, v := range *fillups {
currencyMap[v.Currency] = 1
}
for _, v := range *expenses {
currencyMap[v.Currency] = 1
}
var toReturn []VehicleStatsModel
for currency, _ := range currencyMap {
model := VehicleStatsModel{}
var totalExpenditure, fillupTotal, expenseTotal, totalFuel, averageFuelCost, averageFuelQty, averageFillup, averageExpense float32
var countFillup, countExpense int
for _, v := range *fillups {
if v.Currency == currency {
fillupTotal = fillupTotal + v.TotalAmount
totalFuel = totalFuel + v.FuelQuantity
countFillup++
}
}
for _, v := range *expenses {
if v.Currency == currency {
expenseTotal = expenseTotal + v.Amount
countExpense++
}
}
totalExpenditure = expenseTotal + fillupTotal
if countFillup > 0 {
averageFillup = fillupTotal / float32(countFillup)
averageFuelCost = fillupTotal / totalFuel
averageFuelQty = totalFuel / float32(countFillup)
}
if countExpense > 0 {
averageExpense = expenseTotal / float32(countExpense)
}
model.CountFillups = countFillup
model.CountExpenses = countExpense
model.ExpenditureFillups = fillupTotal
model.ExpenditureExpenses = expenseTotal
model.ExpenditureTotal = totalExpenditure
model.AvgFillupCost = averageFillup
model.AvgExpenseCost = averageExpense
model.AvgFuelPrice = averageFuelCost
model.AvgFuelQty = averageFuelQty
model.Currency = currency
toReturn = append(toReturn, model)
}
return toReturn
}
type UserStatsQueryModel struct {
Start time.Time `json:"start" query:"start" form:"start"`
End time.Time `json:"end" query:"end" form:"end"`
}