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
18
api/api.go
18
api/api.go
|
|
@ -10,6 +10,7 @@ import (
|
|||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/model/app"
|
||||
"arimelody-web/errors"
|
||||
)
|
||||
|
||||
func Handler(app *app.AppState) http.Handler {
|
||||
|
|
@ -21,9 +22,9 @@ func Handler(app *app.AppState) http.Handler {
|
|||
|
||||
mux.Handle("/v1/artist/", http.StripPrefix("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var artistID = strings.Split(r.URL.Path[1:], "/")[0]
|
||||
artist, err := controller.GetArtist(app.DB, artistID)
|
||||
artist, err := app.MusicService.GetArtistByID(artistID)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no rows") {
|
||||
if errors.IsNotExistError(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
|
@ -63,9 +64,9 @@ func Handler(app *app.AppState) http.Handler {
|
|||
|
||||
mux.Handle("/v1/music/", http.StripPrefix("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var releaseID = strings.Split(r.URL.Path[1:], "/")[0]
|
||||
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.IsNotExistError(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
|
@ -105,9 +106,9 @@ func Handler(app *app.AppState) http.Handler {
|
|||
|
||||
mux.Handle("/v1/track/", http.StripPrefix("/v1/track", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var trackID = strings.Split(r.URL.Path[1:], "/")[0]
|
||||
track, err := controller.GetTrack(app.DB, trackID)
|
||||
track, err := app.MusicService.GetTrackByID(trackID)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no rows") {
|
||||
if errors.IsNotExistError(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
|
@ -187,7 +188,10 @@ func getSession(app *app.AppState, r *http.Request) (*model.Session, error) {
|
|||
// fetch existing session
|
||||
session, err := controller.GetSession(app, token)
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "no rows") {
|
||||
if errors.IsValidationError(err) {
|
||||
return nil, err
|
||||
}
|
||||
if errors.IsNotExistError(err) {
|
||||
return nil, fmt.Errorf("Failed to retrieve session: %v\n", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue