123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package relation
- import (
- "github.com/gshopify/service-wrapper/model"
- "github.com/mailru/dbr"
- "gshopper.com/gshopify/shop/graphql/generated"
- "strings"
- )
- type Location struct {
- Id string `db:"id"`
- Name string `db:"name"`
- Status string `db:"status"`
- Legacy bool `db:"legacy"`
- Address1 dbr.NullString `db:"address_1"`
- Address2 dbr.NullString `db:"address_2"`
- City dbr.NullString `db:"city"`
- Country dbr.NullString `db:"country"`
- CountryCode dbr.NullString `db:"country_code"`
- Latitude dbr.NullFloat64 `db:"latitude"`
- Longitude dbr.NullFloat64 `db:"longitude"`
- Phone dbr.NullString `db:"phone"`
- Province dbr.NullString `db:"province"`
- ProvinceCode dbr.NullString `db:"province_code"`
- Zip dbr.NullString `db:"zip"`
- LocalizedCountryName dbr.NullString `db:"localized_country_name"`
- LocalizedProvinceName dbr.NullString `db:"localized_province_name"`
- }
- func (l *Location) As() *generated.Location {
- var (
- fmtProvince = strings.Builder{}
- loc = &generated.Location{
- Address: &generated.LocationAddress{},
- ID: model.NewId(model.GidLocation, l.Id),
- Name: l.Name,
- }
- )
- if l.Address1.Valid {
- loc.Address.Address1 = &l.Address1.String
- loc.Address.Formatted = append(loc.Address.Formatted, l.Address1.String)
- }
- if l.Address2.Valid {
- loc.Address.Address2 = &l.Address2.String
- loc.Address.Formatted = append(loc.Address.Formatted, l.Address2.String)
- }
- if l.City.Valid {
- loc.Address.City = &l.City.String
- loc.Address.Formatted = append(loc.Address.Formatted, l.City.String)
- }
- if l.ProvinceCode.Valid {
- loc.Address.ProvinceCode = &l.ProvinceCode.String
- fmtProvince.WriteString(l.ProvinceCode.String)
- }
- if l.Province.Valid {
- loc.Address.Province = &l.Province.String
- if fmtProvince.Len() == 0 {
- fmtProvince.WriteString(l.Province.String)
- }
- }
- if l.Zip.Valid {
- loc.Address.Zip = &l.Zip.String
- if fmtProvince.Len() == 0 {
- fmtProvince.WriteString(" ")
- }
- fmtProvince.WriteString(l.Zip.String)
- }
- if fmtProvince.Len() > 0 {
- loc.Address.Formatted = append(loc.Address.Formatted, fmtProvince.String())
- }
- if l.Country.Valid {
- loc.Address.Country = &l.Country.String
- loc.Address.Formatted = append(loc.Address.Formatted, l.Country.String)
- }
- if code := model.CountryCode(l.CountryCode.String); code.IsValid() {
- s := code.String()
- loc.Address.CountryCode = &s
- }
- if l.Latitude.Valid {
- loc.Address.Latitude = &l.Latitude.Float64
- }
- if l.Longitude.Valid {
- loc.Address.Longitude = &l.Longitude.Float64
- }
- if l.Phone.Valid {
- loc.Address.Phone = &l.Phone.String
- }
- return loc
- }
|