diff options
Diffstat (limited to 'pkg/db/repository.go')
| -rw-r--r-- | pkg/db/repository.go | 36 |
1 files changed, 1 insertions, 35 deletions
diff --git a/pkg/db/repository.go b/pkg/db/repository.go index 79c7ae3..397eee7 100644 --- a/pkg/db/repository.go +++ b/pkg/db/repository.go @@ -1,41 +1,7 @@ package db -import "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" - -type Entity interface { - GetID() string - SetID(id string) error - Validate() error -} - type Repository[T Entity] interface { All() []T + Find(string) T Save(T) error } - -type inMemoryRepository[T Entity] struct { - items []T -} - -func NewRepository[T Entity]() Repository[T] { - return &inMemoryRepository[T]{ - items: []T{}, - } -} - -func (r *inMemoryRepository[T]) All() []T { - return r.items -} - -func (r *inMemoryRepository[T]) Save(item T) error { - if err := item.Validate(); err != nil { - return err - } - - if item.GetID() == "" { - item.SetID(pls.GenerateULID()) - } - - r.items = append(r.items, item) - return nil -} |
