summaryrefslogtreecommitdiff
path: root/app/db/in_memory_repository.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-05-07 10:47:31 -0700
committermo khan <mo@mokhan.ca>2025-05-07 10:47:31 -0700
commitc82468b1b32ad5bfb347fe65cd5dcfb6680795d1 (patch)
tree679b4728fdae2ed296730a49f5100ddcf3c25f98 /app/db/in_memory_repository.go
parentf0fbdab72254d68d0a3a4a49a4a1646f89f0f913 (diff)
refactor: provide context to repository to apply timeout
Diffstat (limited to 'app/db/in_memory_repository.go')
-rw-r--r--app/db/in_memory_repository.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/app/db/in_memory_repository.go b/app/db/in_memory_repository.go
index 5d8628d..ba9ebad 100644
--- a/app/db/in_memory_repository.go
+++ b/app/db/in_memory_repository.go
@@ -1,6 +1,7 @@
package db
import (
+ "context"
"sort"
"github.com/xlgmokha/x/pkg/x"
@@ -18,17 +19,17 @@ func NewRepository[T domain.Entity]() domain.Repository[T] {
}
}
-func (r *inMemoryRepository[T]) All() []T {
+func (r *inMemoryRepository[T]) All(ctx context.Context) []T {
return r.items
}
-func (r *inMemoryRepository[T]) Find(id domain.ID) T {
- return x.Find(r.All(), func(item T) bool {
+func (r *inMemoryRepository[T]) Find(ctx context.Context, id domain.ID) T {
+ return x.Find(r.All(ctx), func(item T) bool {
return item.GetID() == id
})
}
-func (r *inMemoryRepository[T]) Save(item T) error {
+func (r *inMemoryRepository[T]) Save(ctx context.Context, item T) error {
if err := item.Validate(); err != nil {
return err
}