From 52a6bf5be6d777c072a7ebde1261e8843fc495ef Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 19 Jan 2023 12:47:23 +0200 Subject: [PATCH] feat(sdbapi): replace gorm.Model with own fields --- sdbapi/models/game.go | 15 ++++++++++----- sdbapi/models/user.go | 14 +++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sdbapi/models/game.go b/sdbapi/models/game.go index 80e111e..19a8a5b 100644 --- a/sdbapi/models/game.go +++ b/sdbapi/models/game.go @@ -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"` } diff --git a/sdbapi/models/user.go b/sdbapi/models/user.go index 130483d..a98d88e 100644 --- a/sdbapi/models/user.go +++ b/sdbapi/models/user.go @@ -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 -- 2.44.1