-
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.
Add #274 Process webhooks in goroutine
Signed-off-by: George J Padayatti <[email protected]>
- Loading branch information
1 parent
38671dc
commit ff10611
Showing
5 changed files
with
391 additions
and
111 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
File renamed without changes.
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,38 @@ | ||
package webhook_dispatcher | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/bb-consent/api/src/database" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
func webhookCollection() *mongo.Collection { | ||
return database.DB.Client.Database(database.DB.Name).Collection("webhooks") | ||
} | ||
|
||
func webhookDeliveryCollection() *mongo.Collection { | ||
return database.DB.Client.Database(database.DB.Name).Collection("webhookDeliveries") | ||
} | ||
|
||
// GetWebhookByOrgID Gets a webhook by organisation ID and webhook ID | ||
func GetWebhookByOrgID(webhookId, orgID string) (result Webhook, err error) { | ||
|
||
err = webhookCollection().FindOne(context.TODO(), bson.M{"_id": webhookId, "orgid": orgID}).Decode(&result) | ||
|
||
return result, err | ||
} | ||
|
||
// AddWebhookDelivery Adds payload delivery details to database for a webhook event | ||
func AddWebhookDelivery(webhookDelivery WebhookDelivery) (WebhookDelivery, error) { | ||
|
||
if webhookDelivery.ID == primitive.NilObjectID { | ||
webhookDelivery.ID = primitive.NewObjectID() | ||
} | ||
|
||
_, err := webhookDeliveryCollection().InsertOne(context.TODO(), &webhookDelivery) | ||
|
||
return webhookDelivery, err | ||
} |
Oops, something went wrong.