From b38e77218e6efc75f5e7628e0a4a559ab3aea976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Tue, 28 Oct 2025 23:21:42 +0100 Subject: [PATCH] add read raw meteo data --- service_a/internal/domains/meteo/domain.go | 1 + service_a/internal/domains/meteo/handlers.go | 18 +++++++++++++----- service_a/internal/domains/meteo/service.go | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/service_a/internal/domains/meteo/domain.go b/service_a/internal/domains/meteo/domain.go index 779f9fe..62e599c 100644 --- a/service_a/internal/domains/meteo/domain.go +++ b/service_a/internal/domains/meteo/domain.go @@ -83,4 +83,5 @@ var ( ErrParsingForm = errors.New("error parsing form") ErrRetrievingFile = errors.New("error retrieving file") ErrReadingFile = errors.New("error reading file") + ErrReadingData = errors.New("error reading data") ) diff --git a/service_a/internal/domains/meteo/handlers.go b/service_a/internal/domains/meteo/handlers.go index 2593ba2..9907766 100644 --- a/service_a/internal/domains/meteo/handlers.go +++ b/service_a/internal/domains/meteo/handlers.go @@ -15,12 +15,12 @@ import ( type Handler struct { domains.BaseHandler - *Service + s *Service } func NewHandler(service *Service) *Handler { return &Handler{ - Service: service, + s: service, } } @@ -52,7 +52,7 @@ func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) { } start := time.Now() - err = h.Service.IngestCSV(r.Context(), bytes.NewReader(content), fileStats) + err = h.s.IngestCSV(r.Context(), bytes.NewReader(content), fileStats) if err != nil { slog.Error(ErrCannotParseFile.Error(), "filename", header.Filename, @@ -61,7 +61,7 @@ func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) { return } fileStats.ElapsedMS = int(time.Since(start).Milliseconds()) - h.UpdateElapsedMS(r.Context(), fileStats.BatchID, fileStats.ElapsedMS) + h.s.UpdateElapsedMS(r.Context(), fileStats.BatchID, fileStats.ElapsedMS) slog.Info("CSV file processed", "filename", header.Filename, @@ -90,7 +90,15 @@ func (h *Handler) GetMeteoData(w http.ResponseWriter, r *http.Request) { if err := params.Validate(); err != nil { h.ToJSON(w, http.StatusBadRequest, app.H{"error": err.Error()}) + return } - slog.Info("params", "params", params) + meteoData, err := h.s.GetMeteoData(r.Context(), params) + if err != nil { + h.ToJSON(w, http.StatusNotFound, app.H{"error": ErrReadingData.Error()}) + return + } + + h.ToJSON(w, http.StatusOK, app.H{"meteo_data": meteoData}) + return } diff --git a/service_a/internal/domains/meteo/service.go b/service_a/internal/domains/meteo/service.go index 016dd05..7c64775 100644 --- a/service_a/internal/domains/meteo/service.go +++ b/service_a/internal/domains/meteo/service.go @@ -49,6 +49,6 @@ func (s *Service) UpdateElapsedMS(ctx context.Context, batchID, elapsedMS int) e return nil } -func (s *Service) GetMeteoData(params GetMeteoData) ([]MeteoData, error) { - return []MeteoData{}, nil +func (s *Service) GetMeteoData(ctx context.Context, params GetMeteoData) ([]MeteoData, error) { + return s.repo.GetMeteoData(ctx, params) }