HEAVY: finish music service migration, tidy up services, more tests
This commit is contained in:
parent
9e311df462
commit
90a671982c
47 changed files with 2698 additions and 902 deletions
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"arimelody-web/admin/templates"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
)
|
||||
|
|
@ -23,7 +22,7 @@ func serveArtists(app *app.AppState) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
artists, err := controller.GetAllArtists(app.DB)
|
||||
artists, err := app.MusicService.GetAllArtists()
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch artists: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -50,7 +49,7 @@ func serveArtist(app *app.AppState, artistID string) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
artist, err := controller.GetArtist(app.DB, artistID)
|
||||
artist, err := app.MusicService.GetArtistByID(artistID)
|
||||
if err != nil {
|
||||
if artist == nil {
|
||||
http.NotFound(w, r)
|
||||
|
|
@ -61,7 +60,7 @@ func serveArtist(app *app.AppState, artistID string) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
credits, err := controller.GetArtistCredits(app.DB, artist.ID, true)
|
||||
credits, err := app.MusicService.GetArtistCredits(artistID, true)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to serve admin artist page for %s: %s\n", artistID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
|
|||
|
|
@ -83,39 +83,39 @@ func AdminIndexHandler(app *app.AppState) http.Handler {
|
|||
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
releases, err := controller.GetAllReleases(app.DB, false, 3, true)
|
||||
releases, err := app.MusicService.GetAllReleases(false, 3)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
releaseCount, err := controller.GetReleaseCount(app.DB, false)
|
||||
releaseCount, err := app.MusicService.GetReleaseCount(false)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull releases count: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
artists, err := controller.GetAllArtists(app.DB)
|
||||
artists, err := app.MusicService.GetAllArtists()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artists: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
artistCount, err := controller.GetArtistCount(app.DB)
|
||||
artistCount, err := app.MusicService.GetArtistCount()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull artist count: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tracks, err := controller.GetOrphanTracks(app.DB)
|
||||
tracks, err := app.MusicService.GetOrphanTracks()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull orphan tracks: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
trackCount, err := controller.GetTrackCount(app.DB)
|
||||
trackCount, err := app.MusicService.GetTrackCount()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to pull track count: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"arimelody-web/admin/templates"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
"arimelody-web/errors"
|
||||
)
|
||||
|
||||
func serveReleases(app *app.AppState) http.Handler {
|
||||
|
|
@ -34,7 +34,7 @@ func serveReleases(app *app.AppState) http.Handler {
|
|||
Releases []*model.Release
|
||||
}
|
||||
|
||||
releases, err := controller.GetAllReleases(app.DB, false, 0, true)
|
||||
releases, err := app.MusicService.GetAllFullReleases(false, 0)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch releases: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -60,9 +60,13 @@ func serveRelease(app *app.AppState, releaseID string, action string) http.Handl
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
release, err := controller.GetRelease(app.DB, releaseID, true)
|
||||
release, err := app.MusicService.GetFullReleaseByID(releaseID)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no rows") {
|
||||
if errors.IsValidationError(err) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if errors.IsNotExistError(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
|
@ -130,7 +134,7 @@ func serveEditCredits(release *model.Release) http.Handler {
|
|||
|
||||
func serveAddCredit(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
artists, err := controller.GetArtistsNotOnRelease(app.DB, release.ID)
|
||||
artists, err := app.MusicService.GetArtistsNotOnRelease(release.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch artists not on %s: %s\n", release.ID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -158,7 +162,7 @@ func serveNewCredit(app *app.AppState) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
split := strings.Split(r.URL.Path, "/")
|
||||
artistID := split[len(split) - 1]
|
||||
artist, err := controller.GetArtist(app.DB, artistID)
|
||||
artist, err := app.MusicService.GetArtistByID(artistID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch artist %s: %s\n", artistID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -207,7 +211,7 @@ func serveEditTracks(release *model.Release) http.Handler {
|
|||
|
||||
func serveAddTrack(app *app.AppState, release *model.Release) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
tracks, err := controller.GetTracksNotOnRelease(app.DB, release.ID)
|
||||
tracks, err := app.MusicService.GetTracksNotOnRelease(release.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch tracks not on %s: %s\n", release.ID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -235,7 +239,7 @@ func serveNewTrack(app *app.AppState) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
split := strings.Split(r.URL.Path, "/")
|
||||
trackID := split[len(split) - 1]
|
||||
track, err := controller.GetTrack(app.DB, trackID)
|
||||
track, err := app.MusicService.GetTrackByID(trackID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch track %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"arimelody-web/admin/templates"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
)
|
||||
|
|
@ -23,7 +22,7 @@ func serveTracks(app *app.AppState) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
tracks, err := controller.GetAllTracks(app.DB)
|
||||
tracks, err := app.MusicService.GetAllTracks()
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch tracks: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -50,7 +49,7 @@ func serveTrack(app *app.AppState, trackID string) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := r.Context().Value("session").(*model.Session)
|
||||
|
||||
track, err := controller.GetTrack(app.DB, trackID)
|
||||
track, err := app.MusicService.GetTrackByID(trackID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to serve admin track page for %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
@ -61,7 +60,7 @@ func serveTrack(app *app.AppState, trackID string) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
releases, err := controller.GetTrackReleases(app.DB, track.ID, true)
|
||||
releases, err := app.MusicService.GetTrackReleases(trackID)
|
||||
if err != nil {
|
||||
fmt.Printf("WARN: Failed to fetch releases for track %s: %s\n", trackID, err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue