Skip to content

Commit

Permalink
Fix current version constants for other structs
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmclean committed Sep 3, 2024
1 parent fc9c710 commit b066d8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion garden-app/pkg/garden.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
HealthStatusDown HealthStatus = "DOWN"
HealthStatusUp HealthStatus = "UP"
HealthStatusUnknown HealthStatus = "N/A"

currentGardenVersion = uint(1)
)

// Garden is the representation of a single garden-controller device
Expand Down Expand Up @@ -173,7 +175,7 @@ func (g *Garden) Bind(r *http.Request) error {
fallthrough
case http.MethodPut:
if g.Version == 0 {
g.Version = currentVersion
g.Version = currentGardenVersion
}
if g.CreatedAt == nil || g.CreatedAt.IsZero() {
g.CreatedAt = &now
Expand Down
4 changes: 3 additions & 1 deletion garden-app/pkg/water_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/rs/xid"
)

const currentWaterScheduleVersion = uint(1)

// WaterSchedule allows the user to have more control over how the Zone is watered using an Interval
// and optional MinimumMoisture which acts as the threshold the Zone's soil should be above.
// StartTime specifies when the watering interval should originate from. It can be used to increase/decrease delays in watering.
Expand Down Expand Up @@ -248,7 +250,7 @@ func (ws *WaterSchedule) Bind(r *http.Request) error {
switch r.Method {
case http.MethodPut, http.MethodPost:
if ws.Version == 0 {
ws.Version = currentVersion
ws.Version = currentWaterScheduleVersion
}
if ws.Interval == nil {
return errors.New("missing required interval field")
Expand Down
4 changes: 2 additions & 2 deletions garden-app/pkg/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rs/xid"
)

const currentVersion = uint(1)
const currentZoneVersion = uint(1)

// Zone represents a "waterable resource" that is owned by a Garden..
// This allows for more complex Garden setups where a large irrigation system will be watering entire groups of
Expand Down Expand Up @@ -153,7 +153,7 @@ func (z *Zone) Bind(r *http.Request) error {
fallthrough
case http.MethodPut:
if z.Version == 0 {
z.Version = currentVersion
z.Version = currentZoneVersion
}
if z.CreatedAt == nil || z.CreatedAt.IsZero() {
z.CreatedAt = &now
Expand Down

0 comments on commit b066d8f

Please sign in to comment.