turns out rewriting all of your database code takes a while
This commit is contained in:
parent
1998a36d6d
commit
965d6f5c3e
30 changed files with 947 additions and 1036 deletions
|
@ -1,8 +1,10 @@
|
|||
package model
|
||||
|
||||
import "strings"
|
||||
|
||||
type (
|
||||
Artist struct {
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Website string `json:"website"`
|
||||
Avatar string `json:"avatar"`
|
||||
|
@ -14,8 +16,61 @@ func (artist Artist) GetWebsite() string {
|
|||
}
|
||||
|
||||
func (artist Artist) GetAvatar() string {
|
||||
if artist.Avatar == "" {
|
||||
return "/img/default-avatar.png"
|
||||
}
|
||||
if artist.Avatar == "" {
|
||||
return "/img/default-avatar.png"
|
||||
}
|
||||
return artist.Avatar
|
||||
}
|
||||
|
||||
func (release FullRelease) GetUniqueArtists(only_primary bool) []*Artist {
|
||||
var artists = []*Artist{}
|
||||
|
||||
for _, credit := range release.Credits {
|
||||
if only_primary && !credit.Primary {
|
||||
continue
|
||||
}
|
||||
|
||||
exists := false
|
||||
for _, a := range artists {
|
||||
if a.ID == credit.Artist.ID {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
|
||||
artists = append(artists, &credit.Artist)
|
||||
}
|
||||
|
||||
return artists
|
||||
}
|
||||
|
||||
func (release FullRelease) GetUniqueArtistNames(only_primary bool) []string {
|
||||
var names = []string{}
|
||||
for _, artist := range release.GetUniqueArtists(only_primary) {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func (release FullRelease) PrintArtists(only_primary bool, ampersand bool) string {
|
||||
names := release.GetUniqueArtistNames(only_primary)
|
||||
|
||||
if len(names) == 0 {
|
||||
return "Unknown Artist"
|
||||
} else if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
|
||||
if ampersand {
|
||||
res := strings.Join(names[:len(names)-1], ", ")
|
||||
res += " & " + names[len(names)-1]
|
||||
return res
|
||||
} else {
|
||||
return strings.Join(names[:], ", ")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package model
|
||||
|
||||
type Credit struct {
|
||||
Artist *Artist `json:"artist"`
|
||||
Artist `json:"artist"`
|
||||
Role string `json:"role"`
|
||||
Primary bool `json:"primary" db:"is_primary"`
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
)
|
||||
|
||||
type Link struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func (link Link) NormaliseName() string {
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
ReleaseType string
|
||||
Release struct {
|
||||
ID string `json:"id"`
|
||||
Visible bool `json:"visible"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
ReleaseType ReleaseType `json:"type" db:"type"`
|
||||
ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
|
||||
Artwork string `json:"artwork"`
|
||||
Buyname string `json:"buyname"`
|
||||
Buylink string `json:"buylink"`
|
||||
Links []*Link `json:"links"`
|
||||
Credits []*Credit `json:"credits"`
|
||||
Tracks []*Track `json:"tracks"`
|
||||
|
||||
Release struct {
|
||||
ID string `json:"id"`
|
||||
Visible bool `json:"visible"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
ReleaseType ReleaseType `json:"type" db:"type"`
|
||||
ReleaseDate time.Time `json:"releaseDate" db:"release_date"`
|
||||
Artwork string `json:"artwork"`
|
||||
Buyname string `json:"buyname"`
|
||||
Buylink string `json:"buylink"`
|
||||
Copyright string `json:"copyright" db:"copyright"`
|
||||
CopyrightURL string `json:"copyrightURL" db:"copyrighturl"`
|
||||
}
|
||||
|
||||
FullRelease struct {
|
||||
*Release
|
||||
Tracks []DisplayTrack
|
||||
Credits []Credit
|
||||
Links []Link
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -52,63 +58,10 @@ func (release Release) GetArtwork() string {
|
|||
return release.Artwork
|
||||
}
|
||||
|
||||
func (release Release) IsSingle() bool {
|
||||
func (release FullRelease) IsSingle() bool {
|
||||
return len(release.Tracks) == 1;
|
||||
}
|
||||
|
||||
func (release Release) IsReleased() bool {
|
||||
return release.ReleaseDate.Before(time.Now())
|
||||
}
|
||||
|
||||
func (release Release) GetUniqueArtists(only_primary bool) []Artist {
|
||||
var artists = []Artist{}
|
||||
|
||||
for _, credit := range release.Credits {
|
||||
if only_primary && !credit.Primary {
|
||||
continue
|
||||
}
|
||||
|
||||
exists := false
|
||||
for _, a := range artists {
|
||||
if a.ID == credit.Artist.ID {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
|
||||
artists = append(artists, *credit.Artist)
|
||||
}
|
||||
|
||||
return artists
|
||||
}
|
||||
|
||||
func (release Release) GetUniqueArtistNames(only_primary bool) []string {
|
||||
var names = []string{}
|
||||
for _, artist := range release.GetUniqueArtists(only_primary) {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func (release Release) PrintArtists(only_primary bool, ampersand bool) string {
|
||||
names := release.GetUniqueArtistNames(only_primary)
|
||||
|
||||
if len(names) == 0 {
|
||||
return "Unknown Artist"
|
||||
} else if len(names) == 1 {
|
||||
return names[0]
|
||||
}
|
||||
|
||||
if ampersand {
|
||||
res := strings.Join(names[:len(names)-1], ", ")
|
||||
res += " & " + names[len(names)-1]
|
||||
return res
|
||||
} else {
|
||||
return strings.Join(names[:], ", ")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,30 @@
|
|||
package model
|
||||
|
||||
type Track struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Lyrics string `json:"lyrics"`
|
||||
PreviewURL string `json:"previewURL" db:"preview_url"`
|
||||
Release *Release `json:"-" db:"-"`
|
||||
import (
|
||||
"html/template"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
Track struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Lyrics string `json:"lyrics"`
|
||||
PreviewURL string `json:"previewURL" db:"preview_url"`
|
||||
}
|
||||
|
||||
DisplayTrack struct {
|
||||
*Track
|
||||
Lyrics template.HTML
|
||||
Number int
|
||||
}
|
||||
)
|
||||
|
||||
func (track Track) MakeDisplay(number int) DisplayTrack {
|
||||
return DisplayTrack{
|
||||
Track: &track,
|
||||
Lyrics: template.HTML(strings.Replace(track.Lyrics, "\n", "<br>", -1)),
|
||||
Number: number,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue