Add: Versions, WIP
This commit is contained in:
parent
0ae5265915
commit
00a49ae585
@ -41,13 +41,17 @@ func (s *StoreGorm) AddPage(name string, body string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreGorm) CreatePage(page Page) error {
|
func (s *StoreGorm) CreatePage(page Page) error {
|
||||||
tx := s.db.Save(&page)
|
newversion := new(Page)
|
||||||
|
newversion.Name = page.Name
|
||||||
|
newversion.Body = page.Body
|
||||||
|
newversion.Version = page.Version + 1
|
||||||
|
tx := s.db.Save(newversion)
|
||||||
return tx.Error
|
return tx.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreGorm) GetPage(name string) (Page, error) {
|
func (s *StoreGorm) GetPage(name string) (Page, error) {
|
||||||
var page Page
|
var page Page
|
||||||
tx := s.db.Where("Name = ?", name).First(&page)
|
tx := s.db.Where("Name = ?", name).Order("Version desc").First(&page)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return Page{}, tx.Error
|
return Page{}, tx.Error
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<h1>List</h1>
|
<h1>List</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{{ range .pages }}
|
{{ range .pages }}
|
||||||
<li><a href="{{ .Name }}">{{ .Name }}</a>.- {{ .Body }}</li>
|
<li><a href="{{ .Name }}">{{ .Name }}, v{{ .Version }}</a>.- {{ .Body }}</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user