Files
backend/internal/api/server_handler.go

23 lines
505 B
Go

package api
import (
"encoding/json"
"net/http"
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
)
type ServerHandler struct {
Repo *database.ServerRepository
}
func (h *ServerHandler) GetServers(w http.ResponseWriter, r *http.Request) {
servers, err := h.Repo.GetAllWithStatus(r.Context())
if err != nil {
http.Error(w, "Failed to get servers", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(servers)
}