From 024da3e546e98cbaeea5f7bc86af12b671996f41 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Thu, 29 Jun 2023 23:05:23 +0200 Subject: ref: Refactor how repository is define To make things easier and reduce the number of package I'll move all repository to one folder, starting with auth and user repository. Also implements all testing on top of the repository interface with a im memory implementation. This will later make mescling unit and integration easier. --- pkg/database/repository/auth.go | 10 ++++++++++ pkg/database/repository/user.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 pkg/database/repository/auth.go create mode 100644 pkg/database/repository/user.go (limited to 'pkg/database/repository') diff --git a/pkg/database/repository/auth.go b/pkg/database/repository/auth.go new file mode 100644 index 0000000..b319495 --- /dev/null +++ b/pkg/database/repository/auth.go @@ -0,0 +1,10 @@ +package repository + +import "context" + +type ( + AuthRepository interface { + GetIDByUsername(ctx context.Context, username string) (uint, error) + GetPassword(ctx context.Context, id uint) ([]byte, error) + } +) diff --git a/pkg/database/repository/user.go b/pkg/database/repository/user.go new file mode 100644 index 0000000..f8bd719 --- /dev/null +++ b/pkg/database/repository/user.go @@ -0,0 +1,35 @@ +package repository + +import "context" + +type ( + User struct { + ID uint + Username string + Name string + IsAdmin bool + Path string + } + + UpdateUser struct { + Username string + Name string + Password string + } + + CreateUser struct { + Username string + Name string + Password []byte + IsAdmin bool + Path string + } + + UserRepository interface { + Get(ctx context.Context, id uint) (*User, error) + List(ctx context.Context) ([]*User, error) + Create(ctx context.Context, createUser *CreateUser) (uint, error) + Update(ctx context.Context, id uint, updateUser *UpdateUser) error + Any(ctx context.Context) (bool, error) + } +) -- cgit v1.2.3