diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-13 15:23:33 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-13 15:23:33 -0600 |
| commit | a4ec3f88aa641afdb3dfc2e03d21e8d4151b7ecb (patch) | |
| tree | 0b6c4d8644c8f5f63601f7f42da2d76fc1d72529 /app | |
| parent | 7cd806499f772314b3a326d77e89441a165d1a57 (diff) | |
refactor: sort fields
Diffstat (limited to 'app')
| -rw-r--r-- | app/db/in_memory_repository.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/app/db/in_memory_repository.go b/app/db/in_memory_repository.go index f778eef..2aa1fed 100644 --- a/app/db/in_memory_repository.go +++ b/app/db/in_memory_repository.go @@ -11,8 +11,8 @@ import ( ) type inMemoryRepository[T domain.Entity] struct { - mu sync.RWMutex items []T + mu sync.RWMutex } func NewRepository[T domain.Entity]() domain.Repository[T] { @@ -42,8 +42,10 @@ func (r *inMemoryRepository[T]) Save(ctx context.Context, item T) error { if item.GetID() == "" { item.SetID(domain.ID(pls.GenerateULID())) } + r.mu.Lock() defer r.mu.Unlock() + r.items = append(r.items, item) sort.Slice(r.items, func(i, j int) bool { return r.items[i].GetID() > r.items[j].GetID() |
