diff --git a/service/controllers/pco_webhook.go b/service/controllers/pco_webhook.go index db8bf54..29844bc 100644 --- a/service/controllers/pco_webhook.go +++ b/service/controllers/pco_webhook.go @@ -6,7 +6,6 @@ import ( "fmt" "regexp" "sync" - "time" "git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config" "git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db/models" @@ -177,24 +176,19 @@ func youtubeServiceForUser(userId primitive.ObjectID) (*youtube.Service, error) func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) error { //get uid from context. Lots of sanitizing just incase - var uid primitive.ObjectID - if raw, ok := c.Get("user_bson_id"); ok { - uid, ok = raw.(primitive.ObjectID) - if !ok { - log.Errorf("failed to parse user id to bson object id: %v", raw) - return errors.New("Failed to case user id as bson object id") - } - } + uid := userIdFromContext(c) + + //Check if this is a redilivery. //Load ytClient for user. It is fetched from cache or created - ytClient, err := youtubeServiceForUser(uid) + ytClient, err := youtubeServiceForUser(*uid) if err != nil { log.WithError(err).Error("Failed to initialize youtube client") return err } //Load pcoClient for user. It is fetched from cache or created - pcoClient, err := pcoServiceForUser(uid) + pcoClient, err := pcoServiceForUser(*uid) if err != nil { log.WithError(err).Error("Failed to initialize youtube client") return err @@ -210,8 +204,9 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) //Save audit point eventRecievedAudit := &models.EventRecieved{ - UserId: uid, + UserId: *uid, VendorName: models.PCO_VENDOR_NAME, + VendorId: body.ID, Type: body.Name, } @@ -242,12 +237,12 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) //build audit trail after action was taken broadcastModel := &models.YoutubeBroadcast{ - UserId: uid, + UserId: *uid, Details: broadcast, } actionTaken := &models.ActionTaken{ - UserId: uid, + UserId: *uid, TriggeringEvent: eventRecievedAudit.MongoId(), Result: []primitive.ObjectID{broadcastModel.MongoId()}, VendorName: models.YOUTUBE_VENDOR_NAME, @@ -271,6 +266,12 @@ func scheduleNewBroadcastFromWebhook(c *gin.Context, plan *services.Plan, ytClie startTime := times[0].StartsAt // endTime := times[len(times) - 1].EndsAt TODO: this will be used later + var title string + if plan.Title == "" { + title = "Live Stream Scheduled By Capstone" + } else { + title = plan.Title + } - return yt_helpers.InsertBroadcast(ytClient, plan.Title, startTime, yt_helpers.STATUS_PRIVATE) + return yt_helpers.InsertBroadcast(ytClient, title, startTime, yt_helpers.STATUS_PRIVATE) } diff --git a/service/vendors/pco/services/plan_time.go b/service/vendors/pco/services/plan_time.go index 87d84e7..c879d31 100644 --- a/service/vendors/pco/services/plan_time.go +++ b/service/vendors/pco/services/plan_time.go @@ -15,5 +15,5 @@ type PlanTime struct { TimeType string `jsonapi:"attr,time_type,omitempty"` UpdatedAt time.Time `jsonapi:"attr,updated_at,rfc3339,omitempty"` //relations - AssignedTeams *[]Team `jsonapi:"relation,assigned_teams,omitempty"` + AssignedTeams []Team `jsonapi:"relation,assigned_teams,omitempty"` } diff --git a/service/vendors/youtube/youtube.go b/service/vendors/youtube/youtube.go index 05fc0ec..5a82519 100644 --- a/service/vendors/youtube/youtube.go +++ b/service/vendors/youtube/youtube.go @@ -16,7 +16,7 @@ func InsertBroadcast(service *youtube.Service, title string, startTime time.Time liveBroadcast := &youtube.LiveBroadcast{ Snippet: &youtube.LiveBroadcastSnippet{ Title: title, - ScheduledStartTime: startTime.Format(time.RFC3339), + ScheduledStartTime: startTime.Format(time.RFC3339Nano), }, Status: &youtube.LiveBroadcastStatus{ PrivacyStatus: privacyStatus, diff --git a/ui/db/audit.go b/ui/db/audit.go index bfa7aec..35a79bc 100644 --- a/ui/db/audit.go +++ b/ui/db/audit.go @@ -75,3 +75,5 @@ func (db *DB) FindAuditTrailForUser(userId primitive.ObjectID) ([]models.EventRe return events, actions, nil } + +func (db *DB) FindEventRecievedByVendorId(id string) ([]models.EventRecieved) {return []models.EventRecieved{}} diff --git a/ui/db/models/audit.go b/ui/db/models/audit.go index 3f97c9b..299efa8 100644 --- a/ui/db/models/audit.go +++ b/ui/db/models/audit.go @@ -17,7 +17,8 @@ type EventRecieved struct { Id primitive.ObjectID `bson:"_id,omitempty"` UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too VendorName string `bson:"vendor_name,omitempty"` //Vendor name of who sent us the event - Type string `bson:"type,omitempty"` //type of event + VendorId string `bson:"vendor_id:omitempty"` + Type string `bson:"type,omitempty"` //type of event } func (obj *EventRecieved) MongoId() primitive.ObjectID { diff --git a/versions.json b/versions.json index 4b4ceb0..d361408 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { - "webhook_version": "0.0.45", + "webhook_version": "0.0.48", "frontend_version": "0.0.35" }