feat(launcher): implement modpack manifest API endpoint

This commit is contained in:
2025-06-18 13:16:57 +03:00
parent ca182d6d6f
commit a157fc1cc3
4 changed files with 84 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
package api
import (
"encoding/json"
"errors"
"net/http"
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
"github.com/go-chi/chi/v5"
"github.com/jackc/pgx/v5"
)
type LauncherHandler struct {
ModpackRepo *database.ModpackRepository
}
func (h *LauncherHandler) GetModpackManifest(w http.ResponseWriter, r *http.Request) {
modpackName := chi.URLParam(r, "name")
if modpackName == "" {
http.Error(w, "Modpack name is required", http.StatusBadRequest)
return
}
manifest, err := h.ModpackRepo.GetModpackManifest(r.Context(), modpackName)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
http.Error(w, "Modpack not found or not active", http.StatusNotFound)
return
}
http.Error(w, "Failed to get modpack manifest", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(manifest)
}