Skip to content

Commit

Permalink
Rename service package to core
Browse files Browse the repository at this point in the history
  • Loading branch information
codello committed Sep 9, 2023
1 parent 3409931 commit 7b8a4aa
Show file tree
Hide file tree
Showing 60 changed files with 70 additions and 66 deletions.
4 changes: 2 additions & 2 deletions api/apierror/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/dav/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions api/v1/dav/internal/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/v1/dav/internal/mediafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/dav/internal/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/dav/internal/songdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/dav/internal/txtfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions api/v1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/songs/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions api/v1/songs/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion api/v1/songs/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion api/v1/uploads/file_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1/uploads/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1/uploads/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/karman/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions service/doc.go → core/doc.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion service/errors.go → core/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package core

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions service/dbutil/errors.go → core/internal/dbutil/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions service/media/fakerepo.go → core/media/fakerepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
Expand Down
10 changes: 5 additions & 5 deletions service/media/fakeservice.go → core/media/fakeservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion service/media/repo.go → core/media/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions service/media/repo_test.go → core/media/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
6 changes: 3 additions & 3 deletions service/song/fakerepo.go → core/song/fakerepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions service/song/fakerepo_test.go → core/song/fakerepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down
Loading

0 comments on commit 7b8a4aa

Please sign in to comment.