B: More updates related to getting scheduling to work
This commit is contained in:
parent
a1eecdd7f8
commit
b77f45ccf6
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
|
||||||
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db/models"
|
"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 {
|
func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery) error {
|
||||||
//get uid from context. Lots of sanitizing just incase
|
//get uid from context. Lots of sanitizing just incase
|
||||||
var uid primitive.ObjectID
|
uid := userIdFromContext(c)
|
||||||
if raw, ok := c.Get("user_bson_id"); ok {
|
|
||||||
uid, ok = raw.(primitive.ObjectID)
|
//Check if this is a redilivery.
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Load ytClient for user. It is fetched from cache or created
|
//Load ytClient for user. It is fetched from cache or created
|
||||||
ytClient, err := youtubeServiceForUser(uid)
|
ytClient, err := youtubeServiceForUser(*uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to initialize youtube client")
|
log.WithError(err).Error("Failed to initialize youtube client")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load pcoClient for user. It is fetched from cache or created
|
//Load pcoClient for user. It is fetched from cache or created
|
||||||
pcoClient, err := pcoServiceForUser(uid)
|
pcoClient, err := pcoServiceForUser(*uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to initialize youtube client")
|
log.WithError(err).Error("Failed to initialize youtube client")
|
||||||
return err
|
return err
|
||||||
|
@ -210,8 +204,9 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery)
|
||||||
|
|
||||||
//Save audit point
|
//Save audit point
|
||||||
eventRecievedAudit := &models.EventRecieved{
|
eventRecievedAudit := &models.EventRecieved{
|
||||||
UserId: uid,
|
UserId: *uid,
|
||||||
VendorName: models.PCO_VENDOR_NAME,
|
VendorName: models.PCO_VENDOR_NAME,
|
||||||
|
VendorId: body.ID,
|
||||||
Type: body.Name,
|
Type: body.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,12 +237,12 @@ func ScheduleBroadcastFromWebhook(c *gin.Context, body *webhooks.EventDelivery)
|
||||||
|
|
||||||
//build audit trail after action was taken
|
//build audit trail after action was taken
|
||||||
broadcastModel := &models.YoutubeBroadcast{
|
broadcastModel := &models.YoutubeBroadcast{
|
||||||
UserId: uid,
|
UserId: *uid,
|
||||||
Details: broadcast,
|
Details: broadcast,
|
||||||
}
|
}
|
||||||
|
|
||||||
actionTaken := &models.ActionTaken{
|
actionTaken := &models.ActionTaken{
|
||||||
UserId: uid,
|
UserId: *uid,
|
||||||
TriggeringEvent: eventRecievedAudit.MongoId(),
|
TriggeringEvent: eventRecievedAudit.MongoId(),
|
||||||
Result: []primitive.ObjectID{broadcastModel.MongoId()},
|
Result: []primitive.ObjectID{broadcastModel.MongoId()},
|
||||||
VendorName: models.YOUTUBE_VENDOR_NAME,
|
VendorName: models.YOUTUBE_VENDOR_NAME,
|
||||||
|
@ -271,6 +266,12 @@ func scheduleNewBroadcastFromWebhook(c *gin.Context, plan *services.Plan, ytClie
|
||||||
|
|
||||||
startTime := times[0].StartsAt
|
startTime := times[0].StartsAt
|
||||||
// endTime := times[len(times) - 1].EndsAt TODO: this will be used later
|
// endTime := times[len(times) - 1].EndsAt TODO: this will be used later
|
||||||
|
var title string
|
||||||
return yt_helpers.InsertBroadcast(ytClient, plan.Title, startTime, yt_helpers.STATUS_PRIVATE)
|
if plan.Title == "" {
|
||||||
|
title = "Live Stream Scheduled By Capstone"
|
||||||
|
} else {
|
||||||
|
title = plan.Title
|
||||||
|
}
|
||||||
|
|
||||||
|
return yt_helpers.InsertBroadcast(ytClient, title, startTime, yt_helpers.STATUS_PRIVATE)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,5 @@ type PlanTime struct {
|
||||||
TimeType string `jsonapi:"attr,time_type,omitempty"`
|
TimeType string `jsonapi:"attr,time_type,omitempty"`
|
||||||
UpdatedAt time.Time `jsonapi:"attr,updated_at,rfc3339,omitempty"`
|
UpdatedAt time.Time `jsonapi:"attr,updated_at,rfc3339,omitempty"`
|
||||||
//relations
|
//relations
|
||||||
AssignedTeams *[]Team `jsonapi:"relation,assigned_teams,omitempty"`
|
AssignedTeams []Team `jsonapi:"relation,assigned_teams,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func InsertBroadcast(service *youtube.Service, title string, startTime time.Time
|
||||||
liveBroadcast := &youtube.LiveBroadcast{
|
liveBroadcast := &youtube.LiveBroadcast{
|
||||||
Snippet: &youtube.LiveBroadcastSnippet{
|
Snippet: &youtube.LiveBroadcastSnippet{
|
||||||
Title: title,
|
Title: title,
|
||||||
ScheduledStartTime: startTime.Format(time.RFC3339),
|
ScheduledStartTime: startTime.Format(time.RFC3339Nano),
|
||||||
},
|
},
|
||||||
Status: &youtube.LiveBroadcastStatus{
|
Status: &youtube.LiveBroadcastStatus{
|
||||||
PrivacyStatus: privacyStatus,
|
PrivacyStatus: privacyStatus,
|
||||||
|
|
|
@ -75,3 +75,5 @@ func (db *DB) FindAuditTrailForUser(userId primitive.ObjectID) ([]models.EventRe
|
||||||
|
|
||||||
return events, actions, nil
|
return events, actions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) FindEventRecievedByVendorId(id string) ([]models.EventRecieved) {return []models.EventRecieved{}}
|
||||||
|
|
|
@ -17,6 +17,7 @@ type EventRecieved struct {
|
||||||
Id primitive.ObjectID `bson:"_id,omitempty"`
|
Id primitive.ObjectID `bson:"_id,omitempty"`
|
||||||
UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too
|
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
|
VendorName string `bson:"vendor_name,omitempty"` //Vendor name of who sent us the event
|
||||||
|
VendorId string `bson:"vendor_id:omitempty"`
|
||||||
Type string `bson:"type,omitempty"` //type of event
|
Type string `bson:"type,omitempty"` //type of event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"webhook_version": "0.0.45",
|
"webhook_version": "0.0.48",
|
||||||
"frontend_version": "0.0.35"
|
"frontend_version": "0.0.35"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue