From efadfc1fae316a9339bc5a6eedc299fe00e22aee Mon Sep 17 00:00:00 2001 From: Zdenek Devaty Date: Fri, 5 Apr 2024 20:04:18 +0200 Subject: [PATCH] Allow updating events from EWS --- app.go | 14 +++++++++++--- booking/booking.go | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 933c863..9e8ee4f 100644 --- a/app.go +++ b/app.go @@ -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 } @@ -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) @@ -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) @@ -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 } diff --git a/booking/booking.go b/booking/booking.go index bc93fb8..8aa1478 100644 --- a/booking/booking.go +++ b/booking/booking.go @@ -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, @@ -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"`