2024-08-02 21:48:26 +00:00
|
|
|
package music
|
|
|
|
|
|
|
|
import (
|
2024-08-02 23:27:30 +00:00
|
|
|
"arimelody.me/arimelody.me/global"
|
2024-08-02 21:48:26 +00:00
|
|
|
"arimelody.me/arimelody.me/music/model"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DATABASE
|
|
|
|
|
2024-08-02 23:27:30 +00:00
|
|
|
func PullReleaseCredits(db *sqlx.DB, releaseID string) ([]*model.Credit, error) {
|
|
|
|
type creditDB struct {
|
|
|
|
Artist string
|
|
|
|
Role string
|
|
|
|
Primary bool `db:"is_primary"`
|
|
|
|
}
|
|
|
|
var credit_rows = []creditDB{}
|
|
|
|
var credits = []*model.Credit{}
|
2024-08-02 21:48:26 +00:00
|
|
|
|
|
|
|
err := db.Select(
|
2024-08-02 23:27:30 +00:00
|
|
|
&credit_rows,
|
|
|
|
"SELECT artist, role, is_primary FROM musiccredit WHERE release=$1",
|
2024-08-02 21:48:26 +00:00
|
|
|
releaseID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-08-02 23:27:30 +00:00
|
|
|
for _, c := range credit_rows {
|
|
|
|
credits = append(credits, &model.Credit{
|
|
|
|
Artist: global.GetArtist(c.Artist),
|
|
|
|
Role: c.Role,
|
|
|
|
Primary: c.Primary,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-08-02 21:48:26 +00:00
|
|
|
return credits, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateCreditDB(db *sqlx.DB, releaseID string, artistID string, credit *model.Credit) (error) {
|
|
|
|
_, err := db.Exec(
|
|
|
|
"INSERT INTO musiccredit (release, artist, role, is_primary) "+
|
|
|
|
"VALUES ($1, $2, $3, $4)",
|
|
|
|
releaseID,
|
|
|
|
artistID,
|
|
|
|
credit.Role,
|
|
|
|
credit.Primary,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateCreditDB(db *sqlx.DB, releaseID string, artistID string, credit *model.Credit) (error) {
|
|
|
|
_, err := db.Exec(
|
|
|
|
"UPDATE musiccredit SET "+
|
|
|
|
"role=$3, is_primary=$4 "+
|
|
|
|
"WHERE release=$1, artist=$2",
|
|
|
|
releaseID,
|
|
|
|
artistID,
|
|
|
|
credit.Role,
|
|
|
|
credit.Primary,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteCreditDB(db *sqlx.DB, releaseID string, artistID string) (error) {
|
|
|
|
_, err := db.Exec(
|
|
|
|
"DELETE FROM musiccredit "+
|
|
|
|
"WHERE release=$1, artist=$2",
|
|
|
|
releaseID,
|
|
|
|
artistID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|