Upstream sync

This commit is contained in:
Senad Uka
2023-10-13 11:48:14 +02:00
parent 7369739bdd
commit d01c1a0232
29 changed files with 563 additions and 444 deletions

View File

@@ -1,18 +0,0 @@
package models
import "github.com/jinzhu/gorm"
type Buyer struct {
gorm.Model
Name string
}
func (Buyer) Update() (bool, error) {
return false, nil
}
func (Buyer) Create() (bool, error) {
return false, nil
}
func (Buyer) Delete() (bool, error) {
return false, nil
}

View File

@@ -1,23 +1,24 @@
package models
import (
"database/sql"
"time"
"github.com/jinzhu/gorm"
)
type BaseModel struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updatedAt" gorm:"autoUpdateTime"`
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt,omitempty" gorm:"index"`
}
type Company struct {
gorm.Model
Name string `json:"name"`
Address string `json:"address"`
Email string `json:"email"`
Phone string `json:"phone"`
Users []User `json:"users"`
BaseModel
Name string `json:"name"`
Address string `json:"address"`
Email string `json:"email"`
Phone string `json:"phone"`
Users []User `json:"users"`
Devices []Device `json:"devices"`
}
@@ -26,7 +27,6 @@ type CompanyShortResponse struct {
Name string `json:"name"`
}
func (Company) Update() (bool, error) {
return false, nil
}

View File

