add read raw meteo data

This commit is contained in:
Pedro Pérez 2025-10-28 23:21:42 +01:00
parent e0024cc257
commit b38e77218e
3 changed files with 16 additions and 7 deletions

View File

@ -83,4 +83,5 @@ var (
ErrParsingForm = errors.New("error parsing form") ErrParsingForm = errors.New("error parsing form")
ErrRetrievingFile = errors.New("error retrieving file") ErrRetrievingFile = errors.New("error retrieving file")
ErrReadingFile = errors.New("error reading file") ErrReadingFile = errors.New("error reading file")
ErrReadingData = errors.New("error reading data")
) )

View File

@ -15,12 +15,12 @@ import (
type Handler struct { type Handler struct {
domains.BaseHandler domains.BaseHandler
*Service s *Service
} }
func NewHandler(service *Service) *Handler { func NewHandler(service *Service) *Handler {
return &Handler{ return &Handler{
Service: service, s: service,
} }
} }
@ -52,7 +52,7 @@ func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) {
} }
start := time.Now() 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 { if err != nil {
slog.Error(ErrCannotParseFile.Error(), slog.Error(ErrCannotParseFile.Error(),
"filename", header.Filename, "filename", header.Filename,
@ -61,7 +61,7 @@ func (h *Handler) IngestCSV(w http.ResponseWriter, r *http.Request) {
return return
} }
fileStats.ElapsedMS = int(time.Since(start).Milliseconds()) 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", slog.Info("CSV file processed",
"filename", header.Filename, "filename", header.Filename,
@ -90,7 +90,15 @@ func (h *Handler) GetMeteoData(w http.ResponseWriter, r *http.Request) {
if err := params.Validate(); err != nil { if err := params.Validate(); err != nil {
h.ToJSON(w, http.StatusBadRequest, app.H{"error": err.Error()}) 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
} }

View File

@ -49,6 +49,6 @@ func (s *Service) UpdateElapsedMS(ctx context.Context, batchID, elapsedMS int) e
return nil return nil
} }
func (s *Service) GetMeteoData(params GetMeteoData) ([]MeteoData, error) { func (s *Service) GetMeteoData(ctx context.Context, params GetMeteoData) ([]MeteoData, error) {
return []MeteoData{}, nil return s.repo.GetMeteoData(ctx, params)
} }