2023-10-30 20:06:18 -04:00
|
|
|
package models
|
|
|
|
|
2023-11-01 22:40:50 -04:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
2023-11-07 22:34:57 -05:00
|
|
|
"golang.org/x/oauth2"
|
2023-11-01 22:40:50 -04:00
|
|
|
)
|
2023-10-30 20:06:18 -04:00
|
|
|
|
|
|
|
const VENDOR_ACCOUNT_TYPE = "vendor_account"
|
|
|
|
|
2023-11-02 19:23:07 -04:00
|
|
|
const (
|
2023-11-04 23:43:01 -04:00
|
|
|
YOUTUBE_VENDOR_NAME = "youtube"
|
|
|
|
PCO_VENDOR_NAME = "pco"
|
2023-11-02 19:23:07 -04:00
|
|
|
)
|
|
|
|
|
2023-10-30 20:06:18 -04:00
|
|
|
type VendorAccount struct {
|
2023-11-01 22:40:50 -04:00
|
|
|
*CommonFields `bson:"obj_info"`
|
2023-11-07 22:34:57 -05:00
|
|
|
Id primitive.ObjectID `bson:"_id,omitempty"`
|
2023-11-01 22:40:50 -04:00
|
|
|
UserId primitive.ObjectID `bson:"user_id,omitempty"`
|
|
|
|
Secret string `bson:"secret,omitempty"`
|
|
|
|
OauthCredentials *OauthCredential `bson:"ouath_credentials,omitempty"`
|
2023-11-02 19:23:07 -04:00
|
|
|
Name string `bson:"name"`
|
2023-11-01 22:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (va *VendorAccount) MongoId() primitive.ObjectID {
|
2023-11-03 01:01:33 -04:00
|
|
|
if va.Id.IsZero() {
|
2023-11-01 22:40:50 -04:00
|
|
|
now := time.Now()
|
2023-11-03 01:01:33 -04:00
|
|
|
va.Id = primitive.NewObjectIDFromTimestamp(now)
|
2023-11-01 22:40:50 -04:00
|
|
|
}
|
|
|
|
|
2023-11-03 01:01:33 -04:00
|
|
|
return va.Id
|
2023-11-01 22:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (va *VendorAccount) UpdateObjectInfo() {
|
|
|
|
now := time.Now()
|
|
|
|
if va.CommonFields == nil {
|
|
|
|
va.CommonFields = new(CommonFields)
|
|
|
|
va.EntityType = VENDOR_ACCOUNT_TYPE
|
|
|
|
va.CreatedAt = now
|
|
|
|
}
|
|
|
|
va.UpdatedAt = now
|
2023-10-30 20:06:18 -04:00
|
|
|
}
|
2023-11-04 18:52:41 -04:00
|
|
|
|
2023-11-07 22:34:57 -05:00
|
|
|
func (va *VendorAccount) Token() *oauth2.Token {
|
|
|
|
return &oauth2.Token{
|
|
|
|
AccessToken: va.OauthCredentials.AccessToken,
|
|
|
|
TokenType: va.OauthCredentials.TokenType,
|
|
|
|
RefreshToken: va.OauthCredentials.RefreshToken,
|
|
|
|
Expiry: va.OauthCredentials.ExpiresAt,
|
|
|
|
}
|
|
|
|
}
|