models

package
v0.0.0-...-e9bd53e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	ID        string         `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

BaseModel a basic Go struct which includes the following fields: ID (GUID), CreatedAt, UpdatedAt, DeletedAt

func (*BaseModel) BeforeCreate

func (m *BaseModel) BeforeCreate(tx *gorm.DB) (err error)

type Game

type Game struct {
	BaseModel
	Rows        int        `json:"rows"`
	Cols        int        `json:"cols"`
	Mines       int        `json:"mines"`
	Status      string     `json:"status"`
	GameState   JSONB      `json:"gameState" gorm:"type:jsonb"`
	StartedAt   *time.Time `json:"startedAt,omitempty"`
	FinishedAt  *time.Time `json:"finishedAt,omitempty"`
	CreatedByID string     `json:"-"`         // who created this game - id needed by GORM
	CreatedBy   *User      `json:"createdBy"` // who created this game
}

Game contains the structure of the game

func (*Game) GetGameState

func (g *Game) GetGameState() (game *engine.Game)

func (*Game) UpdateGameState

func (g *Game) UpdateGameState(game *engine.Game)

type JSONB

type JSONB map[string]interface{}

func (*JSONB) Scan

func (j *JSONB) Scan(value interface{}) error

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

type User

type User struct {
	BaseModel
	Email     string       `json:"email" gorm:"uniqueIndex"`
	Username  string       `json:"username" gorm:"uniqueIndex"`
	Password  string       `json:"password"`
	Fullname  string       `json:"fullname"`
	APIKeys   []UserAPIKey `json:"apiKeys"`
	Admin     bool         `json:"-" gorm:"default:false"` // FUTURE: proper RBAC, roles, permissions, etc.
	CreatedAt time.Time    `json:"-"`
	UpdatedAt time.Time    `json:"-"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate hook that runs before entity create

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate hook to run before entity update

type UserAPIKey

type UserAPIKey struct {
	ID        uint      `json:"-" gorm:"primarykey"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
	APIKey    string    `gorm:"unique" json:"apiKey"`
	UserID    string    `json:"-"`
	User      User      `json:"-"`
}

func (*UserAPIKey) BeforeCreate

func (uak *UserAPIKey) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate hook to run before entity create

Jump to

Keyboard shortcuts

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