models

package
v0.0.0-...-d378361 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2017 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyEmail       = errors.New("empty email")
	ErrWrongEmailFormat = errors.New("wrong email format")
)
View Source
var (
	ErrEmptyPassword       = errors.New("empty password")
	ErrWrongPasswordFormat = errors.New("wrong password format")
)
View Source
var (
	ErrEmptyName       = errors.New("empty name")
	ErrWrongNameFormat = errors.New("wrong name format")
)
View Source
var (
	ErrTextTooLong = errors.New("text too long")

	MaxTextLen = 500
)
View Source
var (
	ErrEmptyLabel = errors.New("label can not be empty!")
)
View Source
var ErrIdMustBeOmitted = errors.New("id must be omitted")
View Source
var ErrIdMustBePresent = errors.New("id must be present")
View Source
var ErrInvalidId = errors.New("invalid id")

Functions

func ErrInvalidCast

func ErrInvalidCast(got, expected interface{}) error

Helper to generate error message about bad cast.

Types

type AutoId

type AutoId struct{ Id }

AutoId helpers

func NewAutoId

func NewAutoId() AutoId

New auto Id

func (AutoId) Validate

func (id AutoId) Validate() error

Validates generated id

type Email

type Email string

func SafeCastToEmail

func SafeCastToEmail(data interface{}) (Email, error)

func (Email) Validate

func (e Email) Validate() error

Validates email

type Id

type Id struct{ bson.ObjectId }

General Id helpers

func (Id) GetBSON

func (id Id) GetBSON() (interface{}, error)

func (Id) MarshalJSON

func (id Id) MarshalJSON() ([]byte, error)

func (*Id) SetBSON

func (id *Id) SetBSON(raw bson.Raw) error

func (*Id) UnmarshalJSON

func (id *Id) UnmarshalJSON(data []byte) error

func (Id) Validate

func (id Id) Validate() error

Validates id

type Label

type Label string

func (Label) Validate

func (l Label) Validate() error

type LabelsList

type LabelsList []Label

type Name

type Name string

func (Name) Validate

func (n Name) Validate() error

Validates names

type OptionalId

type OptionalId struct{ Id }

Optional Id helpers

func (OptionalId) Validate

func (id OptionalId) Validate() error

Validates optional id

type Password

type Password string

func (Password) Validate

func (p Password) Validate() error

Validates password

type Project

type Project struct {
	Id          AutoId       `json:"_id,omitempty" bson:"_id,omitempty"`
	Title       Name         `json:"title" bson:"title"`
	Description Text         `json:"description,omitempty" bson:"description,omitempty"`
	Users       []RequiredId `json:"users,omitempty" bson:"users,omitempty"`
	Tasks       []RequiredId `json:"tasks,omitempty" bson:"tasks,omitempty"`
}

func SafeCastToProject

func SafeCastToProject(data interface{}) (Project, error)

func (Project) Validate

func (p Project) Validate() error

Validates project.

type ProjectUser

type ProjectUser struct {
	ProjectId RequiredId
	UserId    RequiredId
}

Helper for both project and user ids.

func SafeCastToProjectUser

func SafeCastToProjectUser(data interface{}) (ProjectUser, error)

type ProjectsList

type ProjectsList []Project

type RequiredId

type RequiredId struct{ Id }

RequiredId helpers

func NewRequiredId

func NewRequiredId(hex string) (RequiredId, error)

New required id

func SafeCastToRequiredId

func SafeCastToRequiredId(data interface{}) (RequiredId, error)

func (RequiredId) Validate

func (id RequiredId) Validate() error

Validates required id

type Task

type Task struct {
	Id          AutoId     `json:"_id,omitempty" bson:"_id,omitempty"`
	Title       Name       `json:"title" bson:"title"`
	ProjectId   RequiredId `json:"project_id" bson:"project_id"`
	Description Text       `json:"description,omitempty" bson:"description,omitempty"`
	InitiatorId RequiredId `json:"initiator_id" bson:"initiator_id"`
	AssigneeId  OptionalId `json:"assignee_id,omitempty" bson:"assignee_id,omitempty"`
	Labels      LabelsList `json:"labels,omitempty" bson:"labels,omitempty"`
}

func SafeCastToTask

func SafeCastToTask(data interface{}) (Task, error)

func (Task) Validate

func (t Task) Validate() error

Validates Task

type TaskLabel

type TaskLabel struct {
	TaskId RequiredId
	Label  Label
}

func SafeCastToTaskLabel

func SafeCastToTaskLabel(data interface{}) (TaskLabel, error)

type TasksList

type TasksList []Task

type Text

type Text string

func (Text) Validate

func (t Text) Validate() error

Validate text

type User

type User struct {
	Id       AutoId       `json:"_id" bson:"_id,omitempty"`
	Email    Email        `json:"email" bson:"email"`
	Password Password     `json:"password,omitempty" bson:"password"`
	Name     Name         `json:"name" bson:"name"`
	Bio      Text         `json:"bio,omitempty" bson:"bio,omitempty"`
	Projects []RequiredId `json:"projects,omitempty" bson:"projects,omitempty"`
}

func SafeCastToUser

func SafeCastToUser(data interface{}) (User, error)

func (*User) Encrypt

func (u *User) Encrypt()

func (User) Validate

func (u User) Validate() error

Returns validation error or nil if valid

type UsersList

type UsersList []User

Jump to

Keyboard shortcuts

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