From ce61d3db96e0539c8df1886ac635e7e85dbde31f Mon Sep 17 00:00:00 2001 From: roerick Date: Fri, 17 Oct 2025 15:32:19 -0600 Subject: initial commit, models not working --- models/models.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 models/models.go (limited to 'models') diff --git a/models/models.go b/models/models.go new file mode 100644 index 0000000..1ccf37f --- /dev/null +++ b/models/models.go @@ -0,0 +1,30 @@ +package models + + +type User struct { + ID uint `gorm:"primaryKey" json:"id"` + Username string `gorm:"unique;not null" json:"username"` + Password string `gorm:"not null" json:"-"` + Blogs []Blog `gorm:"foreignKey:UserID" json:"blogs"` + Comments []Comment `gorm:"foreignKey:UserID" json:"comments"` +} + +type Blog struct { + ID uint `gorm:"primaryKey" json:"id"` + Title string `gorm:"not null" json:"title"` + Content string `gorm:"not null" json:"content"` + UserID uint `gorm:"not null" json:"user_id"` + User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"` + Comments []Comment `gorm:"foreignKey:BlogID" json:"comments"` +} + +type Comment struct { + ID uint `gorm:"primaryKey" json:"id"` + Content string `gorm:"not null" json:"content"` + UserID uint `gorm:"not null" json:"user_id"` + BlogID uint `gorm:"not null" json:"blog_id"` + User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"` + Blog Blog `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"blog"` +} + + -- cgit v1.2.3