@@ -3,12 +3,11 @@ package models
import (
"time"
"github.com/jinzhu/gorm"
"github.com/lib/pq"
)
type Contract struct {
gorm.Model
BaseModel
Name string `json:"name"`
DeviceIDs pq.Int64Array `json:"deviceIds" gorm:"type:integer[]"`
BuyerID uint `json:"buyerId"`
@@ -64,7 +63,7 @@ type ContractResponse struct {
}
func ConvertContractToResponse(contracts []Contract) []ContractResponse {
var contractResponses []ContractResponse
contractResponses := []ContractResponse{}
for _, contract := range contracts {
contractResponse := ContractResponse{
BaseModel: BaseModel{
@@ -102,13 +101,13 @@ func ConvertContractToResponse(contracts []Contract) []ContractResponse {
}
func ConvertContractToResponseModel(contracts []Contract) []ListContractResponse {
var listInvoiceResponses []ListContractResponse
listInvoiceResponses := []ListContractResponse{}
// Get all statuses
statuses := GetContractStatuses()
statusMap := make(map[string]Status)
for _, s := range statuses {
statusMap[s.Value] = s
statusMap[s.Key] = s
}
for _, contract := range contracts {
@@ -171,16 +170,22 @@ type ListContractResponse struct {
}
type CreateContractRequestPayload struct {
SellerID uint `json:"sellerId" binding:"required"`
BuyerID uint `json:"buyerId" binding:"required"`
Description string `json:"description"`
ProductID uint `json:"productId"`
MinTemp float64 `json:"minTemp" binding:"required"`
MaxTemp float64 `json:"maxTemp" binding:"required"`
ArrivalDate int64 `json:"arrivalDate"`
PenaltyType string `json:"penaltyType"`
PenaltyValue int `json:"penaltyValue"`
PenaltyRec string `json:"penaltyRec"`
SellerID uint `json:"sellerId" binding:"required"`
BuyerID uint `json:"buyerId" binding:"required"`
Description string `json:"description"`
ProductID uint `json:"productId"`
MinTemp float64 `json:"minTemp" binding:"required"`
MaxTemp float64 `json:"maxTemp" binding:"required"`
ArrivalDate int64 `json:"arrivalDate"`
PenaltyType string `json:"penaltyType"`
PenaltyValue int `json:"penaltyValue"`
PenaltyRec string `json:"penaltyRec"`
StartPlaceName string `json:"startPlaceName"`
StartLat float64 `json:"startLat"`
StartLon float64 `json:"startLon"`
EndPlaceName string `json:"endPlaceName"`
EndLat float64 `json:"endLat"`
EndLon float64 `json:"endLon"`
}
func (Contract) Update() (bool, error) {

View File

@@ -1,9 +1,7 @@
package models
import "github.com/jinzhu/gorm"
type ContractInfo struct {
gorm.Model
BaseModel
RawJSON string `json:"raw_json" gorm:"type:json"`
}

View File

@@ -4,26 +4,25 @@ import (
"github.com/jinzhu/gorm"
)
type Device struct {
gorm.Model
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
CompanyID uint `json:"companyId"`
BaseModel
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
CompanyID uint `json:"companyId"`
DeviceInfos *[]DeviceInfo `json:"deviceInfos"`
}
type DeviceResponse struct {
BaseModel
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
CompanyID uint `json:"companyId"`
DeviceID string `json:"deviceId"`
DeviceName string `json:"deviceName"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
DeviceConfiguration string `json:"deviceConfiguration" gorm:"type:json"`
CompanyID uint `json:"companyId"`
DeviceInfos *[]DeviceInfo `json:"deviceInfos"`
}
@@ -69,4 +68,3 @@ func (d *Device) Delete(db *gorm.DB) (bool, error) {
return true, nil
}

View File

@@ -1,9 +1,5 @@
package models
import (
"github.com/jinzhu/gorm"
)
// Location holds latitude and longitude.
type Location struct {
Lat float64 `json:"lat"`
@@ -12,32 +8,31 @@ type Location struct {
// ImportantInfo holds fields that are important for quick access.
type SensorData struct {
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
Timestamp int64 `json:"timestamp"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
WifiLoc Location `json:"wifiLocation"`
CellLoc Location `json:"cellLocation"`
Temperature float64 `json:"temperature"`
AccInfo AccelerometerInfo `json:"accelerometerInfo"`
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
Timestamp int64 `json:"timestamp"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
WifiLoc Location `json:"wifiLocation"`
CellLoc Location `json:"cellLocation"`
Temperature float64 `json:"temperature"`
AccInfo AccelerometerInfo `json:"accelerometerInfo"`
AccelerometerInfo
}
type DeviceInfo struct {
gorm.Model
BaseModel
RawJSON string `json:"raw_json" gorm:"type:json"`
SensorData
DeviceID uint
DeviceID uint
ExternalDeviceID string `json:"deviceId"`
}
type DeviceInfoResponse struct {
BaseModel
RawJSON string `json:"rawJson" gorm:"type:json"`
SensorData
DeviceID uint `json:"deviceId"`
DeviceID uint `json:"deviceId"`
ExternalDeviceID string `json:"externalDeviceId"`
}
@@ -51,7 +46,7 @@ func ConvertDeviceInfoToResponse(deviceInfos []DeviceInfo) []DeviceInfoResponse
UpdatedAt: deviceInfo.UpdatedAt,
},
RawJSON: deviceInfo.RawJSON,
SensorData: deviceInfo.SensorData,
SensorData: deviceInfo.SensorData,
DeviceID: deviceInfo.DeviceID,
ExternalDeviceID: deviceInfo.ExternalDeviceID,
}
@@ -71,10 +66,10 @@ type GeoJSONFeatureCollection struct {
}
type GeoJSONFeature struct {
Type string `json:"type"`
Geometry GeoJSONGeometry `json:"geometry"`
DeviceInfoResponse *DeviceInfoResponse `json:"deviceInfo,omitempty"`
Properties map[string]interface{} `json:"properties"`
Type string `json:"type"`
Geometry GeoJSONGeometry `json:"geometry"`
DeviceInfoResponse *DeviceInfoResponse `json:"deviceInfo,omitempty"`
Properties map[string]interface{} `json:"properties"`
}
type GeoJSONGeometry struct {
@@ -91,6 +86,3 @@ func (DeviceInfo) Create() (bool, error) {
func (DeviceInfo) Delete() (bool, error) {
return false, nil
}

View File

@@ -3,68 +3,62 @@ package models
import (
"database/sql"
"time"
"github.com/jinzhu/gorm"
)
type Invoice struct {
gorm.Model
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
BaseModel
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
Status string `json:"status"`
Status string `json:"status"`
}
type InvoiceResponse struct {
BaseModel
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BuyerID uint `json:"buyerId"`
BuyerName string `json:"buyerName"`
BuyerAddress string `json:"buyerAddress"`
BuyerEmail string `json:"buyerEmail"`
BuyerPhone string `json:"buyerPhone"`
SellerID uint `json:"sellerId"`
SellerName string `json:"sellerName"`
SellerAddress string `json:"sellerAddress"`
SellerEmail string `json:"sellerEmail"`
SellerPhone string `json:"sellerPhone"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
Discount int64 `json:"discount"`
Tax int64 `json:"tax"`
TermsAndConditions string `json:"termsAndConditions"`
InvoiceName string `json:"invoiceName"`
InvoiceDate time.Time `json:"invoiceDate"`
InvoiceDueDate time.Time `json:"invoiceDueDate"`
ContractID uint `json:"contractId"`
InvoiceItem *[]InvoiceItem `json:"invoiceItem"`
Status string `json:"status"`
Status string `json:"status"`
}
func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
var invoiceResponses []InvoiceResponse
invoiceResponses := []InvoiceResponse{}
for _, invoice := range invoices {
if invoice.InvoiceItem == nil {
emptySlice := make([]InvoiceItem, 0)
@@ -95,7 +89,7 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
InvoiceDate: invoice.InvoiceDate,
InvoiceDueDate: invoice.InvoiceDueDate,
ContractID: invoice.ContractID,
InvoiceItem: invoice.InvoiceItem,
InvoiceItem: invoice.InvoiceItem,
Status: invoice.Status,
}
invoiceResponses = append(invoiceResponses, invoiceResponse)
@@ -103,23 +97,19 @@ func ConvertInvoiceToResponse(invoices []Invoice) []InvoiceResponse {
return invoiceResponses
}
type ListInvoiceResponse struct {
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractId"`
DateCreated time.Time `json:"dateCreated"`
DueDate time.Time `json:"dueDate"`
Amount string `json:"amount"`
Status KeyValue `json:"status"`
Buyer CompanyShortResponse `json:"buyer"`
ContractID int `json:"contractId"`
DateCreated time.Time `json:"dateCreated"`
DueDate time.Time `json:"dueDate"`
Amount string `json:"amount"`
}
type KeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
}
func GetInvoiceStatuses() []Status {
return []Status{
{Key: "Insurance claimed", Value: "insurance_claimed"},

View File

@@ -3,34 +3,28 @@ package models
import (
"database/sql"
"time"
"github.com/jinzhu/gorm"
)
type InvoiceItem struct {
gorm.Model
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
Description string `json:"description"`
Quantity int64 `json:"quantity"`
Unit string `json:"unit"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
InvoiceID uint `json:"invoiceId"`
BaseModel
Description string `json:"description"`
Quantity int64 `json:"quantity"`
Unit string `json:"unit"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
InvoiceID uint `json:"invoiceId"`
}
type InvoiceItemResponse struct {
BaseModel
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
Description string `json:"description"`
Quantity int64 `json:"quantity"`
Unit string `json:"unit"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
InvoiceID uint `json:"invoiceId"`
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
Description string `json:"description"`
Quantity int64 `json:"quantity"`
Unit string `json:"unit"`
PriceCents int64 `json:"priceCents" gorm:"column:price_cents"`
InvoiceID uint `json:"invoiceId"`
}
// ConvertSliceOfInvoiceItemToResponse converts a slice of InvoiceItem models to a slice of InvoiceItemResponse models
@@ -54,9 +48,6 @@ func ConvertInvoiceItemToResponse(items []InvoiceItem) []InvoiceItemResponse {
return itemResponses
}
func (InvoiceItem) Update() (bool, error) {
return false, nil
}
@@ -66,4 +57,3 @@ func (InvoiceItem) Create() (bool, error) {
func (InvoiceItem) Delete() (bool, error) {
return false, nil
}

View File

@@ -1,12 +1,8 @@
package models
import (
"github.com/jinzhu/gorm"
)
type ProductTemplate struct {
gorm.Model
Name string
BaseModel
Name string `json:"name"`
ProductTemplateConfig map[string]interface{} `json:",omitempty" sql:"-"`
Config string `json:"raw_config" gorm:"type:json"`
}

View File

@@ -1,10 +1,9 @@
package models
import "github.com/jinzhu/gorm"
type TextTemplate struct {
gorm.Model
Value string
BaseModel
Name string `json:"name"`
Value string `json:"value"`
}
func (TextTemplate) Update() (bool, error) {

View File

@@ -1,18 +1,7 @@
package models
import (
"database/sql"
"time"
"github.com/jinzhu/gorm"
)
type User struct {
gorm.Model
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt sql.NullTime `json:"deletedAt" gorm:"index"`
BaseModel
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`