-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
53 lines (44 loc) · 1.16 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
//"log"
"strings"
"time"
)
type Template struct {
Id int `xorm:"SERIAL index"`
StoreId int `xorm:"INT not null unique(template)" form:"-" json:"-"`
ThemeId int `xorm:"INT not null unique(template)" binding:"required"`
Name string `xorm:"not null unique(template)" binding:"required"`
Content string
CreatedAt time.Time
UpdatedAt time.Time
}
type TemplateContext struct {
Page *Page
Store *Store
}
func (context TemplateContext) Collections() []Collection {
collections, _ := GetCollections(context.Store.Id)
return collections
}
func (template *Template) create() error {
template.CreatedAt = time.Now().UTC()
template.UpdatedAt = time.Now().UTC()
_, err := _engine.Insert(template)
if err != nil {
errMsg := err.Error()
if strings.Contains(errMsg, "UNIQUE constraint failed:") {
myErr := appError{Ex: err, Message: "template name was already existing.", Code: 4001}
return &myErr
}
return err
} else {
return nil
}
}
func getTemplates(storeId int) *[]Template {
templates := make([]Template, 0)
err := _engine.Where("store_id = ?", storeId).Find(&templates)
PanicIf(err)
return &templates
}