diff options
| author | ckrinitsin <101062646+ckrinitsin@users.noreply.github.com> | 2025-04-24 23:54:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-24 23:54:17 +0200 |
| commit | b75c7c6a9a040af03ef8b498c88c267bfa00aaf4 (patch) | |
| tree | 8b30f8b1269fe985a1fe0d5cca8b771a6e7484ff /models/database.go | |
| parent | 1e974f70a6c262d0b5db8b177ebb02b46446bfb0 (diff) | |
| download | shopping-list-b75c7c6a9a040af03ef8b498c88c267bfa00aaf4.tar.gz shopping-list-b75c7c6a9a040af03ef8b498c88c267bfa00aaf4.zip | |
Authentication (#1)
* add login and register templates * add jwt and gin-contrib dependencies * add List database table * add authentication * add logout
Diffstat (limited to 'models/database.go')
| -rw-r--r-- | models/database.go | 20 |
1 files changed, 20 insertions, 0 deletions
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 +} |