mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-18 03:36:35 -07:00
chore: initial public commit
This commit is contained in:
commit
fc9054b78c
250 changed files with 32809 additions and 0 deletions
97
engine/handlers/merge.go
Normal file
97
engine/handlers/merge.go
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gabehf/koito/internal/db"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
"github.com/gabehf/koito/internal/utils"
|
||||
)
|
||||
|
||||
func MergeTracksHandler(store db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := logger.FromContext(r.Context())
|
||||
|
||||
fromidStr := r.URL.Query().Get("from_id")
|
||||
fromId, err := strconv.Atoi(fromidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "from_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
toidStr := r.URL.Query().Get("to_id")
|
||||
toId, err := strconv.Atoi(toidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "to_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.MergeTracks(r.Context(), int32(fromId), int32(toId))
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "Failed to merge tracks: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
func MergeReleaseGroupsHandler(store db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := logger.FromContext(r.Context())
|
||||
|
||||
fromidStr := r.URL.Query().Get("from_id")
|
||||
fromId, err := strconv.Atoi(fromidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "from_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
toidStr := r.URL.Query().Get("to_id")
|
||||
toId, err := strconv.Atoi(toidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "to_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.MergeAlbums(r.Context(), int32(fromId), int32(toId))
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "Failed to merge albums: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
func MergeArtistsHandler(store db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := logger.FromContext(r.Context())
|
||||
|
||||
fromidStr := r.URL.Query().Get("from_id")
|
||||
fromId, err := strconv.Atoi(fromidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "from_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
toidStr := r.URL.Query().Get("to_id")
|
||||
toId, err := strconv.Atoi(toidStr)
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "to_id is invalid", 400)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.MergeArtists(r.Context(), int32(fromId), int32(toId))
|
||||
if err != nil {
|
||||
l.Err(err).Send()
|
||||
utils.WriteError(w, "Failed to merge artists: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue