model

package
v0.0.0-...-460480a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2018 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Free    string = "Visitor"
	Woobler string = "Woobler"
)

Plans label

View Source
const BaseVersion uint64 = 1

BaseVersion is creation default version

View Source
const TagSeparator string = ","

TagSeparator specifies which character delimites a tag

Variables

This section is empty.

Functions

func ActivateUser

func ActivateUser(email string, token string) error

ActivateUser activate user's email if the token is valid

func AllPackages

func AllPackages(opt *lib.Option, userID uint64) (*[]Package, error)

AllPackages returns all packages

func AllPlans

func AllPlans() (*[]Plan, error)

AllPlans returns all plans

func BulkUpdatePackageSource

func BulkUpdatePackageSource(ids lib.StringSlice, source string) error

BulkUpdatePackageSource updates somes packages "ids" source

func CaptureCharge

func CaptureCharge(chargeID string) (*stripe.Charge, error)

CaptureCharge applies the charge

func CopyCreationParamsAndFunctions

func CopyCreationParamsAndFunctions(id lib.ID, curVersion uint64, newVersion uint64) error

CopyCreationParamsAndFunctions copie creation parameters and functions from current version to a new version

func CreationInUse

func CreationInUse(creaID lib.ID) bool

CreationInUse returns true if the creation is used by anyone

func CreationLastVersion

func CreationLastVersion(id lib.ID) uint64

CreationLastVersion gets creation's last version

func DeleteCreation

func DeleteCreation(uID uint64, creaID lib.ID) error

DeleteCreation deletes a creation

func DeletePackage

func DeletePackage(uID uint64, id lib.ID) error

DeletePackage delete a package

func DeletePackageCreation

func DeletePackageCreation(uID uint64, pkgID lib.ID, creaID lib.ID) error

DeletePackageCreation delete a creation from a package

func DeleteUser

func DeleteUser(uID uint64) error

DeleteUser deletes the user "uID" from the DB

func IsTokenExpired

func IsTokenExpired(err *jwt.ValidationError) bool

IsTokenExpired tells if a token has expired (claim exp)

func IsTokenInvalid

func IsTokenInvalid(err *jwt.ValidationError) bool

IsTokenInvalid tells if the token signature is wrong

func IsTokenMalformed

func IsTokenMalformed(err *jwt.ValidationError) bool

IsTokenMalformed tells if a token is not JWT standard

func NewCreationVersion

func NewCreationVersion(crea *Creation, newVersion uint64) error

NewCreationVersion create a new version

func NewCustomer

func NewCustomer(custEmail string, plan string, token string) (*stripe.Customer, error)

NewCustomer creates a new customer in the payment system

func NewOrGetTag

func NewOrGetTag(tag *Tag)

NewOrGetTag creates a tag or get one if exists

func NewPackageCreation

func NewPackageCreation(pkgID lib.ID, creaID lib.ID, version uint64, alias string) error

NewPackageCreation create a new relationship with package and creation

func NewPackageCreationParam

func NewPackageCreationParam(pkgID lib.ID, creaID lib.ID, version uint64) error

NewPackageCreationParam create new package creation params

func NewPlanUser

func NewPlanUser(uID uint64, planLabel string, periodEnd int64) (id uint64, err error)

NewPlanUser logs user subscription

func NewToken

func NewToken(user *User, refreshToken string) *jwt.Token

NewToken generates a new token

func NewUser

func NewUser(user *User) (uID uint64, err error)

NewUser creates a new user

func PackageNbCrea

func PackageNbCrea(id lib.ID) uint64

PackageNbCrea returns the number of creations in the package id "id"

func RefreshToken

func RefreshToken(token *jwt.Token) (*jwt.Token, error)

RefreshToken refreshes old token (depending on exp claim)

func RegisterBank

func RegisterBank(email string, token string) (*stripe.Account, error)

RegisterBank links a bank account to a customer

func RenewUserPlan

func RenewUserPlan(custID string, startDate int64, endDate int64) error

RenewUserPlan renews user (customer id) plan from start date to end date

func SafeDeleteCreation

func SafeDeleteCreation(uID uint64, creaID lib.ID) error

SafeDeleteCreation sets creation's state to 'Deleted'

func SafeDeleteUser

func SafeDeleteUser(uID uint64) error

SafeDeleteUser sets deleted at to current date, meaning this user is disactivated

func SendActivationEmail

func SendActivationEmail(name string, to string) error

SendActivationEmail prepares and sends an activation email

func SubCustomer

func SubCustomer(custID string, plan string, token string) (*stripe.Sub, error)

SubCustomer subscribes the customer "custID" to the plan "plan"

