add artists list to /api/v1/music

This commit is contained in:
ari melody 2024-09-12 09:46:40 +01:00
parent bc1b6c5872
commit e69cf78e57
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 18 additions and 11 deletions

View file

@ -7,7 +7,7 @@ tmp_dir = "tmp"
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["admin\\static", "public", "uploads", "test"]
exclude_dir = ["admin/static", "public", "uploads", "test", "db"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false

View file

@ -27,6 +27,7 @@ func ServeCatalog() http.Handler {
type Release struct {
ID string `json:"id"`
Title string `json:"title"`
Artists []string `json:"artists"`
ReleaseType model.ReleaseType `json:"type" db:"type"`
ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
Artwork string `json:"artwork"`
@ -40,9 +41,15 @@ func ServeCatalog() http.Handler {
if !release.Visible && !authorised {
continue
}
artists := []string{}
for _, credit := range release.Credits {
if !credit.Primary { continue }
artists = append(artists, credit.Artist.Name)
}
catalog = append(catalog, Release{
ID: release.ID,
Title: release.Title,
Artists: artists,
ReleaseType: release.ReleaseType,
ReleaseDate: release.ReleaseDate,
Artwork: release.Artwork,

View file

@ -66,17 +66,17 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod
return nil, err
}
if full {
for _, release := range releases {
// get credits
credits, err := GetReleaseCredits(db, release.ID)
if err != nil {
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
}
for _, credit := range credits {
release.Credits = append(release.Credits, credit)
}
for _, release := range releases {
// get credits
credits, err := GetReleaseCredits(db, release.ID)
if err != nil {
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
}
for _, credit := range credits {
release.Credits = append(release.Credits, credit)
}
if full {
// get tracks
tracks, err := GetReleaseTracks(db, release.ID)
if err != nil {