add base handler and refactor H
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type H map[string]any
|
||||
|
||||
type MeteoData struct {
|
||||
Timestamp time.Time `csv:"fecha"`
|
||||
Location string `csv:"ciudad"`
|
||||
@@ -29,18 +27,52 @@ type FileStats struct {
|
||||
FileChecksum string `json:"file_checksum"`
|
||||
}
|
||||
|
||||
type GetMeteoData struct {
|
||||
Location string
|
||||
From string
|
||||
To string
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (mt *GetMeteoData) Validate() error {
|
||||
if mt.Location == "" {
|
||||
return ErrMissingOrInvalidLocation
|
||||
}
|
||||
|
||||
if mt.From == "" {
|
||||
return ErrMissingOrInvalidFromDate
|
||||
}
|
||||
|
||||
if mt.To == "" {
|
||||
return ErrMissingOrInvalidToDate
|
||||
}
|
||||
|
||||
if _, err := time.Parse("2006-01-02", mt.From); err != nil {
|
||||
return ErrMissingOrInvalidFromDate
|
||||
}
|
||||
|
||||
if _, err := time.Parse("2006-01-02", mt.To); err != nil {
|
||||
return ErrMissingOrInvalidToDate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrCannotParseFile = errors.New("cannot parse file")
|
||||
ErrValidateRecord = errors.New("error validating record")
|
||||
ErrRecordNotValid = errors.New("record not valid")
|
||||
ErrReadingCSVHeader = errors.New("error reading CSV header")
|
||||
ErrReadingCSVRow = errors.New("error reading CSV row")
|
||||
ErrMissingOrInvalidDateField = errors.New("missing or invalid date field")
|
||||
ErrMissingOrInvalidCityField = errors.New("missing or invalid city field")
|
||||
ErrMissingOrInvalidMaxTemp = errors.New("missing or invalid max temp field")
|
||||
ErrMissingOrInvalidMinTemp = errors.New("missing or invalid min temp field")
|
||||
ErrMissingOrInvalidRainfall = errors.New("missing or invalid rainfall field")
|
||||
ErrMissingOrInvalidCloudiness = errors.New("missing or invalid cloudiness field")
|
||||
ErrMissingOrInvalidDate = errors.New("missing or invalid date")
|
||||
ErrMissingOrInvalidFromDate = errors.New("missing or invalid from date")
|
||||
ErrMissingOrInvalidToDate = errors.New("missing or invalid to date")
|
||||
ErrMissingOrInvalidLocation = errors.New("missing or invalid location")
|
||||
ErrMissingOrInvalidMaxTemp = errors.New("missing or invalid max temp")
|
||||
ErrMissingOrInvalidMinTemp = errors.New("missing or invalid min temp")
|
||||
ErrMissingOrInvalidRainfall = errors.New("missing or invalid rainfall")
|
||||
ErrMissingOrInvalidCloudiness = errors.New("missing or invalid cloudiness")
|
||||
ErrMaxTempOutOfRange = errors.New("max temp out of range (must be <= 60°C)")
|
||||
ErrMinTempOutOfRange = errors.New("min temp out of range (must be >= -20°C)")
|
||||
ErrRainfallOutOfRange = errors.New("rainfall out of range (must be 0-500 mm)")
|
||||
|
||||
Reference in New Issue
Block a user