func TokenKey

func TokenKey() []byte

TokenKey returns token private key

func UnsubCustomer

func UnsubCustomer(custID string) error

UnsubCustomer unsubscribes customer from his current plan

func UnsubUserPlan

func UnsubUserPlan(planID uint64) error

UnsubUserPlan unsubscribe user from his current plan (will set to free by default)

func UpdateCreation

func UpdateCreation(crea *Creation) error

UpdateCreation update creation's information

func UpdateCreationFunctions

func UpdateCreationFunctions(crea *Creation) error

UpdateCreationFunctions updates creation functions

func UpdateCreationParams

func UpdateCreationParams(crea *Creation) error

UpdateCreationParams update all creation params for a given version (crea.Version)

func UpdateCreationPatch

func UpdateCreationPatch(uID uint64, creaID lib.ID, patch lib.SQLPatch) error

UpdateCreationPatch updates a creation

func UpdateCreationTags

func UpdateCreationTags(crea *Creation) (err error)

UpdateCreationTags updates creation tags

func UpdateCustomerID

func UpdateCustomerID(uID uint64, customerID string) error

UpdateCustomerID updates user's customer ID

func UpdatePackage

func UpdatePackage(pkg *Package) error

UpdatePackage updates package form

func UpdatePackageCreation

func UpdatePackageCreation(pkg *Package) error

UpdatePackageCreation udpates package creation information

func UpdatePackagePatch

func UpdatePackagePatch(uID uint64, pkgID lib.ID, patch lib.SQLPatch) error

UpdatePackagePatch updates a package

func UpdateUserAccountID

func UpdateUserAccountID(uID uint64, accID string) error

UpdateUserAccountID updates user "uID" account ID

func UpdateUserPatch

func UpdateUserPatch(uID uint64, patch lib.SQLPatch) error

UpdateUserPatch updates user informations

func UserCustomerID

func UserCustomerID(uID uint64) (string, error)

UserCustomerID returns customerID of user "uID"

func UserNbPackages

func UserNbPackages(uID uint64) int64

UserNbPackages returns numbers of package the user uID has

func UserSubFund

func UserSubFund(uID uint64, amount uint64) error

UserSubFund substracts user "uID" fund by "amount"

Types

type Creation

type Creation struct {
	ID lib.ID `json:"id"      db:"crea.id"`

	Title       string          `json:"title"  db:"title"`
	Description *lib.NullString `json:"description,omitempty" db:"description"`
	Tags        []Tag           `json:"tags" db:""`
	ThumbPath   *lib.NullString `json:"thumbPath,omitempty" db:"thumb_path"`
	Creator     User            `json:"creator,omitempty" db:""`

	// When a creation is in draft, the very last version is ignored by most queries
	Versions lib.UintSlice `json:"versions,omitempty" db:"versions"`

	Alias      string `json:"alias,omitempty" db:"alias"`
	State      string `json:"state,omitempty" db:"state"`
	IsOwner    bool   `json:"isOwner,omitempty" db:"is_owner"`
	IsFeatured bool   `json:"-" db:"is_featured"`

	NbUse uint64 `json:"nbUse" db:"nb_use"`

	Params     []CreationParam    `json:"params,omitempty" db:""`
	Functions  []CreationFunction `json:"functions,omitempty" db:""`
	PreviewURL string             `json:"previewUrl,omitempty"`
	Version    uint64             `json:"version,omitempty"`

	PreviewPos       PreviewPosition   `json:"previewPosition" db:""`
	PreviewPositions []PreviewPosition `json:"previewPositions,omitempty" db:""`
	IsThumbPreview   bool              `json:"isThumbPreview" db:"is_thumb_preview"`

	Script       string `json:"script,omitempty"`
	ParsedScript string `json:"parsedScript,omitempty"`
	Document     string `json:"document,omitempty"`
	Style        string `json:"style,omitempty"`

	CreatorID uint64 `json:"-" db:"creator_id"`
	Engine    Engine `json:"-" db:""`

	CreatedAt *lib.NullTime `json:"createdAt,omitempty" db:"crea.created_at"`
	UpdatedAt *lib.NullTime `json:"updatedAt,omitempty" db:"crea.updated_at"`
}

Creation is a Wooble object

func AllCreations

func AllCreations(opt lib.Option, uID uint64) ([]Creation, error)

AllCreations returns all creations

func AllDraftCreations

func AllDraftCreations(opt lib.Option, uID uint64) ([]Creation, error)

AllDraftCreations returns all creation in draft of authenticated user

func AllPopularCreations

func AllPopularCreations(opt lib.Option, uID uint64) ([]Creation, error)

