Merge branch 'feature/pubsub' of git-ssh.tornberg.me:mats/go-cart-actor into feature/pubsub

This commit is contained in:
matst80
2025-11-27 12:14:11 +01:00
6 changed files with 78 additions and 20 deletions

View File

@@ -38,16 +38,24 @@ func (c *CartMutationContext) AddItem(g *CartGrain, m *messages.AddItem) error {
if !sameStore {
continue
}
existing.Quantity += int(m.Quantity)
if m.ReservationEndTime != nil {
t := m.ReservationEndTime.AsTime()
if existing.ReservationEndTime == nil || existing.ReservationEndTime.Before(m.ReservationEndTime.AsTime()) {
existing.ReservationEndTime = &t
existing.Quantity += int(m.Quantity)
} else {
existing.ReservationEndTime = &t
}
} else {
existing.Quantity += int(m.Quantity)
}
existing.Stock = uint16(m.Stock)
// If existing had nil store but new has one, adopt it.
if existing.StoreId == nil && m.StoreId != nil {
existing.StoreId = m.StoreId
}
if m.ReservationEndTime != nil {
t := m.ReservationEndTime.AsTime()
existing.ReservationEndTime = &t
}
return nil
}