From feafe31716cdbac304dbcd0bce6fe7b205747f0a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 1 May 2026 22:16:11 +0300 Subject: Task 1: Create AuthService and route handleBootstrap/handleLogin through it Introduce service.AuthService interface with Bootstrap and Login methods, a concrete authService implementation, and a MockAuthService for testing. Wire AuthService into api.Server and update cmd/mediaplayer/main.go to use it. This removes direct store access from handleBootstrap and handleLogin, fixing the DIP violation. Sentinel errors (ErrAlreadyBootstrapped, ErrInvalidCredentials) are added to the service package so the API layer can map them to the correct HTTP status codes without leaking DB details. Files created: - internal/service/auth.go Files modified: - internal/service/service.go - internal/service/media.go - internal/service/mock.go - internal/repository/repository.go - internal/repository/mock.go - internal/api/server.go - internal/api/handlers_auth.go - internal/api/handlers_test.go - internal/api/handlers_more_test.go - cmd/mediaplayer/main.go --- internal/service/mock.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/service/mock.go') diff --git a/internal/service/mock.go b/internal/service/mock.go index f174a62..c6c2301 100644 --- a/internal/service/mock.go +++ b/internal/service/mock.go @@ -18,6 +18,7 @@ var ( _ MediaFavoriteService = (*MockMediaService)(nil) _ MediaNoteService = (*MockMediaService)(nil) _ MediaService = (*MockMediaService)(nil) + _ AuthService = (*MockAuthService)(nil) ) // MockMediaService is a fake MediaService for testing. @@ -240,6 +241,25 @@ func (m *MockAdminService) RevokePermission(ctx context.Context, setID, userID i return nil } +// MockAuthService is a fake AuthService for testing. +type MockAuthService struct { + BootstrapFunc func(ctx context.Context, username, password string) (*AuthResult, error) + LoginFunc func(ctx context.Context, username, password string) (*AuthResult, error) +} + +func (m *MockAuthService) Bootstrap(ctx context.Context, username, password string) (*AuthResult, error) { + if m.BootstrapFunc != nil { + return m.BootstrapFunc(ctx, username, password) + } + return nil, nil +} +func (m *MockAuthService) Login(ctx context.Context, username, password string) (*AuthResult, error) { + if m.LoginFunc != nil { + return m.LoginFunc(ctx, username, password) + } + return nil, nil +} + // MockProgressService is a fake ProgressService for testing. type MockProgressService struct { UpdateProgressFunc func(ctx context.Context, sessionID string, userID, mediaID int64, position float64) error -- cgit v1.2.3