Skip to content

Commit

Permalink
Allow updating events from EWS
Browse files Browse the repository at this point in the history
  • Loading branch information
zdevaty committed Apr 5, 2024
1 parent fe8db20 commit efadfc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func collectResources(config apiserver.Configuration) error {
var changedBookings []model.Booking

for _, ast := range assets {
fmt.Println(ast.ProviderID)
if !ast.AssetID.Valid {
continue
}
Expand All @@ -161,12 +162,14 @@ func collectResources(config apiserver.Configuration) error {
for i := range appointments {
appointments[i].AssetID = ast.AssetID.Int32
a := appointments[i]

fmt.Println(a.ExchangeID)
booking, err := conf.GetBookingByExchangeID(a.ExchangeID)
if err != nil && !errors.Is(err, conf.ErrNotFound) {
log.Error("conf", "getting booking for exchange ID %s: %v", a.ExchangeID, err)
return err
} else if errors.Is(err, conf.ErrNotFound) {
fmt.Println("booking new")

// Booking is new
newBookings = append(newBookings, a)

Expand All @@ -185,11 +188,13 @@ func collectResources(config apiserver.Configuration) error {
}

if booking.ExchangeChangeKey.String != a.ExchangeChangeKey {
fmt.Println("booking changed")
// Booking has changed.
if !booking.BookingID.Valid {
// Booking not yet synced to Eliona
newBookings = append(newBookings, a)
}
a.ElionaID = booking.BookingID.Int32
changedBookings = append(changedBookings, a)
booking.ExchangeChangeKey = null.StringFrom(a.ExchangeChangeKey)
err := conf.UpdateBooking(booking)
Expand All @@ -204,12 +209,15 @@ func collectResources(config apiserver.Configuration) error {
continue
}
}
// todo: unhardcode
bc := booking.NewClient("http://localhost:3031/v1")
if err := bc.Book(newBookings); err != nil {
log.Error("Booking", "booking appointments: %v", err)
log.Error("Booking", "booking: %v", err)
}

// todo: changedBookings
if err := bc.Book(changedBookings); err != nil {
log.Error("Booking", "updating bookings: %v", err)
}

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions booking/booking.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ func NewClient(baseURL string) *client {
}

func (c *client) Book(bookings []model.Booking) error {
fmt.Println(bookings)
var convertedBookings []bookingRequest
for _, b := range bookings {
convertedBookings = append(convertedBookings, bookingRequest{
BookingID: b.ElionaID,
AssetIds: []int{int(b.AssetID)},
OrganizerID: b.OrganizerEmail,
Start: b.Start,
Expand All @@ -38,6 +40,7 @@ func (c *client) Book(bookings []model.Booking) error {
}

type bookingRequest struct {
BookingID int32 `json:"bookingID"`
AssetIds []int `json:"assetIds"`
OrganizerID string `json:"organizerID"`
Start time.Time `json:"start"`
Expand Down

0 comments on commit efadfc1

Please sign in to comment.