feat: dialog to change template metadata in editor

This commit is contained in:
2024-12-03 18:34:23 +00:00
parent 4e34570792
commit e5bbd15837
10 changed files with 369 additions and 72 deletions

View File

@@ -30,7 +30,12 @@ type createTemplateOptions struct {
}
type updateTemplateOptions struct {
tx *bun.Tx
tx *bun.Tx
// name is the new name for the template
name string
// description is the new description for the template
description string
}
@@ -183,10 +188,29 @@ func (mgr *templateManager) updateTemplate(ctx context.Context, name string, opt
tx = &_tx
}
if opts.name != "" {
exists, err := tx.NewSelect().
Table("templates").
Where("name = ?", opts.name).
Exists(ctx)
if err != nil {
return nil, err
}
if exists {
return nil, errTemplateExists
}
}
var template template
err := tx.NewUpdate().Model(&template).
Where("Name = ?", name).
Set("description = ?", opts.description).
q := tx.NewUpdate().Model(&template).Where("name = ?", name)
if opts.name != "" {
q = q.Set("name = ?", opts.name)
}
if opts.description != "" {
q = q.Set("description = ?", opts.description)
}
err := q.
Returning("*").
Scan(ctx)
if err != nil {