add users

This commit is contained in:
u80864958
2025-04-30 16:41:30 +02:00
parent f4adfb6a62
commit eed1718a7e
17 changed files with 538 additions and 60 deletions

View File

@ -1,9 +1,34 @@
package model
type Login struct {
Name string `json:"name"`
Password string `json:"Password"`
import (
"time"
"github.com/google/uuid"
)
type Role string
const (
RoleAdmin Role = " admin"
RoleUser Role = "user"
RoleGuest Role = "guest"
)
type InvalidJWT struct {
JWT string `gorm:"primarykey"`
ValidUntil time.Time
}
type LoginResponse struct {
Token string `json:"token"`
type User struct {
ID uint `gorm:"primarykey" json:"-"`
UUID uuid.UUID `gorm:"type:uuid" json:"uuid"`
Name string `json:"name" gorm:"unique"`
Role Role `json:"role"`
Password []byte `json:"-"`
}
func NewUser() User {
return User{
UUID: uuid.New(),
}
}

View File

@ -11,9 +11,11 @@ type Post struct {
TLDR string `json:"tldr"`
Content string `json:"content"`
Comments []Comment
UserID uint `gorm:"->;<-:create"`
}
type Comment struct {
ID uint
PostID uint
Content string `json:"content"`
UserID uint `gorm:"->;<-:create"`
}

View File

@ -12,7 +12,7 @@ func Init() *gorm.DB {
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Post{}, &Comment{})
db.AutoMigrate(&Post{}, &Comment{}, &User{}, &InvalidJWT{})
db.Save(&Post{
ID: 1,