package handlers import ( "net/http" "github.com/andyleap/hnh-map/internal/app" ) // APIConfig handles GET /map/api/config. func (h *Handlers) APIConfig(rw http.ResponseWriter, req *http.Request) { ctx := req.Context() s := h.Auth.GetSession(ctx, req) if s == nil { JSONError(rw, http.StatusUnauthorized, "Unauthorized", "UNAUTHORIZED") return } config, err := h.Map.GetConfig(ctx, s.Auths) if err != nil { HandleServiceError(rw, err) return } JSON(rw, http.StatusOK, config) } // APIGetChars handles GET /map/api/v1/characters. func (h *Handlers) APIGetChars(rw http.ResponseWriter, req *http.Request) { ctx := req.Context() s := h.Auth.GetSession(ctx, req) if !h.canAccessMap(s) { JSONError(rw, http.StatusUnauthorized, "Unauthorized", "UNAUTHORIZED") return } if !s.Auths.Has(app.AUTH_MARKERS) && !s.Auths.Has(app.AUTH_ADMIN) { JSON(rw, http.StatusOK, []interface{}{}) return } chars := h.Map.GetCharacters() JSON(rw, http.StatusOK, chars) } // APIGetMarkers handles GET /map/api/v1/markers. func (h *Handlers) APIGetMarkers(rw http.ResponseWriter, req *http.Request) { ctx := req.Context() s := h.Auth.GetSession(ctx, req) if !h.canAccessMap(s) { JSONError(rw, http.StatusUnauthorized, "Unauthorized", "UNAUTHORIZED") return } if !s.Auths.Has(app.AUTH_MARKERS) && !s.Auths.Has(app.AUTH_ADMIN) { JSON(rw, http.StatusOK, []interface{}{}) return } markers, err := h.Map.GetMarkers(ctx) if err != nil { HandleServiceError(rw, err) return } JSON(rw, http.StatusOK, markers) } // APIGetMaps handles GET /map/api/maps. func (h *Handlers) APIGetMaps(rw http.ResponseWriter, req *http.Request) { ctx := req.Context() s := h.Auth.GetSession(ctx, req) if !h.canAccessMap(s) { JSONError(rw, http.StatusUnauthorized, "Unauthorized", "UNAUTHORIZED") return } showHidden := s.Auths.Has(app.AUTH_ADMIN) maps, err := h.Map.GetMaps(ctx, showHidden) if err != nil { HandleServiceError(rw, err) return } JSON(rw, http.StatusOK, maps) }