2024-08-01 00:39:18 +00:00
|
|
|
package music
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
2024-08-01 23:53:19 +00:00
|
|
|
type (
|
|
|
|
Credit struct {
|
|
|
|
Artist *Artist `json:"artist"`
|
|
|
|
Role string `json:"role"`
|
|
|
|
Primary bool `json:"primary"`
|
|
|
|
}
|
|
|
|
|
|
|
|
PostCreditBody struct {
|
|
|
|
Artist string `json:"artist"`
|
|
|
|
Role string `json:"role"`
|
|
|
|
Primary bool `json:"primary"`
|
|
|
|
}
|
|
|
|
)
|
2024-08-01 00:39:18 +00:00
|
|
|
|
|
|
|
// GETTERS
|
|
|
|
|
|
|
|
func (credit Credit) GetArtist() Artist {
|
2024-08-01 02:54:15 +00:00
|
|
|
return *credit.Artist
|
2024-08-01 00:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (credit Credit) GetRole() string {
|
2024-08-01 02:54:15 +00:00
|
|
|
return credit.Role
|
2024-08-01 00:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (credit Credit) IsPrimary() bool {
|
2024-08-01 02:54:15 +00:00
|
|
|
return credit.Primary
|
2024-08-01 00:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SETTERS
|
|
|
|
|
|
|
|
func (credit Credit) SetArtist(artist *Artist) error {
|
|
|
|
// TODO: update DB
|
2024-08-01 02:54:15 +00:00
|
|
|
credit.Artist = artist
|
2024-08-01 00:39:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (credit Credit) SetRole(role string) error {
|
|
|
|
// TODO: update DB
|
2024-08-01 02:54:15 +00:00
|
|
|
credit.Role = role
|
2024-08-01 00:39:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (credit Credit) SetPrimary(primary bool) error {
|
|
|
|
// TODO: update DB
|
2024-08-01 02:54:15 +00:00
|
|
|
credit.Primary = primary
|
2024-08-01 00:39:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DATABASE
|
|
|
|
|
|
|
|
func PullReleaseCredits(db *sqlx.DB, releaseID string) ([]Credit, error) {
|
|
|
|
var credits = []Credit{}
|
|
|
|
|
|
|
|
credit_rows, err := db.Query("SELECT artist, role, is_primary FROM musiccredits WHERE release=$1", releaseID)
|
|
|
|
if err != nil {
|
|
|
|
return []Credit{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for credit_rows.Next() {
|
|
|
|
var artistID string
|
|
|
|
var credit = Credit{}
|
|
|
|
err = credit_rows.Scan(
|
|
|
|
&artistID,
|
2024-08-01 02:54:15 +00:00
|
|
|
&credit.Role,
|
|
|
|
&credit.Primary,
|
2024-08-01 00:39:18 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error while pulling credit for release %s: %s\n", releaseID, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-08-01 02:54:15 +00:00
|
|
|
credit.Artist = GetArtist(artistID)
|
|
|
|
if credit.Artist == nil {
|
2024-08-01 00:39:18 +00:00
|
|
|
// this should absolutely not happen ever due to foreign key
|
|
|
|
// constraints, but it doesn't hurt to be sure!
|
|
|
|
fmt.Printf("Error while pulling credit for release %s: Artist %s does not exist\n", releaseID, artistID)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
credits = append(credits, credit)
|
|
|
|
}
|
|
|
|
|
|
|
|
return credits, nil
|
|
|
|
}
|