models

package
v0.0.0-...-b8fb0c1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADMIN = "Admin"
	USER  = "User"

	AUTHCALLBACK   = "auth.callback"
	AUTHOAUTH      = "auth.oauth"
	AUTHREFRESH    = "auth.refresh"
	AUTHTOKEN      = "auth.token"
	PROPOSALCREATE = "proposal.create"
	PROPOSALDELETE = "proposal.delete"
	PROPOSALLIST   = "proposal.list"
	PROPOSALSHOW   = "proposal.show"
	PROPOSALUPDATE = "proposal.update"
	REVIEWCREATE   = "review.create"
	REVIEWDELETE   = "review.delete"
	REVIEWLIST     = "review.list"
	REVIEWSHOW     = "review.show"
	REVIEWUPDATE   = "review.update"
	USERCREATE     = "user.create"
	USERDELETE     = "user.delete"
	USERLIST       = "user.list"
	USERSHOW       = "user.show"
	USERUPDATE     = "user.update"
)

Variables

View Source
var RBAC *gorbac.RBAC

Functions

func Authorize

func Authorize(r Roler, perm string) bool

func ProposalFilterByUser

func ProposalFilterByUser(parentid int, originaldb *gorm.DB) func(db *gorm.DB) *gorm.DB

would prefer to just pass a context in here, but they're all different, so can't

func ReviewFilterByProposal

func ReviewFilterByProposal(parentid int, originaldb *gorm.DB) func(db *gorm.DB) *gorm.DB

would prefer to just pass a context in here, but they're all different, so can't

func ReviewFilterByUser

func ReviewFilterByUser(parentid int, originaldb *gorm.DB) func(db *gorm.DB) *gorm.DB

would prefer to just pass a context in here, but they're all different, so can't

Types

type Login

type Login struct {
	Email    string
	Password string
}

type Proposal

type Proposal struct {
	ID        int    `json:"ID,omitempty" gorm:"primary_key"`
	Abstract  string `json:"abstract,omitempty"`
	Detail    string `json:"detail,omitempty"`
	Firstname string `json:"firstname,omitempty"`
	Title     string `json:"title,omitempty"`
	Withdrawn bool   `json:"withdrawn,omitempty"`

	// Timestamps
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time

	// Foreign Keys
	UserID int

	// Children
	Reviews []Review
}

app.ProposalModel storage type Identifier:

func FilterProposalByUser

func FilterProposalByUser(parent int, list []Proposal) []Proposal

func ProposalFromCreatePayload

func ProposalFromCreatePayload(ctx *app.CreateProposalContext) Proposal

func ProposalFromUpdatePayload

func ProposalFromUpdatePayload(ctx *app.UpdateProposalContext) Proposal

func (Proposal) ToApp

func (m Proposal) ToApp() *app.Proposal

type ProposalDB

type ProposalDB struct {
	DB gorm.DB
}

func NewProposalDB

func NewProposalDB(db gorm.DB) *ProposalDB

func (*ProposalDB) Add

func (m *ProposalDB) Add(ctx context.Context, model Proposal) (Proposal, error)

func (*ProposalDB) Delete

func (m *ProposalDB) Delete(ctx context.Context, id int) error

func (*ProposalDB) List

func (m *ProposalDB) List(ctx context.Context) []Proposal

func (*ProposalDB) ListByUser

func (m *ProposalDB) ListByUser(ctx context.Context, parentid int) []Proposal

func (*ProposalDB) One

func (m *ProposalDB) One(ctx context.Context, id int) (Proposal, error)

func (*ProposalDB) OneByUser

func (m *ProposalDB) OneByUser(ctx context.Context, parentid, id int) (Proposal, error)

func (*ProposalDB) Update

func (m *ProposalDB) Update(ctx context.Context, model Proposal) error

type ProposalStorage

type ProposalStorage interface {
	List(ctx context.Context) []Proposal
	One(ctx context.Context, id int) (Proposal, error)
	Add(ctx context.Context, o Proposal) (Proposal, error)
	Update(ctx context.Context, o Proposal) error
	Delete(ctx context.Context, id int) error

	ListByUser(ctx context.Context, parentid int) []Proposal
	OneByUser(ctx context.Context, parentid, id int) (Proposal, error)
}

type Review

type Review struct {
	ID      int    `json:"ID,omitempty" gorm:"primary_key"`
	Comment string `json:"comment,omitempty"`
	Rating  int    `json:"rating,omitempty"`

	// Timestamps
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time

	// Foreign Keys
	ProposalID int
	UserID     int
}

app.ReviewModel storage type Identifier:

func FilterReviewByProposal

func FilterReviewByProposal(parent int, list []Review) []Review

func FilterReviewByUser

func FilterReviewByUser(parent int, list []Review) []Review

func ReviewFromCreatePayload

func ReviewFromCreatePayload(ctx *app.CreateReviewContext) Review

func ReviewFromUpdatePayload

func ReviewFromUpdatePayload(ctx *app.UpdateReviewContext) Review

func (Review) ToApp

func (m Review) ToApp() *app.Review

