add users
This commit is contained in:
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user