This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"butterfliu/internal/model"
|
||||
"butterfliu/internal/repository"
|
||||
"butterfliu/internal/scanner"
|
||||
"errors"
|
||||
@@ -26,20 +27,20 @@ func NewLibraryService(repo *repository.LibraryRepository) *LibraryService {
|
||||
return &LibraryService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *LibraryService) GetAll() ([]repository.Library, error) {
|
||||
func (s *LibraryService) GetAll() ([]model.Library, error) {
|
||||
return s.repo.GetAll()
|
||||
}
|
||||
|
||||
func (s *LibraryService) GetByID(id int) (repository.Library, error) {
|
||||
func (s *LibraryService) GetByID(id int) (model.Library, error) {
|
||||
return s.repo.GetByID(id)
|
||||
}
|
||||
|
||||
func (s *LibraryService) Create(name, path string) (repository.Library, error) {
|
||||
func (s *LibraryService) Create(name, path string) (model.Library, error) {
|
||||
if name = strings.TrimSpace(name); name == "" {
|
||||
return repository.Library{}, errors.New("library name cannot be empty")
|
||||
return model.Library{}, errors.New("library name cannot be empty")
|
||||
}
|
||||
if path = strings.TrimSpace(path); path == "" {
|
||||
return repository.Library{}, errors.New("library path cannot be empty")
|
||||
return model.Library{}, errors.New("library path cannot be empty")
|
||||
}
|
||||
return s.repo.Create(name, path)
|
||||
}
|
||||
@@ -66,11 +67,11 @@ func (s *LibraryService) GetSongs(id int) ([]repository.SongDetail, error) {
|
||||
return s.repo.GetSongsByLibraryWithDetails(id)
|
||||
}
|
||||
|
||||
func (s *LibraryService) GetArtists() ([]repository.Artist, error) {
|
||||
func (s *LibraryService) GetArtists() ([]model.Artist, error) {
|
||||
return s.repo.GetArtists()
|
||||
}
|
||||
|
||||
func (s *LibraryService) GetAlbums() ([]repository.Album, error) {
|
||||
func (s *LibraryService) GetAlbums() ([]model.Album, error) {
|
||||
return s.repo.GetAlbums()
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ func (s *LibraryService) addScannedSong(song scanner.ScannedSong, libraryID int,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *LibraryService) getOrCreateMediaFile(path string, libraryID int) (repository.MediaFile, error) {
|
||||
func (s *LibraryService) getOrCreateMediaFile(path string, libraryID int) (model.MediaFile, error) {
|
||||
mf, err := s.repo.GetMediaFileByPath(path)
|
||||
if err == nil {
|
||||
return mf, nil
|
||||
@@ -131,7 +132,7 @@ func (s *LibraryService) getOrCreateMediaFile(path string, libraryID int) (repos
|
||||
return s.repo.CreateMediaFile(path, libraryID)
|
||||
}
|
||||
|
||||
func (s *LibraryService) getOrCreateArtist(name string) (repository.Artist, error) {
|
||||
func (s *LibraryService) getOrCreateArtist(name string) (model.Artist, error) {
|
||||
a, err := s.repo.GetArtistByName(name)
|
||||
if err == nil {
|
||||
return a, nil
|
||||
@@ -139,7 +140,7 @@ func (s *LibraryService) getOrCreateArtist(name string) (repository.Artist, erro
|
||||
return s.repo.CreateArtist(name)
|
||||
}
|
||||
|
||||
func (s *LibraryService) getOrCreateAlbum(title string, artistID int) (repository.Album, error) {
|
||||
func (s *LibraryService) getOrCreateAlbum(title string, artistID int) (model.Album, error) {
|
||||
al, err := s.repo.GetAlbumByTitleAndArtist(title, artistID)
|
||||
if err == nil {
|
||||
return al, nil
|
||||
|
||||
Reference in New Issue
Block a user