diff --git a/api/apierror/common.go b/api/apierror/common.go index 2ccc7e7..c20b8fe 100644 --- a/api/apierror/common.go +++ b/api/apierror/common.go @@ -7,8 +7,8 @@ import ( "net/http" "strings" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/pkg/render" - "github.com/Karaoke-Manager/karman/service" ) // ProblemTypeDomain is the base domain for all custom problem types. @@ -72,7 +72,7 @@ func JSONUnmarshalError(err *json.UnmarshalTypeError) *ProblemDetails { // This function maps known errors to their responses. func ServiceError(err error) *ProblemDetails { switch { - case errors.Is(err, service.ErrNotFound): + case errors.Is(err, core.ErrNotFound): return ErrNotFound default: return ErrInternalServerError diff --git a/api/handler.go b/api/handler.go index d5075ee..8199018 100644 --- a/api/handler.go +++ b/api/handler.go @@ -11,11 +11,11 @@ import ( "github.com/Karaoke-Manager/karman/api/apierror" "github.com/Karaoke-Manager/karman/api/middleware" v1 "github.com/Karaoke-Manager/karman/api/v1" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" + "github.com/Karaoke-Manager/karman/core/upload" "github.com/Karaoke-Manager/karman/pkg/render" _ "github.com/Karaoke-Manager/karman/pkg/render/json" // JSON encoding for responses - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" - "github.com/Karaoke-Manager/karman/service/upload" ) // HealthChecker is an interface that can provide information about the system health. diff --git a/api/v1/dav/handler.go b/api/v1/dav/handler.go index 2e578a8..1ac9943 100644 --- a/api/v1/dav/handler.go +++ b/api/v1/dav/handler.go @@ -8,8 +8,8 @@ import ( "golang.org/x/net/webdav" "github.com/Karaoke-Manager/karman/api/v1/dav/internal" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" ) func init() { diff --git a/api/v1/dav/internal/filesystem.go b/api/v1/dav/internal/filesystem.go index 5384030..ffcbe0e 100644 --- a/api/v1/dav/internal/filesystem.go +++ b/api/v1/dav/internal/filesystem.go @@ -11,10 +11,10 @@ import ( "github.com/google/uuid" "golang.org/x/net/webdav" + "github.com/Karaoke-Manager/karman/core" + "github.com/Karaoke-Manager/karman/core/media" + songsvc "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/model" - "github.com/Karaoke-Manager/karman/service" - "github.com/Karaoke-Manager/karman/service/media" - songsvc "github.com/Karaoke-Manager/karman/service/song" ) // flatFS implements a [webdav.FileSystem] that serves songs in a flat hierarchy: @@ -76,7 +76,7 @@ func (s *flatFS) find(ctx context.Context, name string) (node, error) { } song, err := s.songRepo.GetSong(ctx, id) - if errors.Is(err, service.ErrNotFound) { + if errors.Is(err, core.ErrNotFound) { return nil, fs.ErrNotExist } else if err != nil { return nil, err diff --git a/api/v1/dav/internal/mediafile.go b/api/v1/dav/internal/mediafile.go index bee7115..1ee9452 100644 --- a/api/v1/dav/internal/mediafile.go +++ b/api/v1/dav/internal/mediafile.go @@ -9,11 +9,11 @@ import ( "golang.org/x/net/webdav" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" "github.com/Karaoke-Manager/karman/pkg/streamio" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" ) // mediaNode is a node representing a media file. diff --git a/api/v1/dav/internal/root.go b/api/v1/dav/internal/root.go index 05de957..f4ad356 100644 --- a/api/v1/dav/internal/root.go +++ b/api/v1/dav/internal/root.go @@ -10,8 +10,8 @@ import ( "golang.org/x/net/webdav" - "github.com/Karaoke-Manager/karman/service/media" - songsvc "github.com/Karaoke-Manager/karman/service/song" + "github.com/Karaoke-Manager/karman/core/media" + songsvc "github.com/Karaoke-Manager/karman/core/song" ) // rootNode represents the root directory of a flatFS. diff --git a/api/v1/dav/internal/songdir.go b/api/v1/dav/internal/songdir.go index 13c470f..4dea4ea 100644 --- a/api/v1/dav/internal/songdir.go +++ b/api/v1/dav/internal/songdir.go @@ -10,9 +10,9 @@ import ( "golang.org/x/net/webdav" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/model" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" ) // songNode represents the directory for a song. diff --git a/api/v1/dav/internal/txtfile.go b/api/v1/dav/internal/txtfile.go index 8342b3b..52e6b9e 100644 --- a/api/v1/dav/internal/txtfile.go +++ b/api/v1/dav/internal/txtfile.go @@ -11,9 +11,9 @@ import ( "codello.dev/ultrastar/txt" "golang.org/x/net/webdav" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/model" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" ) // txtNode represents the TXT file for a song. diff --git a/api/v1/handler.go b/api/v1/handler.go index 5e9cd3b..7ba8dd6 100644 --- a/api/v1/handler.go +++ b/api/v1/handler.go @@ -9,9 +9,9 @@ import ( "github.com/Karaoke-Manager/karman/api/v1/dav" "github.com/Karaoke-Manager/karman/api/v1/songs" "github.com/Karaoke-Manager/karman/api/v1/uploads" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" - "github.com/Karaoke-Manager/karman/service/upload" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" + "github.com/Karaoke-Manager/karman/core/upload" ) // Handler implements the /v1 API namespace. diff --git a/api/v1/songs/handler.go b/api/v1/songs/handler.go index c886980..72070ad 100644 --- a/api/v1/songs/handler.go +++ b/api/v1/songs/handler.go @@ -7,9 +7,9 @@ import ( "github.com/go-chi/chi/v5" "github.com/Karaoke-Manager/karman/api/middleware" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/pkg/render" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" ) // Handler implements the /v1/songs endpoints. diff --git a/api/v1/songs/handler_test.go b/api/v1/songs/handler_test.go index a68d521..054c264 100644 --- a/api/v1/songs/handler_test.go +++ b/api/v1/songs/handler_test.go @@ -14,10 +14,10 @@ import ( "github.com/jackc/pgxutil" "github.com/Karaoke-Manager/karman/api/apierror" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" "github.com/Karaoke-Manager/karman/pkg/nolog" _ "github.com/Karaoke-Manager/karman/pkg/render/json" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" "github.com/Karaoke-Manager/karman/test" ) diff --git a/api/v1/songs/media_test.go b/api/v1/songs/media_test.go index f48a550..aad356a 100644 --- a/api/v1/songs/media_test.go +++ b/api/v1/songs/media_test.go @@ -17,9 +17,9 @@ import ( "github.com/Karaoke-Manager/karman/api/apierror" "github.com/Karaoke-Manager/karman/api/schema" + "github.com/Karaoke-Manager/karman/core/media" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" - "github.com/Karaoke-Manager/karman/service/media" "github.com/Karaoke-Manager/karman/test" testdata "github.com/Karaoke-Manager/karman/test/data" ) diff --git a/api/v1/uploads/file_crud.go b/api/v1/uploads/file_crud.go index b80e2ba..ba8484c 100644 --- a/api/v1/uploads/file_crud.go +++ b/api/v1/uploads/file_crud.go @@ -10,8 +10,8 @@ import ( "github.com/Karaoke-Manager/karman/api/apierror" "github.com/Karaoke-Manager/karman/api/schema" + "github.com/Karaoke-Manager/karman/core/upload" "github.com/Karaoke-Manager/karman/pkg/render" - "github.com/Karaoke-Manager/karman/service/upload" ) // PutFile implements the PUT /v1/uploads/{uuid}/files/* endpoint. diff --git a/api/v1/uploads/handler.go b/api/v1/uploads/handler.go index c94a2fb..9f16e21 100644 --- a/api/v1/uploads/handler.go +++ b/api/v1/uploads/handler.go @@ -7,9 +7,9 @@ import ( "github.com/go-chi/chi/v5" "github.com/Karaoke-Manager/karman/api/middleware" + "github.com/Karaoke-Manager/karman/core/upload" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/render" - "github.com/Karaoke-Manager/karman/service/upload" ) // Handler implements the /v1/uploads endpoints. diff --git a/api/v1/uploads/handler_test.go b/api/v1/uploads/handler_test.go index ecfa418..1391523 100644 --- a/api/v1/uploads/handler_test.go +++ b/api/v1/uploads/handler_test.go @@ -17,9 +17,9 @@ import ( "github.com/jackc/pgxutil" "github.com/Karaoke-Manager/karman/api/apierror" + "github.com/Karaoke-Manager/karman/core/upload" "github.com/Karaoke-Manager/karman/pkg/nolog" _ "github.com/Karaoke-Manager/karman/pkg/render/json" - "github.com/Karaoke-Manager/karman/service/upload" "github.com/Karaoke-Manager/karman/test" ) diff --git a/cmd/karman/server.go b/cmd/karman/server.go index 932a2a7..61b8d19 100644 --- a/cmd/karman/server.go +++ b/cmd/karman/server.go @@ -23,10 +23,10 @@ import ( "github.com/Karaoke-Manager/karman/api" "github.com/Karaoke-Manager/karman/cmd/karman/internal" + "github.com/Karaoke-Manager/karman/core/media" + "github.com/Karaoke-Manager/karman/core/song" + "github.com/Karaoke-Manager/karman/core/upload" "github.com/Karaoke-Manager/karman/migrations" - "github.com/Karaoke-Manager/karman/service/media" - "github.com/Karaoke-Manager/karman/service/song" - "github.com/Karaoke-Manager/karman/service/upload" ) // serverCmd implements the "server" command. diff --git a/service/doc.go b/core/doc.go similarity index 69% rename from service/doc.go rename to core/doc.go index d9643f4..aa2e6ae 100644 --- a/service/doc.go +++ b/core/doc.go @@ -1,4 +1,4 @@ -// Package service is the root package for the domain logic of Karman. +// Package core is the root package for the domain logic of Karman. // This package itself contains only some shared utilities used by different service implementations. // Sub-packages of this package contain the actual service definitions and implementations. -package service +package core diff --git a/service/errors.go b/core/errors.go similarity index 89% rename from service/errors.go rename to core/errors.go index 74283d6..ea15d43 100644 --- a/service/errors.go +++ b/core/errors.go @@ -1,4 +1,4 @@ -package service +package core import ( "errors" diff --git a/service/dbutil/errors.go b/core/internal/dbutil/errors.go similarity index 66% rename from service/dbutil/errors.go rename to core/internal/dbutil/errors.go index 7be1643..616e857 100644 --- a/service/dbutil/errors.go +++ b/core/internal/dbutil/errors.go @@ -5,12 +5,12 @@ import ( "github.com/jackc/pgx/v5" - "github.com/Karaoke-Manager/karman/service" + "github.com/Karaoke-Manager/karman/core" ) func Error(err error) error { if errors.Is(err, pgx.ErrNoRows) { - return service.ErrNotFound + return core.ErrNotFound } return err } diff --git a/service/dbutil/notes.go b/core/internal/dbutil/notes.go similarity index 100% rename from service/dbutil/notes.go rename to core/internal/dbutil/notes.go diff --git a/service/dbutil/zero.go b/core/internal/dbutil/zero.go similarity index 100% rename from service/dbutil/zero.go rename to core/internal/dbutil/zero.go diff --git a/service/dbutil/zero_test.go b/core/internal/dbutil/zero_test.go similarity index 100% rename from service/dbutil/zero_test.go rename to core/internal/dbutil/zero_test.go diff --git a/service/media/fakerepo.go b/core/media/fakerepo.go similarity index 92% rename from service/media/fakerepo.go rename to core/media/fakerepo.go index bee6d42..f53c7eb 100644 --- a/service/media/fakerepo.go +++ b/core/media/fakerepo.go @@ -6,8 +6,8 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" - svc "github.com/Karaoke-Manager/karman/service" ) // fakeRepo is a Repository implementation backed by an in-memory map. @@ -32,7 +32,7 @@ func (f fakeRepo) CreateFile(_ context.Context, file *model.File) error { // UpdateFile updates the stored version of file. func (f fakeRepo) UpdateFile(_ context.Context, file *model.File) error { if _, ok := f.files[file.UUID]; !ok { - return svc.ErrNotFound + return core.ErrNotFound } file.UpdatedAt = time.Now() f.files[file.UUID] = *file diff --git a/service/media/fakerepo_test.go b/core/media/fakerepo_test.go similarity index 94% rename from service/media/fakerepo_test.go rename to core/media/fakerepo_test.go index 8de0cca..a8bf295 100644 --- a/service/media/fakerepo_test.go +++ b/core/media/fakerepo_test.go @@ -7,9 +7,9 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" - svc "github.com/Karaoke-Manager/karman/service" ) func Test_fakeRepo_CreateFile(t *testing.T) { @@ -59,7 +59,7 @@ func Test_fakeRepo_UpdateFile(t *testing.T) { Model: model.Model{UUID: uuid.New()}, } err := repo.UpdateFile(context.TODO(), &update) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("UpdateFile(ctx, &update) returned an unexpected error: %s, expected ErrNotFound", err) } }) diff --git a/service/media/fakeservice.go b/core/media/fakeservice.go similarity index 77% rename from service/media/fakeservice.go rename to core/media/fakeservice.go index 68d0758..b840020 100644 --- a/service/media/fakeservice.go +++ b/core/media/fakeservice.go @@ -10,21 +10,21 @@ import ( "github.com/Karaoke-Manager/karman/pkg/mediatype" ) -// FakeService is a Service implementation that only uses dummy values for file contents. +// fakeService is a Service implementation that only uses dummy values for file contents. // This type is intended for testing purposes. -type FakeService struct { +type fakeService struct { repo Repository } -// NewFakeService creates a new FakeService instance and returns it. +// NewFakeService creates a new fakeService instance and returns it. // The placeholder will be the content of all "files". func NewFakeService(repo Repository) Service { - return &FakeService{repo} + return &fakeService{repo} } // StoreFile fully reads r and returns a file with dummy values. // file.Type will be set to mediaType. -func (f *FakeService) StoreFile(ctx context.Context, mediaType mediatype.MediaType, r io.Reader) (model.File, error) { +func (f *fakeService) StoreFile(ctx context.Context, mediaType mediatype.MediaType, r io.Reader) (model.File, error) { h := sha256.New() n, err := io.Copy(h, r) if err != nil { diff --git a/service/media/fakeservice_test.go b/core/media/fakeservice_test.go similarity index 100% rename from service/media/fakeservice_test.go rename to core/media/fakeservice_test.go diff --git a/service/media/filestore.go b/core/media/filestore.go similarity index 100% rename from service/media/filestore.go rename to core/media/filestore.go diff --git a/service/media/filestore_test.go b/core/media/filestore_test.go similarity index 100% rename from service/media/filestore_test.go rename to core/media/filestore_test.go diff --git a/service/media/interface.go b/core/media/interface.go similarity index 100% rename from service/media/interface.go rename to core/media/interface.go diff --git a/service/media/memstore.go b/core/media/memstore.go similarity index 100% rename from service/media/memstore.go rename to core/media/memstore.go diff --git a/service/media/memstore_test.go b/core/media/memstore_test.go similarity index 100% rename from service/media/memstore_test.go rename to core/media/memstore_test.go diff --git a/service/media/mockstore.go b/core/media/mockstore.go similarity index 100% rename from service/media/mockstore.go rename to core/media/mockstore.go diff --git a/service/media/mockstore_test.go b/core/media/mockstore_test.go similarity index 100% rename from service/media/mockstore_test.go rename to core/media/mockstore_test.go diff --git a/service/media/repo.go b/core/media/repo.go similarity index 97% rename from service/media/repo.go rename to core/media/repo.go index f7774dd..e8e9dfe 100644 --- a/service/media/repo.go +++ b/core/media/repo.go @@ -11,8 +11,8 @@ import ( "github.com/jackc/pgxutil" "github.com/lmittmann/tint" + "github.com/Karaoke-Manager/karman/core/internal/dbutil" "github.com/Karaoke-Manager/karman/model" - "github.com/Karaoke-Manager/karman/service/dbutil" ) // dbRepo is a Repository implementation backed by a PostgreSQL database. diff --git a/service/media/repo_test.go b/core/media/repo_test.go similarity index 96% rename from service/media/repo_test.go rename to core/media/repo_test.go index 64a1dd5..6544666 100644 --- a/service/media/repo_test.go +++ b/core/media/repo_test.go @@ -9,10 +9,10 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" "github.com/Karaoke-Manager/karman/pkg/nolog" - svc "github.com/Karaoke-Manager/karman/service" "github.com/Karaoke-Manager/karman/test" testdata "github.com/Karaoke-Manager/karman/test/data" ) @@ -89,7 +89,7 @@ func Test_dbRepo_UpdateFile(t *testing.T) { file := model.File{} file.UUID = uuid.New() err := repo.UpdateFile(context.TODO(), &file) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("UpdateFile(ctx, &file) returned an unexpected error: %s, expected ErrNotFound", err) } }) diff --git a/service/media/service.go b/core/media/service.go similarity index 100% rename from service/media/service.go rename to core/media/service.go diff --git a/service/media/service_test.go b/core/media/service_test.go similarity index 100% rename from service/media/service_test.go rename to core/media/service_test.go diff --git a/service/media/task.go b/core/media/task.go similarity index 100% rename from service/media/task.go rename to core/media/task.go diff --git a/service/media/testdata/test.gif b/core/media/testdata/test.gif similarity index 100% rename from service/media/testdata/test.gif rename to core/media/testdata/test.gif diff --git a/service/media/testdata/test.jpg b/core/media/testdata/test.jpg similarity index 100% rename from service/media/testdata/test.jpg rename to core/media/testdata/test.jpg diff --git a/service/media/testdata/test.mp3 b/core/media/testdata/test.mp3 similarity index 100% rename from service/media/testdata/test.mp3 rename to core/media/testdata/test.mp3 diff --git a/service/media/testdata/test.mp4 b/core/media/testdata/test.mp4 similarity index 100% rename from service/media/testdata/test.mp4 rename to core/media/testdata/test.mp4 diff --git a/service/media/testdata/test.png b/core/media/testdata/test.png similarity index 100% rename from service/media/testdata/test.png rename to core/media/testdata/test.png diff --git a/service/song/fakerepo.go b/core/song/fakerepo.go similarity index 94% rename from service/song/fakerepo.go rename to core/song/fakerepo.go index 2610963..68edd14 100644 --- a/service/song/fakerepo.go +++ b/core/song/fakerepo.go @@ -7,8 +7,8 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" - svc "github.com/Karaoke-Manager/karman/service" ) // fakeRepo is a simple implementation of Repository that can be used for testing. @@ -36,7 +36,7 @@ func (r *fakeRepo) CreateSong(_ context.Context, song *model.Song) error { func (r *fakeRepo) GetSong(_ context.Context, id uuid.UUID) (model.Song, error) { song, ok := r.songs[id] if !ok { - return model.Song{}, svc.ErrNotFound + return model.Song{}, core.ErrNotFound } return song, nil } @@ -73,7 +73,7 @@ func (r *fakeRepo) DeleteSong(_ context.Context, id uuid.UUID) (bool, error) { func (r *fakeRepo) UpdateSong(_ context.Context, song *model.Song) error { _, ok := r.songs[song.UUID] if !ok { - return svc.ErrNotFound + return core.ErrNotFound } song.UpdatedAt = time.Now() r.songs[song.UUID] = *song diff --git a/service/song/fakerepo_test.go b/core/song/fakerepo_test.go similarity index 96% rename from service/song/fakerepo_test.go rename to core/song/fakerepo_test.go index b67346a..5d1ed84 100644 --- a/service/song/fakerepo_test.go +++ b/core/song/fakerepo_test.go @@ -7,8 +7,8 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" - svc "github.com/Karaoke-Manager/karman/service" ) func Test_fakeRepo_CreateSong(t *testing.T) { @@ -55,7 +55,7 @@ func Test_fakeRepo_GetSong(t *testing.T) { t.Run("missing", func(t *testing.T) { id := uuid.New() _, err := repo.GetSong(context.TODO(), id) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("GetSong(ctx, %q) produced an unexpected error: %s, expected ErrNotFound", id, err) } }) @@ -147,7 +147,7 @@ func Test_fakeRepo_UpdateSong(t *testing.T) { Model: model.Model{UUID: uuid.New()}, } err := repo.UpdateSong(context.TODO(), &update) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("UpdateSong(ctx, &update) returned an unexpected error: %s, expected ErrNotFound", err) } }) diff --git a/service/song/interface.go b/core/song/interface.go similarity index 95% rename from service/song/interface.go rename to core/song/interface.go index 6014e8a..3a8d30e 100644 --- a/service/song/interface.go +++ b/core/song/interface.go @@ -16,7 +16,7 @@ type Repository interface { CreateSong(ctx context.Context, song *model.Song) error // GetSong fetches the song with the specified UUID. - // If no such song exists, service.ErrNotFound will be returned. + // If no such song exists, core.ErrNotFound will be returned. GetSong(ctx context.Context, id uuid.UUID) (model.Song, error) // FindSongs returns all songs matching the specified query. @@ -27,7 +27,7 @@ type Repository interface { FindSongs(ctx context.Context, limit int, offset int64) ([]model.Song, int64, error) // UpdateSong saves Updates for the specified song. - // The song's UUID must already exist in the database, otherwise e service.ErrNotFound + // The song's UUID must already exist in the database, otherwise e core.ErrNotFound // will be returned. UpdateSong(ctx context.Context, song *model.Song) error diff --git a/service/song/repo.go b/core/song/repo.go similarity index 99% rename from service/song/repo.go rename to core/song/repo.go index 5106b09..38f6e7f 100644 --- a/service/song/repo.go +++ b/core/song/repo.go @@ -13,9 +13,9 @@ import ( "github.com/jackc/pgxutil" "github.com/lmittmann/tint" + "github.com/Karaoke-Manager/karman/core/internal/dbutil" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" - "github.com/Karaoke-Manager/karman/service/dbutil" ) // dbRepo is the main Repository implementation, backed by a PostgreSQL database. diff --git a/service/song/repo_test.go b/core/song/repo_test.go similarity index 97% rename from service/song/repo_test.go rename to core/song/repo_test.go index d5b5c78..ee13654 100644 --- a/service/song/repo_test.go +++ b/core/song/repo_test.go @@ -10,10 +10,10 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/mediatype" "github.com/Karaoke-Manager/karman/pkg/nolog" - svc "github.com/Karaoke-Manager/karman/service" "github.com/Karaoke-Manager/karman/test" testdata "github.com/Karaoke-Manager/karman/test/data" ) @@ -88,7 +88,7 @@ func Test_dbRepo_GetSong(t *testing.T) { _, err := repo.GetSong(context.TODO(), id) if err == nil { t.Errorf("GetSong(ctx, %q) did not return an error, expected ErrNotFound", id) - } else if !errors.Is(err, svc.ErrNotFound) { + } else if !errors.Is(err, core.ErrNotFound) { t.Errorf("GetSong(ctx, %q) returned an unexpected error: %s", id, err) } }) @@ -140,7 +140,7 @@ func Test_dbRepo_UpdateSong(t *testing.T) { song := model.Song{} song.UUID = uuid.New() err := repo.UpdateSong(context.TODO(), &song) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("UpdateSong(ctx, &song) returned an unexpected error: %s, expected ErrNotFound", err) } }) diff --git a/service/song/service.go b/core/song/service.go similarity index 100% rename from service/song/service.go rename to core/song/service.go diff --git a/service/song/service_test.go b/core/song/service_test.go similarity index 100% rename from service/song/service_test.go rename to core/song/service_test.go diff --git a/service/upload/filestore.go b/core/upload/filestore.go similarity index 100% rename from service/upload/filestore.go rename to core/upload/filestore.go diff --git a/service/upload/filestore_test.go b/core/upload/filestore_test.go similarity index 100% rename from service/upload/filestore_test.go rename to core/upload/filestore_test.go diff --git a/service/upload/interface.go b/core/upload/interface.go similarity index 100% rename from service/upload/interface.go rename to core/upload/interface.go diff --git a/service/upload/repo.go b/core/upload/repo.go similarity index 98% rename from service/upload/repo.go rename to core/upload/repo.go index 2387f3e..ed8c2f7 100644 --- a/service/upload/repo.go +++ b/core/upload/repo.go @@ -12,8 +12,8 @@ import ( "github.com/jackc/pgxutil" "github.com/lmittmann/tint" + "github.com/Karaoke-Manager/karman/core/internal/dbutil" "github.com/Karaoke-Manager/karman/model" - "github.com/Karaoke-Manager/karman/service/dbutil" ) // dbRepo is the main Repository implementation, backed by a PostgreSQL database. diff --git a/service/upload/repo_test.go b/core/upload/repo_test.go similarity index 97% rename from service/upload/repo_test.go rename to core/upload/repo_test.go index 2ee5e3e..997b656 100644 --- a/service/upload/repo_test.go +++ b/core/upload/repo_test.go @@ -9,9 +9,9 @@ import ( "github.com/google/uuid" + "github.com/Karaoke-Manager/karman/core" "github.com/Karaoke-Manager/karman/model" "github.com/Karaoke-Manager/karman/pkg/nolog" - svc "github.com/Karaoke-Manager/karman/service" "github.com/Karaoke-Manager/karman/test" testdata "github.com/Karaoke-Manager/karman/test/data" ) @@ -47,7 +47,7 @@ func TestService_GetUpload(t *testing.T) { if err == nil { t.Errorf("GetUpload(ctx, %q) did not return an error, expected ErrNotFound", id) } - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("GetUpload(ctx, %q) returned an unexpected error: %s", id, err) } }) @@ -127,7 +127,7 @@ func TestService_DeleteUpload(t *testing.T) { } _, err = repo.GetUpload(context.TODO(), upload.UUID) - if !errors.Is(err, svc.ErrNotFound) { + if !errors.Is(err, core.ErrNotFound) { t.Errorf("GetUpload(ctx, %q) returned an upload after it was deleted", upload.UUID) } }) diff --git a/service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir1/.gitkeep b/core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir1/.gitkeep similarity index 100% rename from service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir1/.gitkeep rename to core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir1/.gitkeep diff --git a/service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir2/.gitkeep b/core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir2/.gitkeep similarity index 100% rename from service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir2/.gitkeep rename to core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/dir2/.gitkeep diff --git a/service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file1.txt b/core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file1.txt similarity index 100% rename from service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file1.txt rename to core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file1.txt diff --git a/service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file2.txt b/core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file2.txt similarity index 100% rename from service/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file2.txt rename to core/upload/testdata/e4d7ec99-77e0-4595-815a-18f3811c1b9d/file2.txt diff --git a/pkg/nolog/handler.go b/pkg/nolog/handler.go index f54baee..f060d85 100644 --- a/pkg/nolog/handler.go +++ b/pkg/nolog/handler.go @@ -5,9 +5,13 @@ import ( "log/slog" ) +// Handler is a noop logging handler. var Handler slog.Handler = &handler{} + +// Logger is a noop logger. var Logger = slog.New(Handler) +// handler implements a noop slog.Handler. type handler struct{} // Enabled returns false for all log levels.