diff --git a/service/controllers/pco_webhook.go b/service/controllers/pco_webhook.go index c7a7027..d8c2b17 100644 --- a/service/controllers/pco_webhook.go +++ b/service/controllers/pco_webhook.go @@ -28,7 +28,7 @@ var ( type actionFunc func(*gin.Context, *webhooks.EventDelivery) error -func userIdFromContext(c *gin.Context) (*primitive.ObjectID) { +func userIdFromContext(c *gin.Context) *primitive.ObjectID { if id, ok := c.Get("user_bson_id"); !ok { userId := c.Param("userid") diff --git a/service/vendors/pco/webhooks.go b/service/vendors/pco/webhooks.go index eed9e03..3ab7060 100644 --- a/service/vendors/pco/webhooks.go +++ b/service/vendors/pco/webhooks.go @@ -9,7 +9,7 @@ import ( "github.com/google/jsonapi" ) -//gets all current subscriptions +// gets all current subscriptions func (api *PcoApiClient) GetSubscriptions() ([]webhooks.Subscription, error) { api.Url().Path = "/webhook/v2/subscriptions" @@ -35,7 +35,7 @@ func (api *PcoApiClient) GetSubscriptions() ([]webhooks.Subscription, error) { return subscriptions, nil } -//Posts subscriptions to PCO api and returns a new list of subscriptions +// Posts subscriptions to PCO api and returns a new list of subscriptions func (api *PcoApiClient) CreateSubscriptions(subscriptions []webhooks.Subscription) ([]webhooks.Subscription, error) { api.Url().Path = "/webhook/v2/subscriptions" @@ -67,8 +67,8 @@ func (api *PcoApiClient) CreateSubscriptions(subscriptions []webhooks.Subscripti return new_subscriptions, nil } -//Posts subcription to PCO api and updates the subscription at the pointer that was passed to the fuinction with the server response -func (api *PcoApiClient) CreateSubscription(subscription *webhooks.Subscription) (error) { +// Posts subcription to PCO api and updates the subscription at the pointer that was passed to the fuinction with the server response +func (api *PcoApiClient) CreateSubscription(subscription *webhooks.Subscription) error { api.Url().Path = "/webhook/v2/subscriptions" body := bytes.NewBuffer([]byte{}) @@ -91,7 +91,6 @@ func (api *PcoApiClient) CreateSubscription(subscription *webhooks.Subscription) return fmt.Errorf("Failed to retrieve plan with status code: %d", resp.StatusCode) } - err = jsonapi.UnmarshalPayload(resp.Body, subscription) if err != nil { return err diff --git a/service/vendors/pco/webhooks/subscription.go b/service/vendors/pco/webhooks/subscription.go index a196ac1..0d10d21 100644 --- a/service/vendors/pco/webhooks/subscription.go +++ b/service/vendors/pco/webhooks/subscription.go @@ -3,11 +3,11 @@ package webhooks import "time" type Subscription struct { - Id string `jsonapi:"primary,Subscription" bson:"id"` + Id string `jsonapi:"primary,Subscription" bson:"id"` //attrs Active bool `jsonapi:"attr,active,omitempty" bson:"active"` ApplicationId string `jsonapi:"attr,application_id,omitempty" bson:"application_id"` - AuthenticitySecret string `jsonapi:"attr,authenticity_secret,omitempty" bson:"authenticity_secret"` + AuthenticitySecret string `jsonapi:"attr,authenticity_secret,omitempty" bson:"authenticity_secret"` CreatedAt time.Time `jsonapi:"attr,created_at,omitempty" bson:"created_at"` UpdatedAt time.Time `jsonapi:"attr,updated_at,omitempty" bson:"updated_at"` Name string `jsonapi:"attr,name,omitempty" bson:"name"` @@ -15,11 +15,11 @@ type Subscription struct { } type WebhookSubscription struct { - Id string `jsonapi:"primary,WebhookSubscription" bson:"id"` + Id string `jsonapi:"primary,WebhookSubscription" bson:"id"` //attrs Active bool `jsonapi:"attr,active,omitempty" bson:"active"` ApplicationId string `jsonapi:"attr,application_id,omitempty" bson:"application_id"` - AuthenticitySecret string `jsonapi:"attr,authenticity_secret,omitempty" bson:"authenticity_secret"` + AuthenticitySecret string `jsonapi:"attr,authenticity_secret,omitempty" bson:"authenticity_secret"` CreatedAt time.Time `jsonapi:"attr,created_at,omitempty" bson:"created_at"` UpdatedAt time.Time `jsonapi:"attr,updated_at,omitempty" bson:"updated_at"` Name string `jsonapi:"attr,name,omitempty" bson:"name"` diff --git a/ui/controllers/actions.go b/ui/controllers/actions.go index a94e4aa..6e8bb13 100644 --- a/ui/controllers/actions.go +++ b/ui/controllers/actions.go @@ -15,7 +15,7 @@ import ( type actionFunc func(user *models.User) error var ( - actionFuncs map[string]actionFunc = map[string]actionFunc{"pco.plan": setupPcoSubscriptions} + actionFuncs map[string]actionFunc = map[string]actionFunc{"pco.plan": setupPcoSubscriptions} webhooksTemplate map[string]webhooks.Subscription = map[string]webhooks.Subscription{ "services.v2.events.plan.created": { Active: true, @@ -111,7 +111,7 @@ func setupPcoSubscriptions(user *models.User) error { webhookMap := make(map[string]webhooks.Subscription) subscriptions, err := pcoApi.GetSubscriptions() //Loop through found subscriptions - for _, sub := range subscriptions{ + for _, sub := range subscriptions { //if subsciption is in the templates look to add it to our map if templ, ok := webhooksTemplate[sub.Name]; ok { //if the subscription is for our url add it to our map @@ -127,9 +127,9 @@ func setupPcoSubscriptions(user *models.User) error { for _, templ := range webhooksTemplate { if _, ok := webhookMap[templ.Name]; !ok { builtHooks = append(builtHooks, webhooks.Subscription{ - Active: false, - Name: templ.Name, - Url: fmt.Sprintf(templ.Url, conf.AppSettings.WebhookServiceUrl, user.Id.Hex()), + Active: false, + Name: templ.Name, + Url: fmt.Sprintf(templ.Url, conf.AppSettings.WebhookServiceUrl, user.Id.Hex()), }) } } diff --git a/ui/db/audit.go b/ui/db/audit.go index 284667c..bfa7aec 100644 --- a/ui/db/audit.go +++ b/ui/db/audit.go @@ -13,7 +13,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -//return audit trail for user +// return audit trail for user func (db *DB) FindAuditTrailForUser(userId primitive.ObjectID) ([]models.EventRecieved, []models.ActionTaken, error) { conf := config.Config() @@ -22,7 +22,6 @@ func (db *DB) FindAuditTrailForUser(userId primitive.ObjectID) ([]models.EventRe wg.Add(2) errs := make([]error, 2) - events := []models.EventRecieved{} actions := []models.ActionTaken{} diff --git a/ui/db/db.go b/ui/db/db.go index dcd1087..3cd6d48 100644 --- a/ui/db/db.go +++ b/ui/db/db.go @@ -81,7 +81,7 @@ func (db *DB) SaveModels(m ...Model) error { return nil } -//For allowing more varidaic like things +// For allowing more varidaic like things func saveModels[T Model](db *DB, m ...T) error { conf := config.Config() diff --git a/ui/db/models/pco.go b/ui/db/models/pco.go index 95175ca..b49d585 100644 --- a/ui/db/models/pco.go +++ b/ui/db/models/pco.go @@ -3,8 +3,8 @@ package models import ( "time" - "go.mongodb.org/mongo-driver/bson/primitive" "git.preston-baxter.com/Preston_PLB/capstone/webhook-service/vendors/pco/webhooks" + "go.mongodb.org/mongo-driver/bson/primitive" ) const PCO_SUBSCRIPTION_TYPE = "pco_subscription" diff --git a/ui/db/pco.go b/ui/db/pco.go index 008ada4..7d8c643 100644 --- a/ui/db/pco.go +++ b/ui/db/pco.go @@ -12,7 +12,7 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -//using userId and event string return PCO Subscriptions saved to the DB +// using userId and event string return PCO Subscriptions saved to the DB func (db *DB) FindPcoSubscriptionForUser(userId primitive.ObjectID, eventName string) (*models.PcoSubscription, error) { conf := config.Config() @@ -35,14 +35,14 @@ func (db *DB) FindPcoSubscriptionForUser(userId primitive.ObjectID, eventName st return subscription, nil } -//Okay so learned something here. Interfaces are determined implemented for the type a method is related to. -//This function is not implemented for DB it is implemented for *DB and that is important -func (db *DB) SaveSubscriptionsForUser(userId primitive.ObjectID, subscriptions ...webhooks.Subscription) (error) { +// Okay so learned something here. Interfaces are determined implemented for the type a method is related to. +// This function is not implemented for DB it is implemented for *DB and that is important +func (db *DB) SaveSubscriptionsForUser(userId primitive.ObjectID, subscriptions ...webhooks.Subscription) error { mods := make([]*models.PcoSubscription, 0, len(subscriptions)) for _, sub := range subscriptions { mods = append(mods, &models.PcoSubscription{ - UserId: userId, - Details: &sub, + UserId: userId, + Details: &sub, }) }