mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
feat(api): support prefixed IDs in routes and add unified mappers scaffolding
- Handlers parse IDs like kp_123 / tmdb_456 and set id_type accordingly - Add KP->Unified and TMDB->Unified movie mappers (basic fields) - Keep backward compatibility for numeric IDs
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -47,14 +48,39 @@ func (h *TVHandler) Search(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (h *TVHandler) GetByID(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id, err := strconv.Atoi(vars["id"])
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid TV show ID", http.StatusBadRequest)
|
||||
return
|
||||
rawID := vars["id"]
|
||||
|
||||
// Support formats: "123" (old), "kp_123", "tmdb_123"
|
||||
source := ""
|
||||
var id int
|
||||
if strings.Contains(rawID, "_") {
|
||||
parts := strings.SplitN(rawID, "_", 2)
|
||||
if len(parts) != 2 {
|
||||
http.Error(w, "Invalid ID format", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
source = parts[0]
|
||||
parsed, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid numeric ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
id = parsed
|
||||
} else {
|
||||
// Backward compatibility
|
||||
parsed, err := strconv.Atoi(rawID)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid TV show ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
id = parsed
|
||||
}
|
||||
|
||||
language := GetLanguage(r)
|
||||
idType := r.URL.Query().Get("id_type") // kp or tmdb
|
||||
idType := r.URL.Query().Get("id_type")
|
||||
if source == "kp" || source == "tmdb" {
|
||||
idType = source
|
||||
}
|
||||
|
||||
tvShow, err := h.tvService.GetByID(id, language, idType)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user