lib/app/coordinate-helpers.go

104 lines
3.1 KiB
Go
Raw Normal View History

2021-01-14 06:36:35 +00:00
package app
2021-01-27 23:11:19 +00:00
import (
"encoding/base64"
"html/template"
2021-01-14 06:36:35 +00:00
2021-01-27 23:11:19 +00:00
"code.tnxs.net/taxnexus/lib/api/geo/geo_models"
)
func UnMarshalSwaggerCoordinate(s *geo_models.Coordinate, principal *User) *Coordinate {
taxTypes := []*TaxType{}
for _, itm := range s.TaxTypes {
if itm.ID != "" {
taxTypes = append(taxTypes, UnMarshalTaxType(itm))
}
}
var situs string
if s.IsDistrict {
situs = s.State + " / " + s.County + " / " + s.Place
} else {
situs = s.State + " / " + s.County
}
return &Coordinate{
ID: s.ID,
BusinessTaxTypes: GetBusinessTaxTypes(taxTypes),
CannabisTypes: GetCannabisTaxTypes(taxTypes),
Country: s.Country,
CountryID: s.CountryID,
County: s.County,
CountyID: s.CountyID,
ExciseTaxTypes: GetExciseTaxTypes(taxTypes),
Focus: s.Focus,
FormattedAddress: s.FormattedAddress,
IsDistrict: s.IsDistrict,
Latitude: s.Latitude,
Longitude: s.Longitude,
Map: template.URL(base64.RawStdEncoding.EncodeToString(s.Map)), //nolint:gosec // it definitely is
MerchTaxTypes: GetMerchTaxTypes(taxTypes),
Name: s.Name,
Neighborhood: s.Neighborhood,
Place: s.Place,
Geocode: s.PlaceGeocode,
PlaceID: s.PlaceID,
PostalCode: s.PostalCode,
Ref: s.Ref,
Situs: situs,
State: s.State,
StateID: s.StateID,
Status: s.Status,
Street: s.Street,
StreetNumber: s.StreetNumber,
StreetView: template.URL(base64.RawStdEncoding.EncodeToString(s.StreetView)), //nolint:gosec,lll // it definitely is
TelecomTaxTypes: GetTelecomTaxTypes(taxTypes),
}
}
2021-01-14 06:36:35 +00:00
// MarshalToSwagger encodes a first class object to swagger
func (obj *Coordinate) MarshalToSwagger() *geo_models.Coordinate {
theTaxTypes := []*geo_models.TaxType{}
if obj.TaxTypes != nil {
for _, itm := range obj.TaxTypes {
theTaxTypes = append(theTaxTypes, itm.MarshalToSwagger())
}
}
var taxRate geo_models.TaxRate
if obj.TaxRate != nil {
taxRate = geo_models.TaxRate{
CombinedRate: obj.TaxRate.CombinedRate,
County: obj.TaxRate.County,
CountyID: obj.TaxRate.CountyID,
CountyRate: obj.TaxRate.CountyRate,
Date: obj.TaxRate.Date,
}
}
return &geo_models.Coordinate{
ID: obj.ID,
Country: obj.Country,
CountryID: obj.CountryID,
County: obj.County,
CountyID: obj.CountyID,
Focus: obj.Focus,
FormattedAddress: obj.FormattedAddress,
IsDistrict: obj.IsDistrict,
Latitude: obj.Latitude,
Longitude: obj.Longitude,
2021-01-27 23:11:19 +00:00
// Map: obj.Map,
Name: obj.Name,
Neighborhood: obj.Neighborhood,
Place: obj.Place,
PlaceGeocode: obj.Geocode,
PlaceID: obj.PlaceID,
PostalCode: obj.PostalCode,
Ref: obj.Ref,
State: obj.State,
StateID: obj.StateID,
Status: obj.Status,
Street: obj.Street,
StreetNumber: obj.StreetNumber,
// StreetView: obj.StreetView,
TaxTypes: theTaxTypes,
TaxRate: &taxRate,
2021-01-14 06:36:35 +00:00
}
}