added comments
This commit is contained in:
@ -14,11 +14,13 @@ const (
|
||||
RoleGuest Role = "guest"
|
||||
)
|
||||
|
||||
// InvalidJWT Represents a JWT that has expired or is otherwise invalid.
|
||||
type InvalidJWT struct {
|
||||
JWT string `gorm:"primarykey"`
|
||||
ValidUntil time.Time
|
||||
}
|
||||
|
||||
// User represents a user with an ID, UUID, name, role, and password.
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"-"`
|
||||
UUID uuid.UUID `gorm:"type:uuid" json:"uuid"`
|
||||
@ -27,6 +29,7 @@ type User struct {
|
||||
Password []byte `json:"-"`
|
||||
}
|
||||
|
||||
// NewUser creates a new User struct with a generated UUID.
|
||||
func NewUser() User {
|
||||
return User{
|
||||
UUID: uuid.New(),
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Post represents a blog post with associated comments and user ID.
|
||||
type Post struct {
|
||||
gorm.Model
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
@ -13,6 +14,8 @@ type Post struct {
|
||||
Comments []Comment
|
||||
UserID uint `gorm:"->;<-:create"`
|
||||
}
|
||||
|
||||
// Comment represents a comment on a post, including its ID, post association, content, and creator.
|
||||
type Comment struct {
|
||||
ID uint
|
||||
PostID uint
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Init initializes the database connection, auto-migrates models, and seeds a default post.
|
||||
func Init() *gorm.DB {
|
||||
db, err := gorm.Open(sqlite.Open("./blog.db"))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user