diff --git a/app.go b/app.go index f530a72..758334b 100644 --- a/app.go +++ b/app.go @@ -23,6 +23,7 @@ import ( "context" "net/http" "strconv" + "time" api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2" "github.com/eliona-smart-building-assistant/go-eliona/app" @@ -157,7 +158,9 @@ func processNoShow() error { func updateOccupancy() error { ctx := context.Background() - bookedAssets, err := conf.GetBookedAssetIDs(ctx) + since := time.Now() + until := since.Add(30 * time.Minute) + bookedAssets, err := conf.GetBookedAssetIDs(ctx, since, until) if err != nil { log.Error("conf", "getting booked asset IDs: %v", err) return err @@ -166,7 +169,7 @@ func updateOccupancy() error { log.Error("eliona", "setting booked assets: %v", err) return err } - unbookedAssets, err := conf.GetUnbookedAssetIDs(ctx) + unbookedAssets, err := conf.GetUnbookedAssetIDs(ctx, since, until) if err != nil { log.Error("conf", "getting booked asset IDs: %v", err) return err diff --git a/conf/conf.go b/conf/conf.go index e91b7d8..d63b4f8 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -291,9 +291,7 @@ const bookedAsssetsCTE = ` AND e.end_time >= $2 )` -func GetBookedAssetIDs(ctx context.Context) ([]int32, error) { - since := time.Now() - until := since.Add(30 * time.Minute) +func GetBookedAssetIDs(ctx context.Context, since, until time.Time) ([]int32, error) { var assetIDs []*AssetID if err := queries. RawG(bookedAsssetsCTE+` @@ -310,9 +308,7 @@ func GetBookedAssetIDs(ctx context.Context) ([]int32, error) { return ids, nil } -func GetUnbookedAssetIDs(ctx context.Context) ([]int32, error) { - since := time.Now() - until := since.Add(30 * time.Minute) +func GetUnbookedAssetIDs(ctx context.Context, since, until time.Time) ([]int32, error) { var assetIDs []*AssetID if err := queries. RawG(bookedAsssetsCTE+`