HOLY REFACTOR GOOD GRIEF (also finally started some CRUD work)
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
1c310c9101
commit
442889340c
80 changed files with 1571 additions and 1330 deletions
70
music/controller/credit.go
Normal file
70
music/controller/credit.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package music
|
||||
|
||||
import (
|
||||
"arimelody.me/arimelody.me/music/model"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// DATABASE
|
||||
|
||||
func PullReleaseCredits(db *sqlx.DB, releaseID string) ([]model.Credit, error) {
|
||||
var credits = []model.Credit{}
|
||||
|
||||
err := db.Select(
|
||||
&credits,
|
||||
"SELECT * FROM musiccredit WHERE release=$1",
|
||||
releaseID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue