Skip to content

Commit d1e8701

Browse files
committed
fix(order): avoid processing cancelled orders prior to checkout when ignoring checkedout
1 parent 828156a commit d1e8701

File tree

1 file changed

+19
-1
lines changed
  • internal/infrastructure/datasource/filesystem

1 file changed

+19
-1
lines changed

internal/infrastructure/datasource/filesystem/order.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func (o *orderRepository) Find(id order.ID) (order.Order, error) {
2828
func (o *orderRepository) Latest(optionAppliers ...options.Applier[order.ListerOption]) iter.Seq2[order.Order, error] {
2929
option := options.Create(optionAppliers...)
3030

31+
var canceledListBuffer []order.Order
32+
3133
return func(yield func(order.Order, error) bool) {
3234
for _, o := range o.fs.data.orders {
3335
if option.Since != nil && o.CreatedAt().Before(*option.Since) {
@@ -37,12 +39,28 @@ func (o *orderRepository) Latest(optionAppliers ...options.Applier[order.ListerO
3739
continue
3840
}
3941
if option.IgnoreCheckedOut && o.Status == order.StatusCheckedOut {
40-
break
42+
return
43+
}
44+
if o.Status == order.StatusCanceled {
45+
canceledListBuffer = append(canceledListBuffer, o)
46+
continue
4147
}
48+
for _, o := range canceledListBuffer {
49+
if !yield(o, nil) {
50+
return
51+
}
52+
}
53+
canceledListBuffer = nil
54+
if !yield(o, nil) {
55+
return
56+
}
57+
}
58+
for _, o := range canceledListBuffer {
4259
if !yield(o, nil) {
4360
return
4461
}
4562
}
63+
canceledListBuffer = nil
4664
}
4765
}
4866

0 commit comments

Comments
 (0)