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
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package pricelist
|
|
|
|
import (
|
|
"time"
|
|
|
|
"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[PriceList]("pricelist") }
|
|
|
|
type PriceList struct {
|
|
mixin.Model[PriceList]
|
|
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status" orm:"default:draft"`
|
|
Type string `json:"type"`
|
|
StartsAt *time.Time `json:"startsAt,omitempty"`
|
|
EndsAt *time.Time `json:"endsAt,omitempty"`
|
|
|
|
Metadata Map `json:"metadata,omitempty" datastore:"-"`
|
|
Metadata_ string `json:"-" datastore:",noindex"`
|
|
}
|
|
|
|
func (p *PriceList) Load(ps []datastore.Property) (err error) {
|
|
if err = datastore.LoadStruct(p, ps); err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(p.Metadata_) > 0 {
|
|
err = json.DecodeBytes([]byte(p.Metadata_), &p.Metadata)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (p *PriceList) Save() ([]datastore.Property, error) {
|
|
p.Metadata_ = string(json.EncodeBytes(&p.Metadata))
|
|
|
|
return datastore.SaveStruct(p)
|
|
}
|
|
|
|
func New(db *datastore.Datastore) *PriceList {
|
|
t := new(PriceList)
|
|
t.Init(db)
|
|
return t
|
|
}
|
|
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("pricelist")
|
|
}
|