feat: Add SLD endpoints, add date_to to vector_with_kato
This commit is contained in:
@@ -74,15 +74,19 @@ type DatasetFilter struct {
|
||||
}
|
||||
|
||||
// Observation is a single unpivoted value from a dataset's attribute table,
|
||||
// keyed by KATO code and date. Exactly one of Value / ValueText is typically
|
||||
// set (numeric vs non-numeric cell); both may be nil for an empty cell.
|
||||
// keyed by KATO code and date (optionally a date..DateTo period). Exactly one
|
||||
// of Value / ValueText is typically set (numeric vs non-numeric cell); both
|
||||
// may be nil for an empty cell.
|
||||
type Observation struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
DatasetID uuid.UUID `json:"dataset_id"`
|
||||
KatoCode string `json:"kato_code"`
|
||||
Date string `json:"date"`
|
||||
Value *float64 `json:"value"`
|
||||
ValueText *string `json:"value_text"`
|
||||
// DateTo is the period's end date. Nil for a point-in-time observation
|
||||
// (pre-existing behavior).
|
||||
DateTo *string `json:"date_to,omitempty"`
|
||||
Value *float64 `json:"value"`
|
||||
ValueText *string `json:"value_text"`
|
||||
}
|
||||
|
||||
// allowedExtensions lists the accepted lowercase file extensions (including the
|
||||
@@ -134,10 +138,30 @@ func ValidateFileContent(ext string, head []byte) error {
|
||||
if b, ok := firstMeaningfulByte(head); !ok || b != '{' {
|
||||
return fmt.Errorf("file is not valid GeoJSON")
|
||||
}
|
||||
case ".sld", ".xml":
|
||||
// SLD is XML; a lightweight sniff for the opening tag.
|
||||
if b, ok := firstMeaningfulByte(head); !ok || b != '<' {
|
||||
return fmt.Errorf("file is not valid XML/SLD")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllowedSLDExtensions lists the accepted lowercase extensions (including the
|
||||
// dot) for a dataset's SLD (Styled Layer Descriptor) style file.
|
||||
var AllowedSLDExtensions = []string{".sld", ".xml"}
|
||||
|
||||
// ExtensionAllowedForSLD reports whether ext (lowercase, with dot) is a valid
|
||||
// SLD file extension.
|
||||
func ExtensionAllowedForSLD(ext string) bool {
|
||||
for _, e := range AllowedSLDExtensions {
|
||||
if e == ext {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// firstMeaningfulByte returns the first non-whitespace byte after an optional
|
||||
// UTF-8 BOM.
|
||||
func firstMeaningfulByte(head []byte) (byte, bool) {
|
||||
@@ -160,11 +184,15 @@ type AttributeColumn struct {
|
||||
Samples []string `json:"samples,omitempty"`
|
||||
}
|
||||
|
||||
// YearColumn maps an attribute column to the date it represents,
|
||||
// e.g. {"column": "F_2023", "date": "2023-01-01"}.
|
||||
// YearColumn maps an attribute column to the date (or date period) it
|
||||
// represents, e.g. {"column": "F_2023", "date": "2023-01-01"} for a single
|
||||
// point in time, or {"column": "F_2020_2023", "date": "2020-01-01", "date_to":
|
||||
// "2023-12-31"} for a period. DateTo is optional; when nil the mapping is a
|
||||
// single point in time, preserving the original (pre-period) behavior.
|
||||
type YearColumn struct {
|
||||
Column string `json:"column"`
|
||||
Date string `json:"date"`
|
||||
Column string `json:"column"`
|
||||
Date string `json:"date"`
|
||||
DateTo *string `json:"date_to,omitempty"`
|
||||
}
|
||||
|
||||
// DatasetSummary is the lightweight view of a dataset used in list responses.
|
||||
@@ -196,6 +224,11 @@ type Dataset struct {
|
||||
FileType FileType `json:"file_type"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
ContentType string `json:"content_type"`
|
||||
// SldStorageKey points to the dataset's SLD (Styled Layer Descriptor) style
|
||||
// file, if one has been uploaded. Nullable; applies to every file type.
|
||||
SldStorageKey *string `json:"sld_storage_key"`
|
||||
SldFilename *string `json:"sld_filename"`
|
||||
SldContentType *string `json:"sld_content_type"`
|
||||
// Properties holds tabular data extracted from the file (e.g. a shapefile's
|
||||
// attribute table). Nullable; not exposed in dataset responses.
|
||||
Properties json.RawMessage `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user