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
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue