B: Formatting

This commit is contained in:
Preston Baxter 2023-11-18 20:16:44 -06:00
parent 920e203b9d
commit 46f9460a37
8 changed files with 23 additions and 25 deletions

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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{}

View File

@ -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()

View File

@ -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"

View File

@ -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,9 +35,9 @@ 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{