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-10-30 20:06:18 -04:00
|
|
|
|
|
|
|
const VENDOR_ACCOUNT_TYPE = "vendor_account"
|
|
|
|
|
2023-11-02 19:23:07 -04:00
|
|
|
const (
|
|
|
|
YOUTUBE_VENDOR_NAME = "YouTube"
|
|
|
|
PCO_VENDOR_NAME = "PCO"
|
|
|
|
)
|
|
|
|
|
2023-11-01 22:40:50 -04:00
|
|
|
type OauthCredential struct {
|
|
|
|
AccessToken string `bson:"access_token,omitempty" json:"access_token,omitempty"`
|
|
|
|
ExpiresIn int `bson:"expires_in,omitempty" json:"expires_in,omitempty"`
|
|
|
|
ExpiresAt time.Time `bson:"expires_at,omitempty" json:"expires_at,omitempty"`
|
|
|
|
TokenType string `bson:"token_type,omitempty" json:"token_type,omitempty"`
|
|
|
|
Scope string `bson:"scope,omitempty" json:"scope,omitempty"`
|
|
|
|
RefreshToken string `bson:"refresh_token,omitempty" json:"refresh_token,omitempty"`
|
2023-10-30 20:06:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type VendorAccount struct {
|
2023-11-01 22:40:50 -04:00
|
|
|
*CommonFields `bson:"obj_info"`
|
|
|
|
mongoId primitive.ObjectID `bson:"_id,omitempty"`
|
|
|
|
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 {
|
|
|
|
if va.mongoId.IsZero() {
|
|
|
|
now := time.Now()
|
|
|
|
va.mongoId = primitive.NewObjectIDFromTimestamp(now)
|
|
|
|
}
|
|
|
|
|
|
|
|
return va.mongoId
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|