Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Unhardcode booked margin
Browse files Browse the repository at this point in the history
Well, just move the hardcoded values. This will be useful for ad-hoc
bookings and also one step closer to being fully configurable.
  • Loading branch information
zdevaty committed May 9, 2024
1 parent ca0d948 commit 819a331
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 5 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+`
Expand All @@ -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+`
Expand Down

0 comments on commit 819a331

Please sign in to comment.