MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / CreateView

Method CreateView

internal/store/views.go:11–44  ·  view source on GitHub ↗

CreateView adds a new saved view.

(workspaceID string, input models.ViewCreate)

Source from the content-addressed store, hash-verified

9
10// CreateView adds a new saved view.
11func (s *Store) CreateView(workspaceID string, input models.ViewCreate) (*models.View, error) {
12 id := newID()
13 ts := now()
14
15 slug := input.Slug
16 if slug == "" {
17 slug = slugify(input.Name)
18 }
19 slug, err := s.uniqueSlug("views", "workspace_id", workspaceID, slug)
20 if err != nil {
21 return nil, fmt.Errorf("generate slug: %w", err)
22 }
23
24 config := input.Config
25 if config == "" {
26 config = "{}"
27 }
28
29 viewType := input.ViewType
30 if viewType == "" {
31 viewType = "list"
32 }
33
34 _, err = s.db.Exec(s.q(`
35 INSERT INTO views (id, workspace_id, collection_id, name, slug, view_type, config, sort_order, is_default, created_at, updated_at)
36 VALUES (?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?)`),
37 id, workspaceID, input.CollectionID, input.Name, slug, viewType, config, s.dialect.BoolToInt(false), ts, ts,
38 )
39 if err != nil {
40 return nil, fmt.Errorf("insert view: %w", err)
41 }
42
43 return s.GetView(id)
44}
45
46// GetView returns a single view by ID.
47func (s *Store) GetView(id string) (*models.View, error) {

Calls 8

uniqueSlugMethod · 0.95
qMethod · 0.95
GetViewMethod · 0.95
newIDFunction · 0.85
nowFunction · 0.85
slugifyFunction · 0.85
ExecMethod · 0.80
BoolToIntMethod · 0.65