change alot of id values
All checks were successful
Build and Publish / Metadata (push) Successful in 15s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m11s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m7s

This commit is contained in:
matst80
2025-10-14 21:24:50 +02:00
parent 4bec3f8cc0
commit 1565cfdaba
14 changed files with 426 additions and 332 deletions

View File

@@ -8,7 +8,6 @@ import (
"time"
messages "git.tornberg.me/go-cart-actor/pkg/messages"
"git.tornberg.me/go-cart-actor/pkg/voucher"
)
// Legacy padded [16]byte CartId and its helper methods removed.
@@ -31,9 +30,9 @@ type ItemMeta struct {
}
type CartItem struct {
Id int `json:"id"`
ItemId int `json:"itemId,omitempty"`
ParentId int `json:"parentId,omitempty"`
Id uint32 `json:"id"`
ItemId uint32 `json:"itemId,omitempty"`
ParentId uint32 `json:"parentId,omitempty"`
Sku string `json:"sku"`
Price Price `json:"price"`
@@ -53,10 +52,10 @@ type CartItem struct {
}
type CartDelivery struct {
Id int `json:"id"`
Id uint32 `json:"id"`
Provider string `json:"provider"`
Price Price `json:"price"`
Items []int `json:"items"`
Items []uint32 `json:"items"`
PickupPoint *messages.PickupPoint `json:"pickupPoint,omitempty"`
}
@@ -69,8 +68,9 @@ type CartNotification struct {
type CartGrain struct {
mu sync.RWMutex
lastItemId int
lastDeliveryId int
lastItemId uint32
lastDeliveryId uint32
lastVoucherId uint32
lastAccess time.Time
lastChange time.Time // unix seconds of last successful mutation (replay sets from event ts)
userId string
@@ -83,10 +83,17 @@ type CartGrain struct {
PaymentInProgress bool `json:"paymentInProgress"`
OrderReference string `json:"orderReference,omitempty"`
PaymentStatus string `json:"paymentStatus,omitempty"`
Vouchers []*voucher.Voucher `json:"vouchers,omitempty"`
Vouchers []*Voucher `json:"vouchers,omitempty"`
Notifications []CartNotification `json:"cartNotification,omitempty"`
}
type Voucher struct {
Code string `json:"code"`
Rules []*messages.VoucherRule `json:"rules"`
Id uint32 `json:"id"`
Value Price `json:"value"`
}
func (c *CartGrain) GetId() uint64 {
return uint64(c.Id)
}
@@ -124,8 +131,8 @@ func (c *CartGrain) GetState() ([]byte, error) {
return json.Marshal(c)
}
func (c *CartGrain) ItemsWithDelivery() []int {
ret := make([]int, 0, len(c.Items))
func (c *CartGrain) ItemsWithDelivery() []uint32 {
ret := make([]uint32, 0, len(c.Items))
for _, item := range c.Items {
for _, delivery := range c.Deliveries {
for _, id := range delivery.Items {
@@ -138,8 +145,8 @@ func (c *CartGrain) ItemsWithDelivery() []int {
return ret
}
func (c *CartGrain) ItemsWithoutDelivery() []int {
ret := make([]int, 0, len(c.Items))
func (c *CartGrain) ItemsWithoutDelivery() []uint32 {
ret := make([]uint32, 0, len(c.Items))
hasDelivery := c.ItemsWithDelivery()
for _, item := range c.Items {
found := slices.Contains(hasDelivery, item.Id)