Made forecast-period conditionCode optional
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
// Layer: adapters/outbound/postgres forecast feature.
|
||||
package postgres
|
||||
|
||||
import "gitea.maximumdirect.net/ejr/weatherfeeder/model"
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/weatherfeeder/model"
|
||||
)
|
||||
|
||||
func mapForecastParentRow(row forecastParentRow) model.WeatherForecastRun {
|
||||
return model.WeatherForecastRun{
|
||||
@@ -23,7 +27,7 @@ func mapForecastPeriodRow(row forecastPeriodRow) model.WeatherForecastPeriod {
|
||||
EndTime: row.EndTime.UTC(),
|
||||
Name: stringValue(row.Name),
|
||||
IsDay: boolPtr(row.IsDay),
|
||||
ConditionCode: model.WMOCode(row.ConditionCode),
|
||||
ConditionCode: wmoCodePtr(row.ConditionCode),
|
||||
TextDescription: stringValue(row.TextDescription),
|
||||
TemperatureC: float64Ptr(row.TemperatureC),
|
||||
TemperatureCMin: float64Ptr(row.TemperatureCMin),
|
||||
@@ -43,3 +47,11 @@ func mapForecastPeriodRow(row forecastPeriodRow) model.WeatherForecastPeriod {
|
||||
UVIndex: float64Ptr(row.UVIndex),
|
||||
}
|
||||
}
|
||||
|
||||
func wmoCodePtr(v sql.NullInt64) *model.WMOCode {
|
||||
if !v.Valid {
|
||||
return nil
|
||||
}
|
||||
out := model.WMOCode(v.Int64)
|
||||
return &out
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ type forecastPeriodRow struct {
|
||||
EndTime time.Time
|
||||
Name sql.NullString
|
||||
IsDay sql.NullBool
|
||||
ConditionCode int
|
||||
ConditionCode sql.NullInt64
|
||||
TextDescription sql.NullString
|
||||
TemperatureC sql.NullFloat64
|
||||
TemperatureCMin sql.NullFloat64
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestMapForecastPeriodRowNullables(t *testing.T) {
|
||||
period := mapForecastPeriodRow(forecastPeriodRow{
|
||||
StartTime: start,
|
||||
EndTime: end,
|
||||
ConditionCode: 80,
|
||||
ConditionCode: sql.NullInt64{Int64: 80, Valid: true},
|
||||
Name: sql.NullString{String: "Midnight", Valid: true},
|
||||
TemperatureC: sql.NullFloat64{Float64: 12.5, Valid: true},
|
||||
TemperatureCMin: sql.NullFloat64{Valid: false},
|
||||
@@ -84,6 +84,21 @@ func TestMapForecastPeriodRowNullables(t *testing.T) {
|
||||
if !period.StartTime.Equal(start) || !period.EndTime.Equal(end) {
|
||||
t.Fatalf("unexpected time range: %s - %s", period.StartTime, period.EndTime)
|
||||
}
|
||||
if period.ConditionCode == nil || *period.ConditionCode != 80 {
|
||||
t.Fatalf("expected condition code pointer 80, got %v", period.ConditionCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapForecastPeriodRowConditionCodeNullable(t *testing.T) {
|
||||
period := mapForecastPeriodRow(forecastPeriodRow{
|
||||
StartTime: time.Date(2026, 3, 20, 0, 0, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2026, 3, 20, 1, 0, 0, 0, time.UTC),
|
||||
ConditionCode: sql.NullInt64{Valid: false},
|
||||
})
|
||||
|
||||
if period.ConditionCode != nil {
|
||||
t.Fatalf("expected nil condition code, got %v", period.ConditionCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapDiscussionParentRowNullables(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user