model

package
v1.0.0-13 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateCost

func CalculateCost(count int64) int64

CalculateCost

func CalculateRemainingCost

func CalculateRemainingCost(count int64) int64

CalculateRemainingCost

func ConvertCreditToEuro

func ConvertCreditToEuro(total int64) float64

ConvertCreditToEuro converts credit value to euro

func GetRelatedUserGroupIDs

func GetRelatedUserGroupIDs(userGroups []*pbUser.RelatedUserGroup, db *pg.Tx) ([]uuid.UUID, error)

Select user groups in db with given ids in 'userGroups' Return ids slice Used in CreateUserGroup/UpdateUserGroup to add/update ids slice to recommended Artists

func GetRelatedUserGroups

func GetRelatedUserGroups(ids []uuid.UUID, db orm.DB) ([]*pbUser.RelatedUserGroup, error)

Select user groups in db with given 'ids' Return slice of UserGroup response

func GetTagIDs

func GetTagIDs(t []*pbUser.Tag, db *pg.Tx) ([]uuid.UUID, error)

GetTagIDs accepts a slice tags

func GetTags

func GetTags(tagIds []uuid.UUID, db *pg.DB) ([]*pbUser.Tag, error)

GetTags given tag UUID returns a Tag

func StringOrNull

func StringOrNull(str string) sql.NullString

StringOrNull returns properly configured sql.NullString

Types

type AccessRole

type AccessRole int32

AccessRole represents access role type

const (
	// SuperAdminRole has all permissions and can assign admins
	SuperAdminRole AccessRole = iota + 1 // 1

	// AdminRole has admin permissions across all tenants, except the ability to assign other Admins
	AdminRole // 2

	// TenantAdminRole has admin permissions over other users in their tenant.
	TenantAdminRole // 3

	// LabelRole is a like an artist user, but can manage their artists content.
	LabelRole // 4

	// ArtistRole is a like a standard user, but can have multiple personas and the ability to upload
	ArtistRole // 5

	// UserRole is a standard user
	UserRole // 6
)

type AccessToken

type AccessToken struct {
	IDRecord
	ClientID  uuid.UUID `bun:"type:uuid,notnull"`
	UserID    uuid.UUID `bun:"type:uuid"`
	Client    *Client   `bun:"rel:has-one"`
	User      *User     `bun:"rel:has-one"`
	Token     string    `bun:"type:varchar(40),unique,notnull"`
	ExpiresAt time.Time `bun:",notnull"`
	Scope     string    `bun:"type:varchar(200),notnull"`
}

OauthAccessToken ...

func NewOauthAccessToken

func NewOauthAccessToken(client *Client, user *User, expiresIn int, scope string) *AccessToken

NewOauthAccessToken creates new OauthAccessToken instance

type AuthUser

type AuthUser struct {
	ID       uuid.UUID
	TenantID int32
	Username string
	Email    string
	Role     AccessRole
}

AuthUser represents data stored in session/context for a user

type AuthorizationCode

type AuthorizationCode struct {
	IDRecord
	ClientID    uuid.UUID      `bun:"type:uuid,notnull"`
	UserID      uuid.UUID      `bun:"type:uuid,notnull"`
	Client      *Client        `bun:"rel:has-one"`
	User        *User          `bun:"rel:has-one"`
	Code        string         `bun:"type:varchar(40),unique,notnull"`
	RedirectURI sql.NullString `bun:"type:varchar(200)"`
	ExpiresAt   time.Time      `bun:",notnull"`
	Scope       string         `bun:"type:varchar(200),notnull"`
}

OauthAuthorizationCode ...

func NewOauthAuthorizationCode

func NewOauthAuthorizationCode(client *Client, user *User, expiresIn int, redirectURI, scope string) *AuthorizationCode

NewOauthAuthorizationCode creates new OauthAuthorizationCode instance

type Client

type Client struct {
	IDRecord
	Key                 string         `bun:"type:varchar(254),unique,notnull"`
	Secret              string         `bun:"type:varchar(60),notnull"`
	RedirectURI         sql.NullString `bun:"type:varchar(200)"`
	ApplicationName     sql.NullString `bun:"type:varchar(200)"`
	ApplicationHostname sql.NullString `bun:"type:varchar(200)"`
	ApplicationURL      sql.NullString `bun:"type:varchar(200)"`
}

