推进活动系统最小成品闭环与游客体验
This commit is contained in:
41
backend/internal/httpapi/handlers/map_experience_handler.go
Normal file
41
backend/internal/httpapi/handlers/map_experience_handler.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"cmr-backend/internal/httpx"
|
||||
"cmr-backend/internal/service"
|
||||
)
|
||||
|
||||
type MapExperienceHandler struct {
|
||||
service *service.MapExperienceService
|
||||
}
|
||||
|
||||
func NewMapExperienceHandler(service *service.MapExperienceService) *MapExperienceHandler {
|
||||
return &MapExperienceHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *MapExperienceHandler) ListMaps(w http.ResponseWriter, r *http.Request) {
|
||||
limit := 20
|
||||
if raw := r.URL.Query().Get("limit"); raw != "" {
|
||||
if parsed, err := strconv.Atoi(raw); err == nil {
|
||||
limit = parsed
|
||||
}
|
||||
}
|
||||
result, err := h.service.ListMaps(r.Context(), service.ListExperienceMapsInput{Limit: limit})
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
|
||||
func (h *MapExperienceHandler) GetMapDetail(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := h.service.GetMapDetail(r.Context(), r.PathValue("mapAssetPublicID"))
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
Reference in New Issue
Block a user