This repository has been archived by the owner on May 22, 2024. It is now read-only.
generated from eliona-smart-building-assistant/app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package eliona | ||
|
||
import ( | ||
"booking-app/apiserver" | ||
"context" | ||
"fmt" | ||
|
||
api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2" | ||
"github.com/eliona-smart-building-assistant/go-eliona/client" | ||
) | ||
|
||
func NotifyUser(ctx context.Context, booking apiserver.Booking, reason string) error { | ||
ctx = client.AuthenticationContextWrap(ctx) | ||
for _, assetID := range booking.AssetIds { | ||
asset, _, err := client.NewClient().AssetsAPI.GetAssetById(ctx, assetID).Execute() | ||
if err != nil { | ||
return fmt.Errorf("fetching asset id %v: %v", assetID, err) | ||
} | ||
assetName := *asset.Name.Get() | ||
bookingStart := booking.Start.Format("Mon 02.01 15:04") | ||
var message api.Translation | ||
switch reason { | ||
case "conflict": | ||
message = api.Translation{ | ||
De: api.PtrString(fmt.Sprintf( | ||
"Ihre Buchung von Asset %s ab %s wurde aufgrund eines Zeitkonflikts storniert. Bitte buchen Sie neu.", | ||
assetName, bookingStart, | ||
)), | ||
En: api.PtrString(fmt.Sprintf( | ||
"Your booking of asset %s starting at %s got cancelled due to a time conflict. Please rebook.", | ||
assetName, bookingStart, | ||
)), | ||
} | ||
default: | ||
return fmt.Errorf("Unknown reason: %v", reason) | ||
} | ||
_, _, err = client.NewClient().CommunicationAPI. | ||
PostNotification(client.AuthenticationContext()). | ||
Notification( | ||
api.Notification{ | ||
User: booking.OrganizerID, | ||
ProjectId: *api.NewNullableString(&asset.ProjectId), | ||
Message: *api.NewNullableTranslation(&message), | ||
}). | ||
Execute() | ||
if err != nil { | ||
return fmt.Errorf("posting cancel notification: %v", err) | ||
} | ||
} | ||
return nil | ||
} |