@nakedev/go-scaffold 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates/rbac-manifest.js +1 -0
- package/package.json +1 -1
- package/templates/add/rbac/internal/app/role/adapters/inbound/http/dto.go.hbs +52 -0
- package/templates/add/rbac/internal/app/role/adapters/inbound/http/handler.go.hbs +12 -11
- package/templates/add/rbac/internal/app/role/application/dto.go.hbs +10 -10
|
@@ -14,6 +14,7 @@ exports.RBAC_FILES = [
|
|
|
14
14
|
{ template: "add/rbac/internal/app/role/application/errors.go.hbs", output: "internal/app/role/application/errors.go" },
|
|
15
15
|
{ template: "add/rbac/internal/app/role/application/service.go.hbs", output: "internal/app/role/application/service.go" },
|
|
16
16
|
{ template: "add/rbac/internal/app/role/application/service_test.go.hbs", output: "internal/app/role/application/service_test.go" },
|
|
17
|
+
{ template: "add/rbac/internal/app/role/adapters/inbound/http/dto.go.hbs", output: "internal/app/role/adapters/inbound/http/dto.go" },
|
|
17
18
|
{ template: "add/rbac/internal/app/role/adapters/inbound/http/handler.go.hbs", output: "internal/app/role/adapters/inbound/http/handler.go" },
|
|
18
19
|
{ template: "add/rbac/internal/app/role/adapters/inbound/http/handler_test.go.hbs", output: "internal/app/role/adapters/inbound/http/handler_test.go" },
|
|
19
20
|
{ template: "add/rbac/internal/app/role/adapters/outbound/postgres/model.go.hbs", output: "internal/app/role/adapters/outbound/postgres/model.go" },
|
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package httpadapter
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"time"
|
|
5
|
+
|
|
6
|
+
"{{goModule}}/internal/app/role/application"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// Request DTOs belong to the inbound adapter. Keep JSON names and binding
|
|
10
|
+
// tags out of application inputs so role use cases remain transport-neutral.
|
|
11
|
+
type createInput struct {
|
|
12
|
+
Code string `json:"code"`
|
|
13
|
+
Name string `json:"name"`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func toCreateInput(in createInput) application.CreateInput {
|
|
17
|
+
return application.CreateInput{Code: in.Code, Name: in.Name}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type setPermissionsInput struct {
|
|
21
|
+
PermissionCodes *[]string `json:"permission_codes"`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func toSetPermissionsInput(in setPermissionsInput) application.SetPermissionsInput {
|
|
25
|
+
return application.SetPermissionsInput{PermissionCodes: in.PermissionCodes}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Response DTOs belong to the inbound adapter too. Application responses are
|
|
29
|
+
// deliberately free of JSON tags and are mapped explicitly before encoding.
|
|
30
|
+
type roleResponse struct {
|
|
31
|
+
Code string `json:"code"`
|
|
32
|
+
Name string `json:"name"`
|
|
33
|
+
IsSystem bool `json:"is_system"`
|
|
34
|
+
Permissions []string `json:"permissions"`
|
|
35
|
+
CreatedAt time.Time `json:"created_at"`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func toRoleResponse(out application.RoleResponse) roleResponse {
|
|
39
|
+
return roleResponse{
|
|
40
|
+
Code: out.Code, Name: out.Name, IsSystem: out.IsSystem,
|
|
41
|
+
Permissions: out.Permissions, CreatedAt: out.CreatedAt,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type permissionResponse struct {
|
|
46
|
+
Code string `json:"code"`
|
|
47
|
+
Description string `json:"description"`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func toPermissionResponse(out application.PermissionResponse) permissionResponse {
|
|
51
|
+
return permissionResponse{Code: out.Code, Description: out.Description}
|
|
52
|
+
}
|
|
@@ -45,44 +45,45 @@ func (h *Handler) list(c *gin.Context) {
|
|
|
45
45
|
c.Error(toHTTPError(err))
|
|
46
46
|
return
|
|
47
47
|
}
|
|
48
|
-
out := make([]
|
|
48
|
+
out := make([]roleResponse, len(items))
|
|
49
49
|
for i := range items {
|
|
50
|
-
out[i] = application.ToRoleResponse(items[i])
|
|
50
|
+
out[i] = toRoleResponse(application.ToRoleResponse(items[i]))
|
|
51
51
|
}
|
|
52
52
|
c.JSON(http.StatusOK, p.Response(out))
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
func (h *Handler) create(c *gin.Context) {
|
|
56
|
-
var in
|
|
56
|
+
var in createInput
|
|
57
57
|
if err := c.ShouldBindJSON(&in); err != nil {
|
|
58
58
|
c.Error(httpx.BindErr(err))
|
|
59
59
|
return
|
|
60
60
|
}
|
|
61
|
-
item, err := h.svc.Create(c.Request.Context(), in)
|
|
61
|
+
item, err := h.svc.Create(c.Request.Context(), toCreateInput(in))
|
|
62
62
|
if err != nil {
|
|
63
63
|
c.Error(toHTTPError(err))
|
|
64
64
|
return
|
|
65
65
|
}
|
|
66
|
-
c.JSON(http.StatusCreated, application.ToRoleResponse(*item))
|
|
66
|
+
c.JSON(http.StatusCreated, toRoleResponse(application.ToRoleResponse(*item)))
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
func (h *Handler) setPermissions(c *gin.Context) {
|
|
70
|
-
var in
|
|
70
|
+
var in setPermissionsInput
|
|
71
71
|
if err := c.ShouldBindJSON(&in); err != nil {
|
|
72
72
|
c.Error(httpx.BindErr(err))
|
|
73
73
|
return
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
appInput := toSetPermissionsInput(in)
|
|
76
|
+
if appInput.PermissionCodes == nil {
|
|
76
77
|
c.Error(apperror.NewValidation("invalid role input", map[string]string{"permission_codes": "is required"}))
|
|
77
78
|
return
|
|
78
79
|
}
|
|
79
|
-
item, err := h.svc.SetPermissions(c.Request.Context(), c.Param("code"), *
|
|
80
|
+
item, err := h.svc.SetPermissions(c.Request.Context(), c.Param("code"), *appInput.PermissionCodes)
|
|
80
81
|
if err != nil {
|
|
81
82
|
c.Error(toHTTPError(err))
|
|
82
83
|
return
|
|
83
84
|
}
|
|
84
85
|
h.authz.Invalidate(item.Role.Code)
|
|
85
|
-
c.JSON(http.StatusOK, application.ToRoleResponse(*item))
|
|
86
|
+
c.JSON(http.StatusOK, toRoleResponse(application.ToRoleResponse(*item)))
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
func (h *Handler) delete(c *gin.Context) {
|
|
@@ -101,9 +102,9 @@ func (h *Handler) listPermissions(c *gin.Context) {
|
|
|
101
102
|
c.Error(toHTTPError(err))
|
|
102
103
|
return
|
|
103
104
|
}
|
|
104
|
-
out := make([]
|
|
105
|
+
out := make([]permissionResponse, len(items))
|
|
105
106
|
for i := range items {
|
|
106
|
-
out[i] = application.ToPermissionResponse(items[i])
|
|
107
|
+
out[i] = toPermissionResponse(application.ToPermissionResponse(items[i]))
|
|
107
108
|
}
|
|
108
109
|
c.JSON(http.StatusOK, p.Response(out))
|
|
109
110
|
}
|
|
@@ -9,12 +9,12 @@ import (
|
|
|
9
9
|
const PermRoleManage = "role:manage"
|
|
10
10
|
|
|
11
11
|
type CreateInput struct {
|
|
12
|
-
Code string
|
|
13
|
-
Name string
|
|
12
|
+
Code string
|
|
13
|
+
Name string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
type SetPermissionsInput struct {
|
|
17
|
-
PermissionCodes *[]string
|
|
17
|
+
PermissionCodes *[]string
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
type RoleListItem struct {
|
|
@@ -23,16 +23,16 @@ type RoleListItem struct {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
type RoleResponse struct {
|
|
26
|
-
Code string
|
|
27
|
-
Name string
|
|
28
|
-
IsSystem bool
|
|
29
|
-
Permissions []string
|
|
30
|
-
CreatedAt time.Time
|
|
26
|
+
Code string
|
|
27
|
+
Name string
|
|
28
|
+
IsSystem bool
|
|
29
|
+
Permissions []string
|
|
30
|
+
CreatedAt time.Time
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
type PermissionResponse struct {
|
|
34
|
-
Code string
|
|
35
|
-
Description string
|
|
34
|
+
Code string
|
|
35
|
+
Description string
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
func ToRoleResponse(item RoleListItem) RoleResponse {
|