From 5560fad92e5ebcf1bc58927b1e1bc1295dd8b271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Tue, 28 Oct 2025 23:39:13 +0100 Subject: [PATCH] add logs --- service_a/internal/domains/meteo/domain.go | 12 ++++++------ service_a/internal/domains/meteo/handlers.go | 9 ++++++++- service_a/internal/domains/meteo/router.go | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/service_a/internal/domains/meteo/domain.go b/service_a/internal/domains/meteo/domain.go index 62e599c..26ac2a5 100644 --- a/service_a/internal/domains/meteo/domain.go +++ b/service_a/internal/domains/meteo/domain.go @@ -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 { diff --git a/service_a/internal/domains/meteo/handlers.go b/service_a/internal/domains/meteo/handlers.go index 9907766..20213fc 100644 --- a/service_a/internal/domains/meteo/handlers.go +++ b/service_a/internal/domains/meteo/handlers.go @@ -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 } diff --git a/service_a/internal/domains/meteo/router.go b/service_a/internal/domains/meteo/router.go index f773628..5b7bd71 100644 --- a/service_a/internal/domains/meteo/router.go +++ b/service_a/internal/domains/meteo/router.go @@ -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) }