2024-09-18 07:40:50 +02:00
|
|
|
package main
|
2024-08-20 08:34:11 +02:00
|
|
|
|
2024-08-22 07:18:50 +02:00
|
|
|
import (
|
2024-09-11 07:33:22 +02:00
|
|
|
"slices"
|
2024-08-22 07:18:50 +02:00
|
|
|
"time"
|
2024-09-18 07:55:14 +02:00
|
|
|
|
|
|
|
"go-mod.ewintr.nl/planner/sync/item"
|
2024-08-22 07:18:50 +02:00
|
|
|
)
|
2024-08-16 14:25:06 +02:00
|
|
|
|
|
|
|
type Memory struct {
|
2024-09-18 07:55:14 +02:00
|
|
|
items map[string]item.Item
|
2024-08-16 14:25:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemory() *Memory {
|
|
|
|
return &Memory{
|
2024-09-18 07:55:14 +02:00
|
|
|
items: make(map[string]item.Item),
|
2024-08-16 14:25:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-18 07:55:14 +02:00
|
|
|
func (m *Memory) Update(item item.Item) error {
|
2024-08-28 07:21:02 +02:00
|
|
|
m.items[item.ID] = item
|
2024-08-23 10:52:17 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-18 07:55:14 +02:00
|
|
|
func (m *Memory) Updated(kinds []item.Kind, timestamp time.Time) ([]item.Item, error) {
|
|
|
|
result := make([]item.Item, 0)
|
2024-08-22 07:18:50 +02:00
|
|
|
|
|
|
|
for _, i := range m.items {
|
2024-09-11 07:33:22 +02:00
|
|
|
timeOK := timestamp.IsZero() || i.Updated.Equal(timestamp) || i.Updated.After(timestamp)
|
|
|
|
kindOK := len(kinds) == 0 || slices.Contains(kinds, i.Kind)
|
|
|
|
if timeOK && kindOK {
|
2024-08-22 07:18:50 +02:00
|
|
|
result = append(result, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|