|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package handlers
|
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
|
@ -16,51 +17,62 @@ func GetAliasesHandler(store db.DB) http.HandlerFunc {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx := r.Context()
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Debug().Msgf("GetAliasesHandler: Got request with params: '%s'", r.URL.Query().Encode())
|
|
|
|
|
|
|
|
|
|
|
|
// Parse query parameters
|
|
|
|
// Parse query parameters
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
trackIDStr := r.URL.Query().Get("track_id")
|
|
|
|
trackIDStr := r.URL.Query().Get("track_id")
|
|
|
|
|
|
|
|
|
|
|
|
if artistIDStr == "" && albumIDStr == "" && trackIDStr == "" {
|
|
|
|
if artistIDStr == "" && albumIDStr == "" && trackIDStr == "" {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is missing required parameters")
|
|
|
|
utils.WriteError(w, "artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is has more than one of artist_id, album_id, and track_id")
|
|
|
|
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var aliases []models.Alias
|
|
|
|
var aliases []models.Alias
|
|
|
|
|
|
|
|
|
|
|
|
if artistIDStr != "" {
|
|
|
|
if artistIDStr != "" {
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Invalid artist id")
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aliases, err = store.GetAllArtistAliases(ctx, int32(artistID))
|
|
|
|
aliases, err = store.GetAllArtistAliases(ctx, int32(artistID))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to get artist aliases")
|
|
|
|
l.Err(fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Failed to get artist aliases")
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Invalid album id")
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aliases, err = store.GetAllAlbumAliases(ctx, int32(albumID))
|
|
|
|
aliases, err = store.GetAllAlbumAliases(ctx, int32(albumID))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to get artist aliases")
|
|
|
|
l.Err(fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Failed to get album aliases")
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Invalid track id")
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aliases, err = store.GetAllTrackAliases(ctx, int32(trackID))
|
|
|
|
aliases, err = store.GetAllTrackAliases(ctx, int32(trackID))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to get artist aliases")
|
|
|
|
l.Err(fmt.Errorf("GetAliasesHandler: %w", err)).Msg("Failed to get track aliases")
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to retrieve aliases", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -76,6 +88,8 @@ func DeleteAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx := r.Context()
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Debug().Msgf("DeleteAliasHandler: Got request with params: '%s'", r.URL.Query().Encode())
|
|
|
|
|
|
|
|
|
|
|
|
// Parse query parameters
|
|
|
|
// Parse query parameters
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
@ -83,10 +97,12 @@ func DeleteAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
alias := r.URL.Query().Get("alias")
|
|
|
|
alias := r.URL.Query().Get("alias")
|
|
|
|
|
|
|
|
|
|
|
|
if alias == "" || (artistIDStr == "" && albumIDStr == "" && trackIDStr == "") {
|
|
|
|
if alias == "" || (artistIDStr == "" && albumIDStr == "" && trackIDStr == "") {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is missing required parameters")
|
|
|
|
utils.WriteError(w, "alias and artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "alias and artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is has more than one of artist_id, album_id, and track_id")
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -94,36 +110,39 @@ func DeleteAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
if artistIDStr != "" {
|
|
|
|
if artistIDStr != "" {
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Invalid artist id")
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.DeleteArtistAlias(ctx, int32(artistID), alias)
|
|
|
|
err = store.DeleteArtistAlias(ctx, int32(artistID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to delete alias")
|
|
|
|
l.Err(fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Failed to delete artist alias")
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Invalid album id")
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.DeleteAlbumAlias(ctx, int32(albumID), alias)
|
|
|
|
err = store.DeleteAlbumAlias(ctx, int32(albumID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to delete alias")
|
|
|
|
l.Err(fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Failed to delete album alias")
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Invalid track id")
|
|
|
|
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.DeleteTrackAlias(ctx, int32(trackID), alias)
|
|
|
|
err = store.DeleteTrackAlias(ctx, int32(trackID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to delete alias")
|
|
|
|
l.Err(fmt.Errorf("DeleteAliasHandler: %w", err)).Msg("Failed to delete track alias")
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to delete alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -139,64 +158,71 @@ func CreateAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx := r.Context()
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Debug().Msgf("CreateAliasHandler: Got request with params: '%s'", r.URL.Query().Encode())
|
|
|
|
|
|
|
|
|
|
|
|
err := r.ParseForm()
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
utils.WriteError(w, "invalid request body", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid request body", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias := r.FormValue("alias")
|
|
|
|
|
|
|
|
if alias == "" {
|
|
|
|
|
|
|
|
utils.WriteError(w, "alias must be provided", http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
trackIDStr := r.URL.Query().Get("track_id")
|
|
|
|
trackIDStr := r.URL.Query().Get("track_id")
|
|
|
|
|
|
|
|
|
|
|
|
if artistIDStr == "" && albumIDStr == "" && trackIDStr == "" {
|
|
|
|
if alias == "" || (artistIDStr == "" && albumIDStr == "" && trackIDStr == "") {
|
|
|
|
utils.WriteError(w, "artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
l.Debug().Msgf("Request is missing required parameters")
|
|
|
|
|
|
|
|
utils.WriteError(w, "alias and artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is has more than one of artist_id, album_id, and track_id")
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
alias := r.FormValue("alias")
|
|
|
|
|
|
|
|
if alias == "" {
|
|
|
|
|
|
|
|
utils.WriteError(w, "alias must be provided", http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if artistIDStr != "" {
|
|
|
|
if artistIDStr != "" {
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Invalid artist id")
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SaveArtistAliases(ctx, int32(artistID), []string{alias}, "Manual")
|
|
|
|
err = store.SaveArtistAliases(ctx, int32(artistID), []string{alias}, "Manual")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to save alias")
|
|
|
|
l.Err(fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Failed to save artist alias")
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Invalid album id")
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SaveAlbumAliases(ctx, int32(albumID), []string{alias}, "Manual")
|
|
|
|
err = store.SaveAlbumAliases(ctx, int32(albumID), []string{alias}, "Manual")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to save alias")
|
|
|
|
l.Err(fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Failed to save album alias")
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Invalid track id")
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SaveTrackAliases(ctx, int32(trackID), []string{alias}, "Manual")
|
|
|
|
err = store.SaveTrackAliases(ctx, int32(trackID), []string{alias}, "Manual")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to save alias")
|
|
|
|
l.Err(fmt.Errorf("CreateAliasHandler: %w", err)).Msg("Failed to save track alias")
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to save alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -212,6 +238,8 @@ func SetPrimaryAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
ctx := r.Context()
|
|
|
|
ctx := r.Context()
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
l := logger.FromContext(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Debug().Msgf("SetPrimaryAliasHandler: Got request with params: '%s'", r.URL.Query().Encode())
|
|
|
|
|
|
|
|
|
|
|
|
// Parse query parameters
|
|
|
|
// Parse query parameters
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
artistIDStr := r.URL.Query().Get("artist_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
albumIDStr := r.URL.Query().Get("album_id")
|
|
|
|
@ -219,47 +247,52 @@ func SetPrimaryAliasHandler(store db.DB) http.HandlerFunc {
|
|
|
|
alias := r.URL.Query().Get("alias")
|
|
|
|
alias := r.URL.Query().Get("alias")
|
|
|
|
|
|
|
|
|
|
|
|
if alias == "" || (artistIDStr == "" && albumIDStr == "" && trackIDStr == "") {
|
|
|
|
if alias == "" || (artistIDStr == "" && albumIDStr == "" && trackIDStr == "") {
|
|
|
|
|
|
|
|
l.Debug().Msgf("Request is missing required parameters")
|
|
|
|
utils.WriteError(w, "alias and artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "alias and artist_id, album_id, or track_id must be provided", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
if utils.MoreThanOneString(artistIDStr, albumIDStr, trackIDStr) {
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided", http.StatusBadRequest)
|
|
|
|
l.Debug().Msgf("Request is has more than one of artist_id, album_id, and track_id")
|
|
|
|
|
|
|
|
utils.WriteError(w, "only one of artist_id, album_id, or track_id can be provided at a time", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if artistIDStr != "" {
|
|
|
|
if artistIDStr != "" {
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
artistID, err := strconv.Atoi(artistIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Invalid artist id")
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid artist_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SetPrimaryArtistAlias(ctx, int32(artistID), alias)
|
|
|
|
err = store.SetPrimaryArtistAlias(ctx, int32(artistID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to set primary alias")
|
|
|
|
l.Err(fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Failed to set artist primary alias")
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
} else if albumIDStr != "" {
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
albumID, err := strconv.Atoi(albumIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Invalid album id")
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid album_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SetPrimaryAlbumAlias(ctx, int32(albumID), alias)
|
|
|
|
err = store.SetPrimaryAlbumAlias(ctx, int32(albumID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to set primary alias")
|
|
|
|
l.Err(fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Failed to set album primary alias")
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
} else if trackIDStr != "" {
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
trackID, err := strconv.Atoi(trackIDStr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
l.Debug().AnErr("error", fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Invalid track id")
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
utils.WriteError(w, "invalid track_id", http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = store.SetPrimaryTrackAlias(ctx, int32(trackID), alias)
|
|
|
|
err = store.SetPrimaryTrackAlias(ctx, int32(trackID), alias)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
l.Err(err).Msg("Failed to set primary alias")
|
|
|
|
l.Err(fmt.Errorf("SetPrimaryAliasHandler: %w", err)).Msg("Failed to set track primary alias")
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
utils.WriteError(w, "failed to set primary alias", http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|