You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: view.go
    path of file: ./repos/clickvisual/api/internal/api/apiv1/base
    
    the code of the file until where you have to start completion: package base

import (
	"strconv"
	"strings"

	"github.com/ego-component/egorm"
	"github.com/spf13/cast"

	"github.com/clickvisual/clickvisual/api/internal/invoker"
	"github.com/clickvisual/clickvisual/api/internal/pkg/component/core"
	db2 "github.com/clickvisual/clickvisual/api/internal/pkg/model/db"
	view2 "github.com/clickvisual/clickvisual/api/internal/pkg/model/view"
	"github.com/clickvisual/clickvisual/api/internal/service"
	"github.com/clickvisual/clickvisual/api/internal/service/event"
	"github.com/clickvisual/clickvisual/api/internal/service/permission"
	"github.com/clickvisual/clickvisual/api/internal/service/permission/pmsplugin"
)

// ViewDelete
// @Summary		 删除视图
// @Tags         LOGSTORE
func ViewDelete(c *core.Context) {
	var err error
	id := cast.ToInt(c.Param("id"))
	if id == 0 {
		c.JSONE(1, "error id", nil)
		return
	}
	if id == -1 {
		c.JSONE(1, "default time field not support delete", nil)
		return
	}
	var viewInfo db2.BaseView
	viewInfo, err = db2.ViewInfo(invoker.Db, id)
	if err != nil {
		c.JSONE(1, err.Error(), nil)
		return
	}
	tableInfo, err := db2.TableInfo(invoker.Db, viewInfo.Tid)
	if err != nil {
		c.JSONE(1, err.Error(), nil)
		return
	}
	if err = permission.Manager.CheckNormalPermission(view2.ReqPermission{
		UserId:      c.Uid(),
		ObjectType:  pmsplugin.PrefixInstance,
		ObjectIdx:   strconv.Itoa(tableInfo.Database.Iid),
		SubResource: pmsplugin.Log,
		Acts:        []string{pmsplugin.ActDelete},
		DomainType:  pmsplugin.PrefixTable,
		DomainId:    strconv.Itoa(tableInfo.ID),
	}); err != nil {
		c.JSONE(1, "permission verification failed", err)
		return
	}
	tx := invoker.Db.Begin()
	err = db2.ViewDelete(tx, id)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}
	var viewList []*db2.BaseView
	conds := egorm.Conds{}
	conds["tid"] = viewInfo.Tid
	viewList, err = db2.ViewList(tx, conds)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}

	databaseInfo, _ := db2.DatabaseInfo(tx, tableInfo.Did)
	op, er
    
func ViewUpdate(c *core.Context) {
	var err error
	id := cast.ToInt(c.Param("id"))
	if id < 1 {
		c.JSONE(1, "error id", nil)
		return
	}
	params := view2.ReqViewCreate{}
	err = c.Bind(&params)
	if err != nil {
		c.JSONE(1, err.Error(), nil)
		return
	}
	tx := invoker.Db.Begin()
	ups := make(map[string]interface{}, 0)
	ups["is_use_default_time"] = params.IsUseDefaultTime
	ups["key"] = params.Key
	ups["format"] = params.Format
	err = db2.ViewUpdate(tx, id, ups)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}
	var viewInfo db2.BaseView
	viewInfo, err = db2.ViewInfo(tx, id)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}
	tableInfo, err := db2.TableInfo(tx, viewInfo.Tid)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}
	if err = permission.Manager.CheckNormalPermission(view2.ReqPermission{
		UserId:      c.Uid(),
		ObjectType:  pmsplugin.PrefixInstance,
		ObjectIdx:   strconv.Itoa(tableInfo.Database.Iid),
		SubResource: pmsplugin.Log,
		Acts:        []string{pmsplugin.ActEdit},
		DomainType:  pmsplugin.PrefixTable,
		DomainId:    strconv.Itoa(tableInfo.ID),
	}); err != nil {
		c.JSONE(1, "permission verification failed", err)
		return
	}
	var viewList []*db2.BaseView
	conds := egorm.Conds{}
	conds["tid"] = viewInfo.Tid
	viewList, err = db2.ViewList(tx, conds)
	if err != nil {
		tx.Rollback()
		c.JSONE(1, err.Error(), nil)
		return
	}
	databaseInfo, _ := db2.DatabaseInfo(tx, tableInfo.Did)
	op, err := service.InstanceManager.Load(databaseInfo.Iid)
	if err != nil {
		tx.Rollback()
		c.JSONE(core.CodeErr, err.Error(), nil)
		return
	}
	dSQL, cQSL, err := op.SyncView(tableInfo, &viewInfo, viewList, true)
	if err != nil {
		tx.Rollback()
		c.JSONE(core.CodeErr, err.Error(), nil)
		return
	}
	ups1 := make(map[string]interface{}, 0)
	ups1["sql_view"] = cQSL
	ups1["uid"] = c.Uid()
	err = db2.ViewUpdate(tx, viewInfo.ID, ups1)
	if err != nil {
		tx.Rollback()
		c.JSONE(core.CodeErr, err.Error(), nil)
		return
	}
	ups2 := make(map[string]interface{}, 0)
	ups2["sql_view"] = dSQL
	ups2["uid"] = c.Uid()
	err = db2.TableUpdate(tx, tableInfo.ID, ups2)
	if err != nil {
		tx.Rollback()
		c.JSONE(core.CodeErr, err.Error(), nil)
		return
	}
	if err = tx.Commit().Error; err != nil {
		c.JSONE(core.CodeErr, err.Error(), nil)
		return
	}
	event.Event.InquiryCMDB(c.User(), db2.OpnViewsUpdate, map[string]interface{}{"params": params})
	c.JSONOK()
}