unique ids
This commit is contained in:
@@ -65,6 +65,7 @@ type CartNotification struct {
|
||||
|
||||
type SubscriptionDetails struct {
|
||||
Id string `json:"id"`
|
||||
Version uint16 `json:"version"`
|
||||
OfferingCode string `json:"offeringCode,omitempty"`
|
||||
SigningType string `json:"signingType,omitempty"`
|
||||
Meta json.RawMessage `json:"data,omitempty"`
|
||||
|
||||
@@ -24,8 +24,10 @@ func UpsertSubscriptionDetails(g *CartGrain, m *messages.UpsertSubscriptionDetai
|
||||
}
|
||||
|
||||
id := MustNewCartId().String()
|
||||
|
||||
g.SubscriptionDetails[id] = &SubscriptionDetails{
|
||||
Id: id,
|
||||
Version: 1,
|
||||
OfferingCode: m.OfferingCode,
|
||||
SigningType: m.SigningType,
|
||||
Meta: meta,
|
||||
@@ -38,11 +40,14 @@ func UpsertSubscriptionDetails(g *CartGrain, m *messages.UpsertSubscriptionDetai
|
||||
if !ok {
|
||||
return fmt.Errorf("subscription details not found")
|
||||
}
|
||||
changed := false
|
||||
if m.OfferingCode != "" {
|
||||
existing.OfferingCode = m.OfferingCode
|
||||
changed = true
|
||||
}
|
||||
if m.SigningType != "" {
|
||||
existing.SigningType = m.SigningType
|
||||
changed = true
|
||||
}
|
||||
if m.Data != nil {
|
||||
// Only validate & assign if there is content; empty -> leave as-is.
|
||||
@@ -51,7 +56,11 @@ func UpsertSubscriptionDetails(g *CartGrain, m *messages.UpsertSubscriptionDetai
|
||||
return fmt.Errorf("subscription details invalid json")
|
||||
}
|
||||
existing.Meta = m.Data.Value
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
existing.Version++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user