OauthClient ...

type Credit

type Credit struct {
	IDRecord
	UserID uuid.UUID `bun:"type:uuid,notnull"`
	User   *User     `bun:"rel:has-one"`
	Total  int64     `bun:",notnull,default:128"`
}

Credit

type Email

type Email struct {
	Recipient string
	Subject   string
	Template  string
}

func NewOauthEmail

func NewOauthEmail(email, subject, template string) *Email

NewOauthEmail

type EmailToken

type EmailToken struct {
	IDRecord
	Reference   uuid.UUID `bun:"type:uuid,notnull,default:uuid_generate_v4()"`
	EmailSent   bool      `bun:",notnull,default:false"`
	EmailSentAt *time.Time
	ExpiresAt   time.Time `bun:",notnull"`
}

EmailTokenModel is an abstract model which can be used for objects from which we derive redirect emails (email confirmation, password reset and such)

func NewOauthEmailToken

func NewOauthEmailToken(expiresIn *time.Duration) *EmailToken

NewEmailToken creates new OauthEmailToken instance

type EmailTokenClaims

type EmailTokenClaims struct {
	Username  string `json:"username"`
	Reference string `json:"reference"`
	jwt.StandardClaims
}

func NewOauthEmailTokenClaims

func NewOauthEmailTokenClaims(email string, emailToken *EmailToken) *EmailTokenClaims

NewOauthEmailTokenClaims creates new NewOauthEmailTokenClaims instance

type GroupType

type GroupType struct {
	IDRecord
	Name        string `bun:",notnull"`
	Description string
}

type IDRecord

type IDRecord struct {
	ID        uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time
	DeletedAt time.Time `bun:",soft_delete"`
}

MyGormModel mimixks GormModel but uses uuid's for ID, generated in go

type Link struct {
	ID           uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	URI          string    `bun:",notnull"`
	Type         string
	Platform     string `bun:",notnull"`
	PersonalData bool   `bun:",notnull"`
}

Link is an internet hyperlink

type Logger

type Logger interface {
	// source, msg, error, params
	Log(context.Context, string, string, error, map[string]interface{})
}

Logger represents logging interface

type MembershipClass

type MembershipClass struct {
	IDRecord
	Name      string `bun:",notnull"`
	ProductID string `bun:",notnull"`
	PriceID   string `bun:",notnull"`
}

MembershipClass

type RBACService

type RBACService interface {
	EnforceRole(context.Context, AccessRole) bool
	EnforceUser(context.Context, uuid.UUID) bool
	EnforceTenant(context.Context, uuid.UUID) bool
	EnforceTenantAdmin(context.Context, int32) bool
	EnforceTenantAndRole(context.Context, AccessRole, int32) bool
	IsLowerRole(context.Context, AccessRole) bool
}

RBACService represents role-based access control service interface

type RefreshToken

type RefreshToken struct {
	IDRecord
	ClientID  uuid.UUID `bun:"type:uuid,notnull"`
	UserID    uuid.UUID `bun:"type:uuid"`
	Client    *Client   `bun:"rel:has-one"`
	User      *User     `bun:"rel:has-one"`
	Token     string    `bun:"type:varchar(40),unique,notnull"`
	ExpiresAt time.Time `bun:",notnull,default:now()"`
	Scope     string    `bun:"type:varchar(200),notnull"`
}

OauthRefreshToken ...

func NewOauthRefreshToken

func NewOauthRefreshToken(client *Client, user *User, expiresIn int, scope string) *RefreshToken

NewOauthRefreshToken creates new OauthRefreshToken instance

type Role

type Role struct {
	ID          int32  `bun:"type:,unique"`
	Name        string `bun:"type:varchar(50),unique,notnull"`
	Description string `bun:"type:varchar(200),notnull"`
	IsDefault   bool   `bun:"default:false"`
}

Role is a one of roles user can have

type Scope

type Scope struct {
	ID          int32  `bun:"type:,unique"`
	Name        string `bun:"type:varchar(50),unique,notnull"`
	Description string `bun:"type:varchar(200)"`
	IsDefault   bool   `bun:"default:false"`
}

OauthScope ...

