实现音频服务api
This commit is contained in:
@@ -4,38 +4,6 @@ import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Library struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type MediaFile struct {
|
||||
ID int `json:"id"`
|
||||
Path string `json:"path"`
|
||||
LibraryID int `json:"library_id"`
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Album struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
ArtistID int `json:"artist_id"`
|
||||
}
|
||||
|
||||
type Song struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
ArtistID int `json:"artist_id"`
|
||||
AlbumID int `json:"album_id"`
|
||||
Duration int `json:"duration"`
|
||||
MediaFileID int `json:"media_file_id"`
|
||||
}
|
||||
|
||||
type SongDetail struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
@@ -140,31 +108,6 @@ func (r *LibraryRepository) GetSongsByLibraryWithDetails(libraryID int) ([]SongD
|
||||
return songs, nil
|
||||
}
|
||||
|
||||
func (r *LibraryRepository) GetAllSongsWithDetails() ([]SongDetail, error) {
|
||||
rows, err := r.db.Query(`
|
||||
SELECT s.id, s.title, a.name as artist_name, al.title as album_title, s.duration, mf.path
|
||||
FROM songs s
|
||||
INNER JOIN media_files mf ON s.media_file_id = mf.id
|
||||
INNER JOIN artists a ON s.artist_id = a.id
|
||||
INNER JOIN albums al ON s.album_id = al.id
|
||||
ORDER BY s.title
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
songs := []SongDetail{}
|
||||
for rows.Next() {
|
||||
var song SongDetail
|
||||
if err := rows.Scan(&song.ID, &song.Title, &song.Artist, &song.Album, &song.Duration, &song.Path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
songs = append(songs, song)
|
||||
}
|
||||
return songs, nil
|
||||
}
|
||||
|
||||
func (r *LibraryRepository) GetMediaFileByPath(path string) (MediaFile, error) {
|
||||
row := r.db.QueryRow("SELECT id, path, library_id FROM media_files WHERE path = ?", path)
|
||||
var mediaFile MediaFile
|
||||
@@ -300,21 +243,3 @@ func (r *LibraryRepository) GetAlbums() ([]Album, error) {
|
||||
}
|
||||
return albums, nil
|
||||
}
|
||||
|
||||
func (r *LibraryRepository) GetSongs() ([]Song, error) {
|
||||
rows, err := r.db.Query("SELECT id, title, artist_id, album_id, duration, media_file_id FROM songs")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
songs := []Song{}
|
||||
for rows.Next() {
|
||||
var song Song
|
||||
if err := rows.Scan(&song.ID, &song.Title, &song.ArtistID, &song.AlbumID, &song.Duration, &song.MediaFileID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
songs = append(songs, song)
|
||||
}
|
||||
return songs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user