AllPopularCreations returns all popular creations

func AllUsedCreations

func AllUsedCreations(opt lib.Option, uID uint64) ([]Creation, error)

AllUsedCreations return creations used in some packages

func CreationByID

func CreationByID(id lib.ID, uID uint64, latestVersion bool) (*Creation, error)

CreationByID returns a creation with the id "id"

func CreationByIDAndVersion

func CreationByIDAndVersion(id lib.ID, version uint64) (*Creation, error)

CreationByIDAndVersion returns the creation "creaID" and check if the version "version" exists

func NewCreation

func NewCreation(crea *Creation) (*Creation, error)

NewCreation creates a creation

func (*Creation) GenerateDefaultThumb

func (c *Creation) GenerateDefaultThumb() ([]byte, string)

GenerateDefaultThumb generates unique thumbnail for the creation it returns the image buffer and the image path

func (*Creation) PopulateFunctions

func (c *Creation) PopulateFunctions()

PopulateFunctions populates creation's functions for documentation

func (*Creation) PopulateParams

func (c *Creation) PopulateParams()

PopulateParams populates creation's parameters (for previewing and building into package)

func (*Creation) PopulatePreviewPositions

func (c *Creation) PopulatePreviewPositions()

PopulatePreviewPositions populates available creation's preview positions

func (*Creation) PopulateTags

func (c *Creation) PopulateTags() error

PopulateTags populates creation's tags

func (*Creation) RetrievePreviewURL

func (c *Creation) RetrievePreviewURL()

RetrievePreviewURL construct the creation's preview URL and sets the `PreviewUrl` field It uses the current `Version` of the creation c

func (*Creation) RetrieveSourceCode

func (c *Creation) RetrieveSourceCode(version string, files ...string) error

RetrieveSourceCode request the source files in the cloud and set the content to the Creation

type CreationFunction

type CreationFunction struct {
	Call   string `json:"call" db:"call"`
	Detail string `json:"detail" db:"detail"`
}

CreationFunction is a creation function

type CreationParam

type CreationParam struct {
	CreationID lib.ID `json:"-" db:"creation_id"`
	Field      string `json:"field" db:"field"`
	Value      string `json:"value" db:"value"`
}

CreationParam is a creation parameter

type CustomClaims

type CustomClaims struct {
	Name         string `json:"name"`
	Plan         Plan   `json:"plan"`
	RefreshToken string `json:"refresh_token"`
	IsActive     bool   `json:"isActive"`
	jwt.StandardClaims
}

CustomClaims is wooble token claims

type Element

type Element struct {
	Type    string
	Content string
	Attr    string
}

Element represents an HTML element (DOM node)

type Email

type Email struct {
	Title    string
	Name     string
	Elements []Element
}

Email is for sending emails (used in templates)

type Engine

type Engine struct {
	Name string `json:"name"   db:"eng.name"`

	ContentType string `json:"-" db:"content_type"`
	Extension   string `json:"-" db:"extension"`
}

Engine is the engine used by a creation (JSES5 is the only one available for now)

func EngineByName

func EngineByName(name string) (*Engine, error)

EngineByName returns engine with name "name"

type Package

type Package struct {
	ID lib.ID `json:"id" db:"pkg.id"`

	Title   string `json:"title" validate:"required" db:"pkg.title"`
	NbBuild uint64 `json:"nbBuild" db:"nb_build"`

	Referer       *lib.NullString `json:"referer,omitempty" db:"referer"`
	UserID        uint64          `json:"-" db:"pkg.user_id"`
	User          User            `json:"-" db:""`
	Creations     []Creation      `json:"creations,omitempty" db:""`
	Source        *lib.NullString `json:"source,omitempty" db:"source"`
	BuildRequired bool            `json:"buildRequired" db:"build_required"`
	NbCrea        *lib.NullInt64  `json:"nbCreations" db:"nb_creations"`

	CreatedAt *lib.NullTime `json:"createdAt,omitempty" db:"pkg.created_at"`
	UpdatedAt *lib.NullTime `json:"updatedAt,omitempty" db:"pkg.updated_at"`
	BuiltAt   *lib.NullTime `json:"builtAt,omitempty" db:"built_at"`
}

Package is a bundle of creations

func NewPackage

func NewPackage(pkg *Package) (*Package, error)

NewPackage creates a new package

func PackageByID

func PackageByID(uID uint64, id lib.ID) (*Package, error)

PackageByID returns package with id "id"

func (*Package) PopulateCreations

func (p *Package) PopulateCreations() error

PopulateCreations populates creations in the package

type Plan