type ReviewDB

type ReviewDB struct {
	DB gorm.DB
}

func NewReviewDB

func NewReviewDB(db gorm.DB) *ReviewDB

func (*ReviewDB) Add

func (m *ReviewDB) Add(ctx context.Context, model Review) (Review, error)

func (*ReviewDB) Delete

func (m *ReviewDB) Delete(ctx context.Context, id int) error

func (*ReviewDB) List

func (m *ReviewDB) List(ctx context.Context) []Review

func (*ReviewDB) ListByProposal

func (m *ReviewDB) ListByProposal(ctx context.Context, parentid int) []Review

func (*ReviewDB) ListByUser

func (m *ReviewDB) ListByUser(ctx context.Context, parentid int) []Review

func (*ReviewDB) One

func (m *ReviewDB) One(ctx context.Context, id int) (Review, error)

func (*ReviewDB) OneByProposal

func (m *ReviewDB) OneByProposal(ctx context.Context, parentid, id int) (Review, error)

func (*ReviewDB) OneByUser

func (m *ReviewDB) OneByUser(ctx context.Context, parentid, id int) (Review, error)

func (*ReviewDB) Update

func (m *ReviewDB) Update(ctx context.Context, model Review) error

type ReviewStorage

type ReviewStorage interface {
	List(ctx context.Context) []Review
	One(ctx context.Context, id int) (Review, error)
	Add(ctx context.Context, o Review) (Review, error)
	Update(ctx context.Context, o Review) error
	Delete(ctx context.Context, id int) error

	ListByProposal(ctx context.Context, parentid int) []Review
	OneByProposal(ctx context.Context, parentid, id int) (Review, error)

	ListByUser(ctx context.Context, parentid int) []Review
	OneByUser(ctx context.Context, parentid, id int) (Review, error)
}

type Roler

type Roler interface {
	GetRole() string
}

Roler is an interface that provides a Role function which returns a string value representing the role to which a user belongs.

type User

type User struct {
	ID        int    `json:"ID,omitempty" gorm:"primary_key"`
	Bio       string `json:"bio,omitempty"`
	City      string `json:"city,omitempty"`
	Country   string `json:"country,omitempty"`
	Email     string `json:"email,omitempty"`
	Firstname string `json:"firstname,omitempty"`
	Lastname  string `json:"lastname,omitempty"`
	Role      string `json:"role,omitempty"`
	State     string `json:"state,omitempty"`

	// Timestamps
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time

	// Children
	Proposals []Proposal
	Reviews   []Review

	// Auth
	Password string

	// OAuth2
	Oauth2Uid      string
	Oauth2Provider string
	Oauth2Token    string
	Oauth2Refresh  string
	Oauth2Expiry   time.Time

	// Confirm
	ConfirmToken string
	Confirmed    bool

	// Lock
	AttemptNumber int64
	AttemptTime   time.Time
	Locked        time.Time

	// Recover
	RecoverToken       string
	RecoverTokenExpiry time.Time
}

app.UserModel storage type Identifier:

func UserFromCreatePayload

func UserFromCreatePayload(ctx *app.CreateUserContext) User

func UserFromUpdatePayload

func UserFromUpdatePayload(ctx *app.UpdateUserContext) User

func (*User) BeforeCreate

func (u *User) BeforeCreate() (err error)

func (User) GetRole

func (m User) GetRole() string

func (User) ToApp

func (m User) ToApp() *app.User

type UserDB

type UserDB struct {
	DB gorm.DB
}

func NewUserDB

func NewUserDB(db gorm.DB) *UserDB

func (*UserDB) Add

func (m *UserDB) Add(ctx context.Context, model User) (User, error)

func (*UserDB) ConfirmUser

func (m *UserDB) ConfirmUser(confirmToken string) (interface{}, error)

func (*UserDB) Create

func (m *UserDB) Create(email string, attr authboss.Attributes) error

func (*UserDB) Delete

func (m *UserDB) Delete(ctx context.Context, id int) error

func (*UserDB) Get

func (m *UserDB) Get(email string) (interface{}, error)

func (*UserDB) GetByLogin

func (m *UserDB) GetByLogin(ctx context.Context, l Login) (User, error)

func (*UserDB) List

func (m *UserDB) List(ctx context.Context) []User

func (*UserDB) One

func (m *UserDB) One(ctx context.Context, id int) (User, error)

func (*UserDB) Put

func (m *UserDB) Put(email string, attr authboss.Attributes) error

func (*UserDB) RecoverUser

func (m *UserDB) RecoverUser(recoverToken string) (interface{}, error)

func (*UserDB) Update

func (m *UserDB) Update(ctx context.Context, model User) error

func (*UserDB) UserByOauth

func (m *UserDB) UserByOauth(id, provider string) (User, error)

type UserStorage

type UserStorage interface {
	List(ctx context.Context) []User
	One(ctx context.Context, id int) (User, error)
	Add(ctx context.Context, o User) (User, error)
	Update(ctx context.Context, o User) error
	Delete(ctx context.Context, id int) error
}

Jump to

Keyboard shortcuts

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