-
Notifications
You must be signed in to change notification settings - Fork 0
/
cqrs_uc_internal_generator.go
124 lines (109 loc) · 3.07 KB
/
cqrs_uc_internal_generator.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package modulegenerator
import (
"os"
"github.com/Muruyung/go-utilities/logger"
)
func internalCqrsUcGenerator(dto dtoModule, cqrsType string, isGenerate bool) error {
if !isGenerate {
return nil
}
dto.path += "usecase" + dto.sep
var (
err error
pathQuery = "query" + dto.sep + dto.name
pathCommand = "command" + dto.sep + dto.name
_, okGet = dto.methods["get"]
_, okList = dto.methods["getList"]
_, okCreate = dto.methods["create"]
_, okUpdate = dto.methods["update"]
_, okDelete = dto.methods["delete"]
isQuery = (okGet || okList || cqrsType == "query")
isCommand = (okCreate || okUpdate || okDelete || cqrsType == "command")
)
if isQuery {
if _, err = os.Stat(dto.path + pathQuery); os.IsNotExist(err) {
err = os.MkdirAll(dto.path+pathQuery, 0777)
if err != nil {
return err
} else {
logger.Logger.Info("internal directory usecase query created")
}
}
if _, err = os.Stat(dto.path + pathQuery + "/init.go"); os.IsNotExist(err) {
err = generateInitUc(dto.name, dto.path+pathQuery, dto.services, dto.fields)
if err != nil {
return err
} else {
logger.Logger.Info("internal init usecase query created")
}
}
}
if isCommand {
if _, err = os.Stat(dto.path + pathCommand); os.IsNotExist(err) {
err = os.MkdirAll(dto.path+pathCommand, 0777)
if err != nil {
return err
} else {
logger.Logger.Info("internal directory usecase command created")
}
}
if _, err = os.Stat(dto.path + pathCommand + "/init.go"); os.IsNotExist(err) {
err = generateInitUc(dto.name, dto.path+pathCommand, dto.services, dto.fields)
if err != nil {
return err
} else {
logger.Logger.Info("internal init usecase command created")
}
}
}
if _, ok := dto.methods["get"]; ok {
err = generateGetUc(dto.name, dto.path+pathQuery, dto.services, dto.fields["id"])
if err != nil {
return err
} else {
logger.Logger.Info("internal get usecase created")
}
}
if _, ok := dto.methods["getList"]; ok {
err = generateGetListUc(dto.name, dto.path+pathQuery, dto.services)
if err != nil {
return err
} else {
logger.Logger.Info("internal get list usecase created")
}
}
if _, ok := dto.methods["create"]; ok {
err = generateCreateUc(dto.name, dto.path+pathCommand, dto.services, dto.fields)
if err != nil {
return err
} else {
logger.Logger.Info("internal create usecase created")
}
}
if _, ok := dto.methods["update"]; ok {
err = generateUpdateUc(dto.name, dto.path+pathCommand, dto.services, dto.fields)
if err != nil {
return err
} else {
logger.Logger.Info("internal update usecase created")
}
}
if _, ok := dto.methods["delete"]; ok {
err = generateDeleteUc(dto.name, dto.path+pathCommand, dto.services, dto.fields)
if err != nil {
return err
} else {
logger.Logger.Info("internal update usecase created")
}
}
if _, ok := dto.methods["custom"]; ok {
dto.path += cqrsType + dto.sep + dto.name
err = generateCustomUc(dto)
if err != nil {
return err
} else {
logger.Logger.Info("internal custom usecase created")
}
}
return nil
}