-
Notifications
You must be signed in to change notification settings - Fork 3
/
deaprtment.go
102 lines (85 loc) · 1.84 KB
/
deaprtment.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func fetchDepartment(c *gin.Context) {
idStr := c.Query(`ids`)
var us []map[string]interface{}
var err error
if len(idStr) > 0 {
us, err = org.UnitByIDs(strings.Split(idStr, `,`))
} else {
us, err = org.AllUnit()
}
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, map[string]interface{}{
`data`: us,
`total`: len(us),
})
}
func createDepartment(c *gin.Context) {
var body map[string]string
err := c.BindJSON(&body) // 会发送错误信息
if err != nil {
return
}
parentID := body[`parentID`]
info := map[string][]string{
`ou`: []string{body[`ou`]},
`description`: []string{body[`description`]},
`rbacType`: []string{body[`rbacType`]},
`priority`: []string{body[`priority`]},
}
id, err := org.AddUnit(parentID, info)
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, map[string]string{`id`: id})
}
func editDepartment(c *gin.Context) {
var body map[string]string
err := c.BindJSON(&body) // 会发送错误信息
if err != nil {
return
}
info := map[string][]string{
`ou`: []string{body[`ou`]},
`description`: []string{body[`description`]},
`rbacType`: []string{body[`rbacType`]},
`priority`: []string{body[`priority`]},
}
id := c.Param(`id`)
err = org.ModifyUnit(id, info)
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, map[string]string{`id`: id})
}
func departmentByID(c *gin.Context) {
unit, err := org.UnitByID(c.Param(`id`))
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, map[string]interface{}{
`data`: unit,
})
}
func delDepartment(c *gin.Context) {
id := c.Param(`id`)
err := org.DelUnit(id)
if err != nil {
sendError(c, err)
return
}
c.JSON(http.StatusOK, map[string]string{
`id`: id,
})
}