mirror of
https://github.com/cuigh/swirl
synced 2024-12-30 15:53:24 +00:00
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package biz
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/cuigh/auxo/data/guid"
|
|
"github.com/cuigh/auxo/net/web"
|
|
"github.com/cuigh/swirl/dao"
|
|
"github.com/cuigh/swirl/model"
|
|
)
|
|
|
|
// Template return a service template biz instance.
|
|
var Template = &templateBiz{}
|
|
|
|
type templateBiz struct {
|
|
}
|
|
|
|
func (b *templateBiz) List(args *model.TemplateListArgs) (tpls []*model.Template, count int, err error) {
|
|
do(func(d dao.Interface) {
|
|
tpls, count, err = d.TemplateList(args)
|
|
})
|
|
return
|
|
}
|
|
|
|
func (b *templateBiz) Create(tpl *model.Template, user web.User) (err error) {
|
|
do(func(d dao.Interface) {
|
|
tpl.ID = guid.New()
|
|
err = d.TemplateCreate(tpl)
|
|
if err == nil {
|
|
Event.CreateServiceTemplate(model.EventActionCreate, tpl.ID, tpl.Name, user)
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
func (b *templateBiz) Get(id string) (tpl *model.Template, err error) {
|
|
do(func(d dao.Interface) {
|
|
tpl, err = d.TemplateGet(id)
|
|
})
|
|
return
|
|
}
|
|
|
|
func (b *templateBiz) Delete(id string, user web.User) (err error) {
|
|
do(func(d dao.Interface) {
|
|
var tpl *model.Template
|
|
tpl, err = d.TemplateGet(id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = d.TemplateDelete(id)
|
|
if err == nil {
|
|
Event.CreateServiceTemplate(model.EventActionDelete, id, tpl.Name, user)
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
func (b *templateBiz) Update(tpl *model.Template, user web.User) (err error) {
|
|
do(func(d dao.Interface) {
|
|
tpl.UpdatedBy = user.ID()
|
|
tpl.UpdatedAt = time.Now()
|
|
err = d.TemplateUpdate(tpl)
|
|
if err == nil {
|
|
Event.CreateServiceTemplate(model.EventActionUpdate, tpl.ID, tpl.Name, user)
|
|
}
|
|
})
|
|
return
|
|
}
|