Skip to content

Commit 1a4498b

Browse files
committed
feat(crud): add basic interfaces for crud package
1 parent e2a3424 commit 1a4498b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/crud/interfaces.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package crud
2+
3+
import (
4+
"context"
5+
"errors"
6+
"time"
7+
)
8+
9+
var (
10+
ErrNotFound = errors.New("entity not found")
11+
ErrInvalidInput = errors.New("invalid input")
12+
)
13+
14+
type Entity interface {
15+
GetID() int64
16+
GetName() string
17+
GetCreatedAt() time.Time
18+
GetUpdatedAt() time.Time
19+
}
20+
21+
type Manager[T Entity] interface {
22+
Create(ctx context.Context, name string) (T, error)
23+
Read(ctx context.Context, id int64) (T, error)
24+
Update(ctx context.Context, id int64, name string) (T, error)
25+
Delete(ctx context.Context, id int64) error
26+
List(ctx context.Context) ([]T, error)
27+
}

0 commit comments

Comments
 (0)