DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

52a6bf5be6d777c072a7ebde1261e8843fc495ef — Jonni Liljamo 1 year, 8 months ago 1c410e9
feat(sdbapi): replace gorm.Model with own fields
2 files changed, 19 insertions(+), 10 deletions(-)

M sdbapi/models/game.go
M sdbapi/models/user.go
M sdbapi/models/game.go => sdbapi/models/game.go +10 -5
@@ 9,6 9,8 @@
package models

import (
	"time"

	"gorm.io/gorm"
)



@@ 19,9 21,12 @@ const (
)

type Game struct {
	gorm.Model
	ID    string `json:"id" gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
	P1    User   `json:"p1" gorm:"foreignkey:ID"`
	P2    User   `json:"p2" gorm:"foreignkey:ID"`
	State uint8  `json:"state" gorm:"type:smallint"`
	ID        string `json:"id" gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	P1        User           `json:"p1" gorm:"foreignkey:ID"`
	P2        User           `json:"p2" gorm:"foreignkey:ID"`
	State     uint8          `json:"state" gorm:"type:smallint"`
	EndedAt   time.Time      `json:"ended_at" gorm:"type:timestamptz"`
}

M sdbapi/models/user.go => sdbapi/models/user.go +9 -5
@@ 9,16 9,20 @@
package models

import (
	"time"

	"golang.org/x/crypto/bcrypt"
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	ID       string `json:"id" gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
	Username string `json:"username" gorm:"unique"`
	Email    string `json:"email" gorm:"unique"`
	Password string `json:"password"`
	ID        string `json:"id" gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	Username  string         `json:"username" gorm:"unique"`
	Email     string         `json:"email" gorm:"unique"`
	Password  string         `json:"password"`
}

// hash a users password