type Plan struct {
	Label      *lib.NullString `json:"label,omitempty" db:"plan.label"`
	PriceMonth uint64          `json:"pricePerMonth,omitempty" db:"price_per_month"`
	PriceYear  uint64          `json:"pricePerYear,omitempty" db:"price_per_year"`

	Level *lib.NullInt64 `json:"level,omitempty" db:"level"`

	NbPkg  *lib.NullInt64 `json:"nbPkg,omitempty" db:"nb_pkg"`
	NbCrea *lib.NullInt64 `json:"nbCrea,omitempty" db:"nb_crea"`

	StartDate *lib.NullTime `json:"startDate,omitempty" db:"start_date"`
	EndDate   *lib.NullTime `json:"endDate,omitempty" db:"end_date"`
	UnsubDate *lib.NullTime `json:"unsubDate,omitempty" db:"unsub_date"`
}

Plan is a Wooble plan with some restrictions NbPkg is the number of packages allowed (0 means infinite) NbCrea is the number of creations per package (0 means infinite)

func DefaultPlan

func DefaultPlan(userID uint64) (*Plan, error)

DefaultPlan gets free plan or second plan if user is VIP

func PlanByLabel

func PlanByLabel(label string) (*Plan, error)

PlanByLabel gets plan with label "label"

func (*Plan) HasExpired

func (plan *Plan) HasExpired() bool

HasExpired returns true if the plan has expired

type PreviewPosition

type PreviewPosition struct {
	Position    string `json:"position" db:"position_id"`
	StyleSource string `json:"styleSource" db:"style_source"`
}

PreviewPosition is the creation position in the preview

type Tag

type Tag struct {
	ID    uint64 `json:"id,omitempty" db:"tag.id"`
	Title string `json:"title" db:"tag.title"`
	NbUse uint64 `json:"nbUse" db:"tag_nb_use"`
}

Tag is for arranging crations

func AllTags

func AllTags(opt lib.Option) ([]Tag, error)

AllTags returns all tags Filters : search Orders : nb_use

type User

type User struct {
	ID         uint64         `json:"-" db:"user.id"`
	CustomerID string         `json:"-" db:"customer_id"`
	AccountID  lib.NullString `json:"-" db:"account_id"`

	Email    string          `json:"email,omitempty" db:"email"`
	Name     string          `json:"name,omitempty" db:"name"`
	PicPath  *lib.NullString `json:"profilePath,omitempty" db:"pic_path"`
	Fullname *lib.NullString `json:"fullname,omitempty" db:"fullname"`
	IsVIP    bool            `json:"-" db:"is_vip"`
	IsActive bool            `json:"-" db:"is_active"`

	Website      *lib.NullString `json:"website,omitempty" db:"website"`
	CodepenName  *lib.NullString `json:"codepenName,omitempty" db:"codepen_name"`
	DribbbleName *lib.NullString `json:"dribbbleName,omitempty" db:"dribbble_name"`
	GithubName   *lib.NullString `json:"githubName,omitempty" db:"github_name"`
	TwitterName  *lib.NullString `json:"twitterName,omitempty" db:"twitter_name"`

	PlanID   *lib.NullInt64 `json:"-" db:"plan_user.id"`
	Plan     *Plan          `json:"plan,omitempty" db:""`
	Packages *[]Package     `json:"packages,omitempty" db:""`

	IsCreator bool   `json:"isCreator,omitempty" db:"is_creator"`
	Fund      uint64 `json:"fund,omitempty" db:"fund"`

	Secret string `json:"-" db:"passwd"`
	Salt   string `json:"-" db:"salt_key"`

	CreatedAt *lib.NullTime `json:"createdAt,omitempty" db:"user.created_at"`
	UpdatedAt *lib.NullTime `json:"updatedAt,omitempty" db:"user.updated_at"`
	DeletedAt *lib.NullTime `json:"deletedAt,omitempty" db:"user.deleted_at"`
}

User is a Wooble user

func AllActiveUsers

func AllActiveUsers() ([]User, error)

AllActiveUsers returns all public and activated users

func UserByEmail

func UserByEmail(email string) (*User, error)

UserByEmail returns user with a specified email or name

func UserByToken

func UserByToken(token interface{}) (*User, error)

UserByToken return the user whom the token belong to

func UserPrivateByID

func UserPrivateByID(userID uint64) (*User, error)

UserPrivateByID returns user with id "id" It'll select the most recent plan but ignore it if the end_date expired

func UserPublicByName

func UserPublicByName(username string) (*User, error)

UserPublicByName returns user public profile with the name "username"

func (*User) IsPasswordValid

func (u *User) IsPasswordValid(passwd string) bool

IsPasswordValid checks if a password is valid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL