models

package
v0.0.0-...-eecba0e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type User

type User struct {
	ID          int `gorm:"primary_key"` // This is the User Model PK field
	CreatedAt   time.Time
	DeletedAt   *time.Time
	Description string
	Title       string
	UpdatedAt   time.Time
}

User Model Description

func UserFromUserPayload

func UserFromUserPayload(payload *app.UserPayload) *User

UserFromUserPayload Converts source UserPayload to target User model only copying the non-nil fields from the source.

func (User) TableName

func (m User) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

func (*User) UserToApplicationVndUser

func (m *User) UserToApplicationVndUser() *app.ApplicationVndUser

UserToApplicationVndUser loads a User and builds the default view of media type ApplicationVndUser.

type UserDB

type UserDB struct {
	Db *gorm.DB
}

UserDB is the implementation of the storage interface for User.

func NewUserDB

func NewUserDB(db *gorm.DB) *UserDB

NewUserDB creates a new storage type.

func (*UserDB) Add

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

Add creates a new record.

func (*UserDB) DB

func (m *UserDB) DB() interface{}

DB returns the underlying database.

func (*UserDB) Delete

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

Delete removes a single record.

func (*UserDB) Get

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

Get returns a single User as a Database Model This is more for use internally, and probably not what you want in your controllers

func (*UserDB) List

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

List returns an array of User

func (*UserDB) ListApplicationVndUser

func (m *UserDB) ListApplicationVndUser(ctx context.Context) []*app.ApplicationVndUser

ListApplicationVndUser returns an array of view: default.

func (*UserDB) OneApplicationVndUser

func (m *UserDB) OneApplicationVndUser(ctx context.Context, id int) (*app.ApplicationVndUser, error)

OneApplicationVndUser loads a User and builds the default view of media type ApplicationVndUser.

func (*UserDB) TableName

func (m *UserDB) TableName() string

TableName overrides the table name settings in Gorm to force a specific table name in the database.

func (*UserDB) Update

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

Update modifies a single record.

func (*UserDB) UpdateFromUserPayload

func (m *UserDB) UpdateFromUserPayload(ctx context.Context, payload *app.UserPayload, id int) error

UpdateFromUserPayload applies non-nil changes from UserPayload to the model and saves it

type UserStorage

type UserStorage interface {
	DB() interface{}
	List(ctx context.Context) ([]*User, error)
	Get(ctx context.Context, id int) (*User, error)
	Add(ctx context.Context, user *User) error
	Update(ctx context.Context, user *User) error
	Delete(ctx context.Context, id int) error

	ListApplicationVndUser(ctx context.Context) []*app.ApplicationVndUser
	OneApplicationVndUser(ctx context.Context, id int) (*app.ApplicationVndUser, error)

	UpdateFromUserPayload(ctx context.Context, payload *app.UserPayload, id int) error
}

UserStorage represents the storage interface.

Jump to

Keyboard shortcuts

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