From b75c7c6a9a040af03ef8b498c88c267bfa00aaf4 Mon Sep 17 00:00:00 2001 From: ckrinitsin <101062646+ckrinitsin@users.noreply.github.com> Date: Thu, 24 Apr 2025 23:54:17 +0200 Subject: Authentication (#1) * add login and register templates * add jwt and gin-contrib dependencies * add List database table * add authentication * add logout --- models/database.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'models') diff --git a/models/database.go b/models/database.go index 2daaa1e..ffc8a47 100644 --- a/models/database.go +++ b/models/database.go @@ -1,18 +1,28 @@ package models import ( + "os" "time" "gorm.io/driver/sqlite" "gorm.io/gorm" ) +type List struct { + Name string `gorm:"primaryKey"` + Password []byte + CreatedAt time.Time + UpdatedAt time.Time + Entries []Entry +} + type Entry struct { ID uint `gorm:"primaryKey"` Text string Checked bool CreatedAt time.Time UpdatedAt time.Time + ListName string } var DB *gorm.DB @@ -24,7 +34,17 @@ func ConnectDatabase() { panic("Failed to connect to database!") } + db.AutoMigrate(&List{}) db.AutoMigrate(&Entry{}) DB = db } + +func BasePath() string { + basePath := os.Getenv("BASE_PATH") + if basePath == "" { + basePath = "/" + } + + return basePath +} -- cgit 1.4.1