This commit is contained in:
Pedro Pérez 2025-10-28 23:39:13 +01:00
parent b38e77218e
commit 5560fad92e
3 changed files with 15 additions and 7 deletions

View File

@ -6,12 +6,12 @@ import (
)
type MeteoData struct {
Timestamp time.Time `csv:"fecha"`
Location string `csv:"ciudad"`
MaxTemp float32 `csv:"temperatura maxima"`
MinTemp float32 `csv:"temperatura minima"`
Rainfall float32 `csv:"precipitacion"`
Cloudiness int `csv:"nubosidad"`
Timestamp time.Time `csv:"fecha" json:"timestamp"`
Location string `csv:"ciudad" json:"location"`
MaxTemp float32 `csv:"temperatura maxima" json:"max_temp"`
MinTemp float32 `csv:"temperatura minima" json:"min_temp"`
Rainfall float32 `csv:"precipitacion" json:"rainfall"`
Cloudiness int `csv:"nubosidad" json:"cloudiness"`
}
type RejectedMeteoData struct {

View File

@ -70,6 +70,7 @@ func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) {
"elapsed_ms", fileStats.ElapsedMS,
"file_checksum", fileStats.FileChecksum,
)
h.ToJSON(w, http.StatusOK, app.H{"stats": fileStats})
}
@ -77,6 +78,9 @@ func (h *Handler) IngestExcel(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello from excel")
}
func (h *Handler) GetCities(w http.ResponseWriter, r *http.Request) {
}
func (h *Handler) GetMeteoData(w http.ResponseWriter, r *http.Request) {
queryParams := r.URL.Query()
@ -89,16 +93,19 @@ func (h *Handler) GetMeteoData(w http.ResponseWriter, r *http.Request) {
}
if err := params.Validate(); err != nil {
slog.Error("Error validating struct", "error", err)
h.ToJSON(w, http.StatusBadRequest, app.H{"error": err.Error()})
return
}
meteoData, err := h.s.GetMeteoData(r.Context(), params)
if err != nil {
slog.Error(ErrReadingData.Error(), "error", err)
h.ToJSON(w, http.StatusNotFound, app.H{"error": ErrReadingData.Error()})
return
}
slog.Info("Data retrieved", "location", params.Location)
h.ToJSON(w, http.StatusOK, app.H{"meteo_data": meteoData})
return
}

View File

@ -6,5 +6,6 @@ func RegisterRoutes(mux *http.ServeMux, handler *Handler) {
mux.HandleFunc("POST /ingest/csv", handler.IngestCSV)
mux.HandleFunc("POST /ingest/excel", handler.IngestExcel)
mux.HandleFunc("GET /cities", handler.GetCities)
mux.HandleFunc("GET /data", handler.GetMeteoData)
}