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
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package servicezone
|
|
|
|
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[ServiceZone]("servicezone") }
|
|
|
|
type ServiceZone struct {
|
|
mixin.Model[ServiceZone]
|
|
|
|
Name string `json:"name"`
|
|
FulfillmentSetId string `json:"fulfillmentSetId"`
|
|
|
|
Metadata Map `json:"metadata,omitempty" datastore:"-" orm:"default:{}"`
|
|
Metadata_ string `json:"-" datastore:",noindex"`
|
|
}
|
|
|
|
func (s *ServiceZone) Load(ps []datastore.Property) (err error) {
|
|
if err = datastore.LoadStruct(s, ps); err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(s.Metadata_) > 0 {
|
|
err = json.DecodeBytes([]byte(s.Metadata_), &s.Metadata)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (s *ServiceZone) Save() ([]datastore.Property, error) {
|
|
s.Metadata_ = string(json.EncodeBytes(&s.Metadata))
|
|
|
|
return datastore.SaveStruct(s)
|
|
}
|
|
|
|
func New(db *datastore.Datastore) *ServiceZone {
|
|
s := new(ServiceZone)
|
|
s.Init(db)
|
|
return s
|
|
}
|
|
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("servicezone")
|
|
}
|