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")
ErrRetrievingFile = errors.New("error retrieving file")
ErrReadingFile = errors.New("error reading file")
ErrReadingData = errors.New("error reading data")
)

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
}

View File

@ -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)
}