add read raw meteo data

This commit is contained in:
2025-10-28 23:21:42 +01:00
parent e0024cc257
commit b38e77218e
3 changed files with 16 additions and 7 deletions
+13 -5
View File
@@ -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
}