mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package geozone
|
|
|
|
import (
|
|
"github.com/hanzoai/commerce/datastore"
|
|
"github.com/hanzoai/commerce/models/mixin"
|
|
"github.com/hanzoai/commerce/util/json"
|
|
"github.com/hanzoai/orm"
|
|
|
|
. "github.com/hanzoai/commerce/types"
|
|
)
|
|
|
|
func init() { orm.Register[GeoZone]("geozone") }
|
|
|
|
type GeoZone struct {
|
|
mixin.Model[GeoZone]
|
|
|
|
Type string `json:"type"` // "country", "province", "city", "zip"
|
|
CountryCode string `json:"countryCode"`
|
|
ProvinceCode string `json:"provinceCode"`
|
|
City string `json:"city"`
|
|
PostalExpression string `json:"postalExpression"`
|
|
ServiceZoneId string `json:"serviceZoneId"`
|
|
|
|
Metadata Map `json:"metadata,omitempty" datastore:"-" orm:"default:{}"`
|
|
Metadata_ string `json:"-" datastore:",noindex"`
|
|
}
|
|
|
|
func (g *GeoZone) Load(ps []datastore.Property) (err error) {
|
|
if err = datastore.LoadStruct(g, ps); err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(g.Metadata_) > 0 {
|
|
err = json.DecodeBytes([]byte(g.Metadata_), &g.Metadata)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (g *GeoZone) Save() ([]datastore.Property, error) {
|
|
g.Metadata_ = string(json.EncodeBytes(&g.Metadata))
|
|
|
|
return datastore.SaveStruct(g)
|
|
}
|
|
|
|
func New(db *datastore.Datastore) *GeoZone {
|
|
g := new(GeoZone)
|
|
g.Init(db)
|
|
return g
|
|
}
|
|
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("geozone")
|
|
}
|