model

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const RolesCollectionName = "roles"
View Source
const UserCollectionName = "users"

Variables

This section is empty.

Functions

This section is empty.

Types

type Role

type Role struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	Code      RoleCode           `bson:"code" validate:"required,rolecode"`
	Status    bool               `bson:"status" validate:"required"`
	CreatedAt time.Time          `bson:"createdAt" validate:"required"`
	UpdatedAt time.Time          `bson:"updatedAt" validate:"required"`
}

func NewRole

func NewRole(code RoleCode) (*Role, error)

func (*Role) EnsureIndexes

func (*Role) EnsureIndexes(db mongo.Database)

func (*Role) GetValue

func (role *Role) GetValue() *Role

func (*Role) Validate

func (role *Role) Validate() error

type RoleCode

type RoleCode string
const (
	RoleCodeLearner RoleCode = "LEARNER"
	RoleCodeAdmin   RoleCode = "ADMIN"
	RoleCodeAuthor  RoleCode = "AUTHOR"
	RoleCodeEditor  RoleCode = "EDITOR"
)

type User

type User struct {
	ID            primitive.ObjectID   `bson:"_id,omitempty"`
	Name          string               `bson:"name" validate:"required,max=200"`
	Email         string               `bson:"email" validate:"required,email"`
	Password      *string              `bson:"password" validate:"required,min=6,max=100"`
	ProfilePicURL *string              `bson:"profilePicUrl,omitempty" validate:"omitempty,max=500"`
	Roles         []primitive.ObjectID `bson:"roles,omitempty" validate:"required"`
	Verified      bool                 `bson:"verified" validate:"-"`
	Status        bool                 `bson:"status" validate:"-"`
	CreatedAt     time.Time            `bson:"createdAt" validate:"required"`
	UpdatedAt     time.Time            `bson:"updatedAt" validate:"required"`

	// docs
	RoleDocs []*Role `bson:"-" validate:"-"`
}

func NewUser

func NewUser(email string, pwdHash string, name string, profilePicUrl *string, roles []*Role) (*User, error)

func (*User) EnsureIndexes

func (*User) EnsureIndexes(db mongo.Database)

func (*User) GetValue

func (user *User) GetValue() *User

func (*User) Validate

func (user *User) Validate() error

Jump to

Keyboard shortcuts

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