lens @ 9ba53fea71728ce64342d0d59f4199876e4b6164

feat: Partially fix test

This will totally be fixed later.
  1diff --git a/README.md b/README.md
  2index 9ff9bfd53f0a3058505d4b70861d40120fb3537d..e28adc9e0830f84e9f3c5f70fb14784907de293d 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -15,3 +15,6 @@ * User base root folder 
  6 * Albuns
  7 * Testing. Since I still on initial iteration phases I'm not adding as many
  8   testing as I'd like to. Once I set on most of the design I'll add testing.
  9+* Add testing agains db and memory[^1] in preparation for redis implementation
 10+
 11+[^1]: https://github.com/alicebob/miniredis
 12diff --git a/pkg/components/auth/controller.go b/pkg/components/auth/controller.go
 13index 2f30fb5d1027286fc809f6a683bc42416ed86db3..a33d9b37458ee677835aff5a26543fe84a3ac6c6 100644
 14--- a/pkg/components/auth/controller.go
 15+++ b/pkg/components/auth/controller.go
 16@@ -67,7 +67,7 @@ 	if err != nil {
 17 		return err
 18 	}
 19 
 20-	err = c.userRepository.Create(ctx, &user.CreateUser{
 21+	_, err = c.userRepository.Create(ctx, &user.CreateUser{
 22 		Username: string(username),
 23 		Password: hash,
 24 		Path:     string(path),
 25diff --git a/pkg/components/auth/controller_test.go b/pkg/components/auth/controller_test.go
 26index 6b4e3cd03ecdb792c56141c5e68ba1a53b343815..50bf69b08d8dea4e8d4d5e3dbf4e706701984139 100644
 27--- a/pkg/components/auth/controller_test.go
 28+++ b/pkg/components/auth/controller_test.go
 29@@ -17,7 +17,7 @@
 30 type (
 31 	scene struct {
 32 		ctx            context.Context
 33-		mockRepository *MockUserRepository
 34+		mockRepository *MockAuthRepository
 35 		controller     Controller
 36 	}
 37 
 38@@ -27,6 +27,12 @@ 		username string
 39 		password []byte
 40 	}
 41 
 42+	MockAuthRepository struct {
 43+		index uint
 44+		users []*mockUser
 45+		err   error
 46+	}
 47+
 48 	MockUserRepository struct {
 49 		index uint
 50 		users []*mockUser
 51@@ -35,16 +41,17 @@ 	}
 52 )
 53 
 54 var (
 55-	_   Repository = &MockUserRepository{}
 56+	_   Repository = &MockAuthRepository{}
 57 	key            = []byte("6368616e676520746869732070617373")
 58 )
 59 
 60 func setUp() *scene {
 61+	mockAuthRepository := &MockAuthRepository{}
 62 	mockUserRepository := &MockUserRepository{}
 63 	return &scene{
 64 		ctx:            context.Background(),
 65-		mockRepository: mockUserRepository,
 66-		controller:     *NewController(mockUserRepository, nil, key),
 67+		mockRepository: mockAuthRepository,
 68+		controller:     *NewController(mockAuthRepository, mockUserRepository, key),
 69 	}
 70 }
 71 
 72@@ -93,11 +100,11 @@ 		Username: m.username,
 73 	}
 74 }
 75 
 76-func (m *MockUserRepository) GetLastId() uint {
 77+func (m *MockAuthRepository) GetLastId() uint {
 78 	return m.index
 79 }
 80 
 81-func (m *MockUserRepository) List(ctx context.Context) ([]*user.User, error) {
 82+func (m *MockAuthRepository) List(ctx context.Context) ([]*user.User, error) {
 83 	if m.err != nil {
 84 		return nil, m.err
 85 	}
 86@@ -105,7 +112,7 @@
 87 	return lo.Map(m.users, toUser), nil
 88 }
 89 
 90-func (m *MockUserRepository) Get(ctx context.Context, id uint) (*user.User, error) {
 91+func (m *MockAuthRepository) Get(ctx context.Context, id uint) (*user.User, error) {
 92 	if m.err != nil {
 93 		return nil, m.err
 94 	}
 95@@ -118,7 +125,7 @@ 	}
 96 	return nil, errors.New("Item not found")
 97 }
 98 
 99-func (m *MockUserRepository) GetIDByUsername(ctx context.Context, username string) (uint, error) {
100+func (m *MockAuthRepository) GetIDByUsername(ctx context.Context, username string) (uint, error) {
101 	if m.err != nil {
102 		return 0, m.err
103 	}
104@@ -131,7 +138,7 @@ 	}
105 	return 0, errors.New("Item not found")
106 }
107 
108-func (m *MockUserRepository) GetPassword(ctx context.Context, id uint) ([]byte, error) {
109+func (m *MockAuthRepository) GetPassword(ctx context.Context, id uint) ([]byte, error) {
110 	if m.err != nil {
111 		return nil, m.err
112 	}
113@@ -144,7 +151,7 @@ 	}
114 	return nil, errors.New("Item not found")
115 }
116 
117-func (m *MockUserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
118+func (m *MockAuthRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
119 	if m.err != nil {
120 		return 0, m.err
121 	}
122@@ -160,7 +167,7 @@
123 	return m.index, nil
124 }
125 
126-func (m *MockUserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
127+func (m *MockAuthRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
128 	if m.err != nil {
129 		return m.err
130 	}
131@@ -177,7 +184,7 @@ func remove[T any](slice []T, s int) []T {
132 	return append(slice[:s], slice[s+1:]...)
133 }
134 
135-func (r *MockUserRepository) Delete(ctx context.Context, id uint) error {
136+func (r *MockAuthRepository) Delete(ctx context.Context, id uint) error {
137 	if r.err != nil {
138 		return r.err
139 	}
140@@ -189,3 +196,19 @@ 		}
141 	}
142 	return nil
143 }
144+
145+func (m *MockUserRepository) List(ctx context.Context) ([]*user.User, error) {
146+	panic("not implemented") // TODO: Implement
147+}
148+
149+func (m *MockUserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
150+	panic("not implemented") // TODO: Implement
151+}
152+
153+func (m *MockUserRepository) Update(ctx context.Context, id uint, updateUser *user.UpdateUser) error {
154+	panic("not implemented") // TODO: Implement
155+}
156+
157+func (m *MockUserRepository) Any(ctx context.Context) (bool, error) {
158+	panic("not implemented") // TODO: Implement
159+}
160diff --git a/pkg/components/user/model.go b/pkg/components/user/model.go
161index ce1b3a5986e2782ab36ae08dd05f02862f2d01a4..0ff6d0ab9a5b77cbfef5fab9f5b717d6e066119e 100644
162--- a/pkg/components/user/model.go
163+++ b/pkg/components/user/model.go
164@@ -27,7 +27,7 @@ 	}
165 
166 	Repository interface {
167 		List(ctx context.Context) ([]*User, error)
168-		Create(ctx context.Context, createUser *CreateUser) error
169+		Create(ctx context.Context, createUser *CreateUser) (uint, error)
170 		Update(ctx context.Context, id uint, updateUser *UpdateUser) error
171 		Any(ctx context.Context) (bool, error)
172 	}
173diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go
174index a02b67b669b46c634051daf69000a5a9044a0336..a0884f4f6e1db95c98c490fbb6ca6e10ac214de4 100644
175--- a/pkg/database/sql/user.go
176+++ b/pkg/database/sql/user.go
177@@ -137,7 +137,7 @@
178 	return userPassword.Password, nil
179 }
180 
181-func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) error {
182+func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
183 	user := &User{
184 		Username: createUser.Username,
185 		Name:     createUser.Name,
186@@ -148,10 +148,10 @@ 	result := self.db.
187 		WithContext(ctx).
188 		Create(user)
189 	if result.Error != nil {
190-		return result.Error
191+		return 0, result.Error
192 	}
193 
194-	return nil
195+	return user.Model.ID, nil
196 }
197 
198 func (self *UserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
199diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
200index 473ce032516e298768da908b7e64f84e4f705bce..f0d89addaf626140630730ce1d27ee65780a0c1f 100644
201--- a/pkg/database/sql/user_test.go
202+++ b/pkg/database/sql/user_test.go
203@@ -48,7 +48,7 @@ 	defer tearDown()
204 
205 	repository := NewUserRepository(db)
206 
207-	err := repository.Create(context.Background(), &user.CreateUser{
208+	id, err := repository.Create(context.Background(), &user.CreateUser{
209 		Username: "new_username",
210 		Name:     "new_name",
211 	})
212@@ -56,12 +56,12 @@ 	if err != nil {
213 		t.Fatalf("Error creating: %s", err.Error())
214 	}
215 
216-	got, err := repository.Get(context.Background(), 1)
217+	got, err := repository.Get(context.Background(), id)
218 	if err != nil {
219 		t.Fatalf("Error getting: %s", err.Error())
220 	}
221 	want := &user.User{
222-		ID:       1,
223+		ID:       id,
224 		Username: "new_username",
225 		Name:     "new_name",
226 	}
227@@ -78,7 +78,7 @@ 	defer tearDown()
228 
229 	repository := NewUserRepository(db)
230 
231-	err := repository.Create(context.Background(), &user.CreateUser{
232+	id, err := repository.Create(context.Background(), &user.CreateUser{
233 		Username: "username",
234 		Name:     "name",
235 	})
236@@ -86,7 +86,7 @@ 	if err != nil {
237 		t.Fatalf("Error creating user: %s", err.Error())
238 	}
239 
240-	err = repository.Update(context.Background(), 1, &user.UpdateUser{
241+	err = repository.Update(context.Background(), id, &user.UpdateUser{
242 		Username: "new_username",
243 		Name:     "new_name",
244 	})
245@@ -99,7 +99,7 @@ 	if err != nil {
246 		t.Fatalf("Error getting user: %s", err.Error())
247 	}
248 	want := &user.User{
249-		ID:       1,
250+		ID:       id,
251 		Username: "new_username",
252 		Name:     "new_name",
253 	}
254diff --git a/pkg/ext/middleware.go b/pkg/ext/middleware.go
255index 649272e6714bfd5f0f85355c4f6b439eb1e6620f..bc23b9087ca3fab75190d884ec56b4d6472297f0 100644
256--- a/pkg/ext/middleware.go
257+++ b/pkg/ext/middleware.go
258@@ -4,9 +4,10 @@ import (
259 	"encoding/base64"
260 	"time"
261 
262-	"git.sr.ht/~gabrielgio/img/pkg/components/user"
263 	"github.com/sirupsen/logrus"
264 	"github.com/valyala/fasthttp"
265+
266+	"git.sr.ht/~gabrielgio/img/pkg/components/user"
267 )
268 
269 func HTML(next fasthttp.RequestHandler) fasthttp.RequestHandler {
270diff --git a/pkg/worker/file_scanner.go b/pkg/worker/file_scanner.go
271index fda869c156fa47a69f6166faebb6f17a3df20f2c..a51f60bbc11afea841fce4787e37e11b54992812 100644
272--- a/pkg/worker/file_scanner.go
273+++ b/pkg/worker/file_scanner.go
274@@ -77,10 +77,6 @@ 	if exists {
275 		return nil
276 	}
277 
278-	if errResp != nil {
279-		return errResp
280-	}
281-
282 	return f.repository.Create(ctx, &media.CreateMedia{
283 		Name:     name,
284 		Path:     path,