This commit is contained in:
Preston Baxter 2023-11-16 19:45:48 -06:00
parent f703f2d1ab
commit 6f1ce7dcc1
21 changed files with 50 additions and 57 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/google/jsonapi" "github.com/google/jsonapi"
) )
func (api *PcoApiClient) GetPlan(service_type_id, plan_id string) (*services.Plan, error){ func (api *PcoApiClient) GetPlan(service_type_id, plan_id string) (*services.Plan, error) {
api.Url().Path = fmt.Sprintf("/services/v2/service_types/%s/plans/%s", service_type_id, plan_id) api.Url().Path = fmt.Sprintf("/services/v2/service_types/%s/plans/%s", service_type_id, plan_id)
req, err := http.NewRequest(http.MethodGet, api.Url().String(), nil) req, err := http.NewRequest(http.MethodGet, api.Url().String(), nil)

View File

@ -1,6 +1,5 @@
package services package services
type Series struct { type Series struct {
Id string `jsonapi:"primary,Series"` Id string `jsonapi:"primary,Series"`
} }

View File

@ -1,6 +1,5 @@
package services package services
type ServiceType struct { type ServiceType struct {
Id string `jsonapi:"primary,ServiceType"` Id string `jsonapi:"primary,ServiceType"`
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/google/jsonapi" "github.com/google/jsonapi"
) )
//Structure delivered to target when sending webhooks // Structure delivered to target when sending webhooks
type EventDelivery struct { type EventDelivery struct {
//uuid of the EventDelivery //uuid of the EventDelivery
ID string `jsonapi:"primary,EventDelivery"` ID string `jsonapi:"primary,EventDelivery"`
@ -22,7 +22,7 @@ type EventDelivery struct {
Organization *services.Organization `jsonapi:"relation,organization"` Organization *services.Organization `jsonapi:"relation,organization"`
} }
//Unmarshall payload of EventDelivery into the struct you think it is // Unmarshall payload of EventDelivery into the struct you think it is
func (event *EventDelivery) UnmarshallPayload(obj any) error { func (event *EventDelivery) UnmarshallPayload(obj any) error {
return jsonapi.UnmarshalPayload(strings.NewReader(event.Payload), obj) return jsonapi.UnmarshalPayload(strings.NewReader(event.Payload), obj)
} }

View File

@ -11,7 +11,7 @@ const (
STATUS_PUBLIC = "public" STATUS_PUBLIC = "public"
) )
//Inserts Broadcast into youtube // Inserts Broadcast into youtube
func InsertBroadcast(service *youtube.Service, title string, startTime time.Time, privacyStatus string) (*youtube.LiveBroadcast, error) { func InsertBroadcast(service *youtube.Service, title string, startTime time.Time, privacyStatus string) (*youtube.LiveBroadcast, error) {
liveBroadcast := &youtube.LiveBroadcast{ liveBroadcast := &youtube.LiveBroadcast{
Snippet: &youtube.LiveBroadcastSnippet{ Snippet: &youtube.LiveBroadcastSnippet{

View File

@ -146,7 +146,6 @@ func LoginHandler(c *gin.Context) {
return return
} }
if user == nil { if user == nil {
log.Warnf("No user was found for: %s", reqBody.Email) log.Warnf("No user was found for: %s", reqBody.Email)
renderTempl(c, templates.LoginPage(fmt.Sprintf("No user found for %s", reqBody.Email))) renderTempl(c, templates.LoginPage(fmt.Sprintf("No user found for %s", reqBody.Email)))

View File

@ -46,12 +46,12 @@ func DashboardPage(c *gin.Context) {
waitGroup := new(sync.WaitGroup) waitGroup := new(sync.WaitGroup)
waitGroup.Add(2) waitGroup.Add(2)
go func(wg *sync.WaitGroup){ go func(wg *sync.WaitGroup) {
vendors, errs[0] = mongo.FindAllVendorAccountsByUser(user.MongoId()) vendors, errs[0] = mongo.FindAllVendorAccountsByUser(user.MongoId())
wg.Done() wg.Done()
}(waitGroup) }(waitGroup)
go func(wg *sync.WaitGroup){ go func(wg *sync.WaitGroup) {
actions, errs[1] = mongo.FindActionMappingsByUser(user.MongoId()) actions, errs[1] = mongo.FindActionMappingsByUser(user.MongoId())
wg.Done() wg.Done()
}(waitGroup) }(waitGroup)
@ -68,6 +68,5 @@ func DashboardPage(c *gin.Context) {
} }
} }
renderTempl(c, templates.DashboardPage(user, vendors, actions)) renderTempl(c, templates.DashboardPage(user, vendors, actions))
} }

View File

@ -94,7 +94,7 @@ func RecievePCOOuath(c *gin.Context) {
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode ,string(rawBody)) log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode, string(rawBody))
c.AbortWithStatus(502) c.AbortWithStatus(502)
return return
} }

View File

@ -106,12 +106,11 @@ func ReceiveYoutubeOauth(c *gin.Context) {
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode ,string(rawBody)) log.Errorf("Response failed with status code: %d. Error: %s", resp.StatusCode, string(rawBody))
c.AbortWithStatus(502) c.AbortWithStatus(502)
return return
} }
oauthResp := &models.OauthCredential{} oauthResp := &models.OauthCredential{}
err = json.Unmarshal(rawBody, oauthResp) err = json.Unmarshal(rawBody, oauthResp)
if err != nil { if err != nil {

View File

@ -11,7 +11,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
//Interface for any object that wants to take advantage of the DB package // Interface for any object that wants to take advantage of the DB package
type Model interface { type Model interface {
//Should return the _id field of the object if it exits //Should return the _id field of the object if it exits
@ -35,7 +35,7 @@ func NewClient(uri string) (*DB, error) {
return &DB{client: client}, nil return &DB{client: client}, nil
} }
//Upserts // Upserts
func (db *DB) SaveModel(m Model) error { func (db *DB) SaveModel(m Model) error {
conf := config.Config() conf := config.Config()
@ -81,7 +81,7 @@ func (db *DB) SaveModels(m ...Model) error {
return nil return nil
} }
//Doesn't upsert // Doesn't upsert
func (db *DB) InsertModel(m Model) error { func (db *DB) InsertModel(m Model) error {
conf := config.Config() conf := config.Config()

View File

@ -50,5 +50,3 @@ func (va *VendorAccount) Token() *oauth2.Token {
Expiry: va.OauthCredentials.ExpiresAt, Expiry: va.OauthCredentials.ExpiresAt,
} }
} }

View File

@ -90,10 +90,10 @@ func (ts *VendorTokenSource) Token() (*oauth2.Token, error) {
return token, nil return token, nil
} }
//Allow us to check for kind of error at the end // Allow us to check for kind of error at the end
var TokenWaitExpired error = errors.New("Waiting for token to refresh took too long") var TokenWaitExpired error = errors.New("Waiting for token to refresh took too long")
//Used to extract the token lock that was updated when the change stream alerts // Used to extract the token lock that was updated when the change stream alerts
type tokenLockChangeEvent struct { type tokenLockChangeEvent struct {
TokenLock *models.TokenLock `bson:"fullDocument"` TokenLock *models.TokenLock `bson:"fullDocument"`
} }

View File

@ -74,7 +74,7 @@ func TestRefreshToken(t *testing.T) {
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(2) wg.Add(2)
go func(tkr oauth2.TokenSource, wg *sync.WaitGroup){ go func(tkr oauth2.TokenSource, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
var err error var err error
tk1, err = tkr.Token() tk1, err = tkr.Token()
@ -84,7 +84,7 @@ func TestRefreshToken(t *testing.T) {
} }
}(tkr1, wg) }(tkr1, wg)
go func(tkr oauth2.TokenSource, wg *sync.WaitGroup){ go func(tkr oauth2.TokenSource, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
var err error var err error
tk2, err = tkr.Token() tk2, err = tkr.Token()
@ -92,7 +92,7 @@ func TestRefreshToken(t *testing.T) {
t.Errorf("got err = %v; want none", err) t.Errorf("got err = %v; want none", err)
return return
} }
}(tkr2,wg) }(tkr2, wg)
wg.Wait() wg.Wait()

View File

@ -11,7 +11,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
//seraches for a single user by email address // seraches for a single user by email address
func (db *DB) FindUserByEmail(email string) (*models.User, error) { func (db *DB) FindUserByEmail(email string) (*models.User, error) {
conf := config.Config() conf := config.Config()
@ -34,7 +34,7 @@ func (db *DB) FindUserByEmail(email string) (*models.User, error) {
return user, nil return user, nil
} }
//find user by its unique id // find user by its unique id
func (db *DB) FindUserById(id string) (*models.User, error) { func (db *DB) FindUserById(id string) (*models.User, error) {
conf := config.Config() conf := config.Config()
@ -44,7 +44,7 @@ func (db *DB) FindUserById(id string) (*models.User, error) {
return nil, err return nil, err
} }
res := db.client.Database(conf.Mongo.EntDb).Collection(conf.Mongo.EntCol).FindOne(context.Background(), bson.M{"_id": objId , "obj_info.ent": models.USER_TYPE}, opts) res := db.client.Database(conf.Mongo.EntDb).Collection(conf.Mongo.EntCol).FindOne(context.Background(), bson.M{"_id": objId, "obj_info.ent": models.USER_TYPE}, opts)
if res.Err() != nil { if res.Err() != nil {
if res.Err() == mongo.ErrNoDocuments { if res.Err() == mongo.ErrNoDocuments {
@ -62,7 +62,7 @@ func (db *DB) FindUserById(id string) (*models.User, error) {
return user, nil return user, nil
} }
//returns all users // returns all users
func (db *DB) FindAllUsers() ([]models.User, error) { func (db *DB) FindAllUsers() ([]models.User, error) {
conf := config.Config() conf := config.Config()

View File

@ -11,7 +11,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
//return all vendor accounts for a user // return all vendor accounts for a user
func (db *DB) FindAllVendorAccountsByUser(userId primitive.ObjectID) ([]models.VendorAccount, error) { func (db *DB) FindAllVendorAccountsByUser(userId primitive.ObjectID) ([]models.VendorAccount, error) {
conf := config.Config() conf := config.Config()
@ -33,7 +33,7 @@ func (db *DB) FindAllVendorAccountsByUser(userId primitive.ObjectID) ([]models.V
return vendors, nil return vendors, nil
} }
//find vendor for user by name // find vendor for user by name
func (db *DB) FindVendorAccountByUser(userId primitive.ObjectID, name string) (*models.VendorAccount, error) { func (db *DB) FindVendorAccountByUser(userId primitive.ObjectID, name string) (*models.VendorAccount, error) {
conf := config.Config() conf := config.Config()
@ -55,7 +55,7 @@ func (db *DB) FindVendorAccountByUser(userId primitive.ObjectID, name string) (*
return vendor, nil return vendor, nil
} }
//find vendoraccount by its unique id // find vendoraccount by its unique id
func (db *DB) FindVendorAccountById(vendorId primitive.ObjectID) (*models.VendorAccount, error) { func (db *DB) FindVendorAccountById(vendorId primitive.ObjectID) (*models.VendorAccount, error) {
conf := config.Config() conf := config.Config()