show first entry
This commit is contained in:
9
backend/model/auth.go
Normal file
9
backend/model/auth.go
Normal file
@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
type Login struct {
|
||||
Name string `json:"name"`
|
||||
Password string `json:"Password"`
|
||||
}
|
||||
type LoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
}
|
19
backend/model/blog.go
Normal file
19
backend/model/blog.go
Normal file
@ -0,0 +1,19 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
gorm.Model
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Title string `json:"title"`
|
||||
TLDR string `json:"tldr"`
|
||||
Content string `json:"content"`
|
||||
Comments []Comment
|
||||
}
|
||||
type Comment struct {
|
||||
ID uint
|
||||
PostID uint
|
||||
Content string `json:"content"`
|
||||
}
|
40
backend/model/init.go
Normal file
40
backend/model/init.go
Normal file
@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Init() *gorm.DB {
|
||||
db, err := gorm.Open(sqlite.Open("./blog.db"))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
db.AutoMigrate(&Post{}, &Comment{})
|
||||
|
||||
db.Save(&Post{
|
||||
ID: 1,
|
||||
Title: "Foo",
|
||||
TLDR: "Just some Foo Bar",
|
||||
Content: "fkdj kjfk adjflkjdlö jdslj alsödj fla",
|
||||
})
|
||||
db.Save(&Post{
|
||||
ID: 2,
|
||||
Title: "Bar",
|
||||
TLDR: "Just some Bar Baz",
|
||||
Content: `
|
||||
# Hello Worls
|
||||
|
||||
- alsödj
|
||||
- adf adf
|
||||
|
||||
| adsf | asdf |
|
||||
|------|------|
|
||||
| adf | adsf |
|
||||
`,
|
||||
})
|
||||
|
||||
return db
|
||||
}
|
Reference in New Issue
Block a user