This commit is contained in:
Alexander
2026-04-29 17:29:58 +02:00
parent 3ecc6aee62
commit 945aab82c2
24 changed files with 2038 additions and 822 deletions
+47
View File
@@ -0,0 +1,47 @@
package api
import (
"encoding/json"
"net/http"
"github.com/fujin/music-agregator/internal/indexer"
)
func (h *Handlers) ListIndexers(w http.ResponseWriter, r *http.Request) {
indexers := h.IndexerService.GetIndexers(r.Context())
writeJSON(w, http.StatusOK, indexers)
}
func (h *Handlers) SearchIndexers(w http.ResponseWriter, r *http.Request) {
var req struct {
Artist string `json:"artist"`
Album *string `json:"album,omitempty"`
Year *uint32 `json:"year,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "invalid request body")
return
}
if req.Limit == 0 {
req.Limit = 20
}
criteria := &indexer.MusicSearchCriteria{
Artist: req.Artist,
Album: req.Album,
Year: req.Year,
Limit: req.Limit,
Offset: req.Offset,
}
results, err := h.IndexerService.Search(r.Context(), criteria, nil)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
writeJSON(w, http.StatusOK, results)
}