-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworkspacesHandler.go
73 lines (65 loc) · 1.53 KB
/
workspacesHandler.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package handler
import (
"github.com/m-cmp/mc-iam-manager/models"
"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"
"github.com/opentracing/opentracing-go/log"
)
func CreateWorkspace(tx *pop.Connection, s *models.Workspace) (*models.Workspace, error) {
err := tx.Create(s)
if err != nil {
log.Error(err)
return nil, err
}
return s, nil
}
func GetWorkspaceList(tx *pop.Connection) (*models.Workspaces, error) {
var s models.Workspaces
err := tx.All(&s)
if err != nil {
log.Error(err)
return nil, err
}
return &s, nil
}
func GetWorkspaceById(tx *pop.Connection, id uuid.UUID) (*models.Workspace, error) {
var s models.Workspace
err := tx.Find(&s, id)
if err != nil {
log.Error(err)
return nil, err
}
return &s, nil
}
func SearchWorkspacesByName(tx *pop.Connection, name string, option string) (*models.Workspaces, error) {
table := "workspaces"
var query string
if option == "contain" {
query = "SELECT * FROM " + table + " WHERE name ILIKE '%" + name + "%';"
} else {
query = "SELECT * FROM " + table + " WHERE name LIKE '" + name + "';"
}
var s models.Workspaces
err := tx.RawQuery(query).All(&s)
if err != nil {
log.Error(err)
return nil, err
}
return &s, nil
}
func UpdateWorkspace(tx *pop.Connection, s *models.Workspace) (*models.Workspace, error) {
err := tx.Update(s)
if err != nil {
log.Error(err)
return nil, err
}
return s, nil
}
func DeleteWorkspace(tx *pop.Connection, s *models.Workspace) error {
err := tx.Destroy(s)
if err != nil {
log.Error(err)
return err
}
return nil
}