type ShareTransaction

type ShareTransaction struct {
	IDRecord
	UserID    uuid.UUID `bun:"type:uuid,notnull"`
	User      *User     `bun:"rel:has-one"`
	InvoiceID string    `bun:",unique,notnull"`
	Quantity  int64     `bun:",notnull,"`
}

ShareTransaction model

type StreetAddress

type StreetAddress struct {
	ID           uuid.UUID         `bun:"type:uuid,default:uuid_generate_v4()"`
	PersonalData bool              `bun:",notnull"`
	Data         map[string]string `pg:",hstore"`
}

StreetAddress holds geographical data and marks if private

type StripeUser

type StripeUser struct {
	IDRecord
	CustomerID string    `bun:",unique,notnull"`
	UserID     uuid.UUID `bun:"type:uuid,notnull"`
	User       *User     `bun:"rel:has-one"`
}

Stripe User

type Tag

type Tag struct {
	ID   uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Type string    `bun:",notnull"`
	Name string    `bun:",notnull"`
}

Tag provides basic tag structure

func SearchTags

func SearchTags(query string, tagType string, db *pg.DB) ([]*Tag, error)

SearchTags find a tag by query string on Name

type Tenant

type Tenant struct {
	Id     uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Name   string    `json:"name"`
	Active bool      `json:"active"`
}

Tenant table

type User

type User struct {
	IDRecord
	LegacyID               int32  `bun:",type:serial,notnull,unique"`
	Username               string `bun:",notnull,unique"`
	FullName               string
	FirstName              string
	LastName               string
	EmailConfirmed         bool   `bun:"default:false"`
	Country                string `bun:"type:varchar(2)"`
	Member                 bool   `bun:"default:false,notnull"`
	NewsletterNotification bool
	FollowedGroups         []uuid.UUID  `bun:",type:uuid[],array"`
	OwnerOfGroups          []*UserGroup `bun:"rel:has-many"`
	TenantID               int32
	RoleID                 int32
	LastLogin              time.Time
	LastPasswordChange     time.Time
	Password               sql.NullString `bun:"type:varchar(60)"`
	Token                  string
}

User basic definition of a User and its meta

func (*User) UpdateLoginDetails

func (u *User) UpdateLoginDetails(token string)

UpdateLoginDetails updates login related fields

type UserGroup

type UserGroup struct {
	IDRecord
	DisplayName    string `bun:",unique,notnull"`
	Description    string
	ShortBio       string
	GroupEmail     string
	AddressID      uuid.UUID `bun:"type:uuid,notnull"` //for Country see User model
	Address        *StreetAddress
	TypeID         uuid.UUID `bun:"type:uuid,notnull"` //for e.g. Persona Type
	Type           *GroupType
	OwnerID        uuid.UUID   `bun:"type:uuid,notnull"`
	Owner          *User       `bun:"rel:has-one"`
	Links          []uuid.UUID `bun:",type:uuid[],array"`
	Members        []UserGroup `pg:"many2many:user_group_members,fk:user_group_id,joinFK:member_id"`
	MemberOfGroups []UserGroup `pg:"many2many:user_group_members,fk:member_id,joinFK:user_group_id"`
	Avatar         uuid.UUID   `bun:"type:uuid"`
	Banner         uuid.UUID   `bun:"type:uuid"`
	Tags           []uuid.UUID `bun:",type:uuid[],array"`
}

UserGroup represents a group of Users and maintains a set of metadata

func (*UserGroup) AddRecommended

func (u *UserGroup) AddRecommended(db *pg.DB, recommendedID uuid.UUID) (error, string)

func (*UserGroup) RemoveRecommended

func (u *UserGroup) RemoveRecommended(db *pg.DB, recommendedID uuid.UUID) (error, string)

type UserMembership

type UserMembership struct {
	IDRecord
	UserID            uuid.UUID `bun:"type:uuid,notnull"`
	User              *User     `bun:"rel:has-one"`
	MembershipClassID uuid.UUID `bun:"type:uuid,notnull"`
	MembershipClass   *MembershipClass
	SubscriptionID    string `bun:",unique,notnull"`
	Start             time.Time
	End               time.Time
}

UserMembership

Jump to

Keyboard shortcuts

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