正在显示
23 个修改的文件
包含
994 行增加
和
3 行删除
@@ -226,6 +226,8 @@ github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+ | @@ -226,6 +226,8 @@ github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+ | ||
226 | github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= | 226 | github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= |
227 | github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= | 227 | github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= |
228 | github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= | 228 | github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= |
229 | +github.com/go-pg/pg v8.0.7+incompatible h1:ty/sXL1OZLo+47KK9N8llRcmbA9tZasqbQ/OO4ld53g= | ||
230 | +github.com/go-pg/pg v8.0.7+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA= | ||
229 | github.com/go-pg/pg/v10 v10.0.0-beta.2/go.mod h1:UAuqGPC94ySi4rJ3DC5e4SY1rlwugZbJA/XoJ/kf5Rw= | 231 | github.com/go-pg/pg/v10 v10.0.0-beta.2/go.mod h1:UAuqGPC94ySi4rJ3DC5e4SY1rlwugZbJA/XoJ/kf5Rw= |
230 | github.com/go-pg/pg/v10 v10.7.3 h1:oL/Hz5MJie/9epmwxlZjfReO+2wlLPOK6BeGb9I+XHk= | 232 | github.com/go-pg/pg/v10 v10.7.3 h1:oL/Hz5MJie/9epmwxlZjfReO+2wlLPOK6BeGb9I+XHk= |
231 | github.com/go-pg/pg/v10 v10.7.3/go.mod h1:UsDYtA+ihbBNX1OeIvDejxkL4RXzL3wsZYoEv5NUEqM= | 233 | github.com/go-pg/pg/v10 v10.7.3/go.mod h1:UsDYtA+ihbBNX1OeIvDejxkL4RXzL3wsZYoEv5NUEqM= |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/tiptok/godevp/pkg/domain" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type CreateClientVersionCommand struct { | ||
11 | + // 提交人 | ||
12 | + Commiter string `json:"commiter,omitempty"` | ||
13 | + // 项目名称 | ||
14 | + ProjectName string `json:"projectName,omitempty"` | ||
15 | + // 版本号 | ||
16 | + Version string `json:"version,omitempty"` | ||
17 | + // 标题 | ||
18 | + Title string `json:"title,omitempty"` | ||
19 | + // 其他备注信息 | ||
20 | + Remark string `json:"remark,omitempty"` | ||
21 | + // 客户端安装包信息 | ||
22 | + ClientPackageInfo []*domain.ClientPackageInfo `json:"clientPackageInfo,omitempty"` | ||
23 | +} | ||
24 | + | ||
25 | +func (createClientVersionCommand *CreateClientVersionCommand) Valid(validation *validation.Validation) { | ||
26 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
27 | +} | ||
28 | + | ||
29 | +func (createClientVersionCommand *CreateClientVersionCommand) ValidateCommand() error { | ||
30 | + valid := validation.Validation{} | ||
31 | + b, err := valid.Valid(createClientVersionCommand) | ||
32 | + if err != nil { | ||
33 | + return err | ||
34 | + } | ||
35 | + if !b { | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
38 | + } | ||
39 | + } | ||
40 | + return nil | ||
41 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveClientVersionCommand struct { | ||
10 | + // dcc | ||
11 | + Id int64 `json:"id" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeClientVersionCommand *RemoveClientVersionCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removeClientVersionCommand *RemoveClientVersionCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removeClientVersionCommand) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/tiptok/godevp/pkg/domain" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type UpdateClientVersionCommand struct { | ||
11 | + // dcc | ||
12 | + Id int64 `json:"id" valid:"Required"` | ||
13 | + // 提交人 | ||
14 | + Commiter string `json:"commiter,omitempty"` | ||
15 | + // 项目名称 | ||
16 | + ProjectName string `json:"projectName,omitempty"` | ||
17 | + // 版本号 | ||
18 | + Version string `json:"version,omitempty"` | ||
19 | + // 标题 | ||
20 | + Title string `json:"title,omitempty"` | ||
21 | + // 其他备注信息 | ||
22 | + Remark string `json:"remark,omitempty"` | ||
23 | + // 客户端安装包信息 | ||
24 | + ClientPackageInfo []*domain.ClientPackageInfo `json:"clientPackageInfo,omitempty"` | ||
25 | +} | ||
26 | + | ||
27 | +func (updateClientVersionCommand *UpdateClientVersionCommand) Valid(validation *validation.Validation) { | ||
28 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
29 | +} | ||
30 | + | ||
31 | +func (updateClientVersionCommand *UpdateClientVersionCommand) ValidateCommand() error { | ||
32 | + valid := validation.Validation{} | ||
33 | + b, err := valid.Valid(updateClientVersionCommand) | ||
34 | + if err != nil { | ||
35 | + return err | ||
36 | + } | ||
37 | + if !b { | ||
38 | + for _, validErr := range valid.Errors { | ||
39 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + return nil | ||
43 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetClientVersionQuery struct { | ||
10 | + // dcc | ||
11 | + Id int64 `json:"id" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getClientVersionQuery *GetClientVersionQuery) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getClientVersionQuery *GetClientVersionQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getClientVersionQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListClientVersionQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listClientVersionQuery *ListClientVersionQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listClientVersionQuery *ListClientVersionQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listClientVersionQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "github.com/tiptok/godevp/pkg/application/clientVersion/command" | ||
8 | + "github.com/tiptok/godevp/pkg/application/clientVersion/query" | ||
9 | + "github.com/tiptok/godevp/pkg/application/factory" | ||
10 | + "github.com/tiptok/godevp/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 客户端版本服务 | ||
14 | +type ClientVersionService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 创建 | ||
18 | +func (clientVersionService *ClientVersionService) CreateClientVersion(createClientVersionCommand *command.CreateClientVersionCommand) (interface{}, error) { | ||
19 | + if err := createClientVersionCommand.ValidateCommand(); err != nil { | ||
20 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
21 | + } | ||
22 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
23 | + if err != nil { | ||
24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
25 | + } | ||
26 | + if err := transactionContext.StartTransaction(); err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + defer func() { | ||
30 | + transactionContext.RollbackTransaction() | ||
31 | + }() | ||
32 | + newClientVersion := &domain.ClientVersion{ | ||
33 | + Commiter: createClientVersionCommand.Commiter, | ||
34 | + ProjectName: createClientVersionCommand.ProjectName, | ||
35 | + Version: createClientVersionCommand.Version, | ||
36 | + Title: createClientVersionCommand.Title, | ||
37 | + Remark: createClientVersionCommand.Remark, | ||
38 | + ClientPackageInfo: createClientVersionCommand.ClientPackageInfo, | ||
39 | + } | ||
40 | + var clientVersionRepository domain.ClientVersionRepository | ||
41 | + if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | ||
42 | + "transactionContext": transactionContext, | ||
43 | + }); err != nil { | ||
44 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
45 | + } else { | ||
46 | + clientVersionRepository = value | ||
47 | + } | ||
48 | + if clientVersion, err := clientVersionRepository.Save(newClientVersion); err != nil { | ||
49 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
50 | + } else { | ||
51 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
52 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
53 | + } | ||
54 | + return clientVersion, nil | ||
55 | + } | ||
56 | +} | ||
57 | + | ||
58 | +// 返回 | ||
59 | +func (clientVersionService *ClientVersionService) GetClientVersion(getClientVersionQuery *query.GetClientVersionQuery) (interface{}, error) { | ||
60 | + if err := getClientVersionQuery.ValidateQuery(); err != nil { | ||
61 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
62 | + } | ||
63 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
64 | + if err != nil { | ||
65 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
66 | + } | ||
67 | + if err := transactionContext.StartTransaction(); err != nil { | ||
68 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
69 | + } | ||
70 | + defer func() { | ||
71 | + transactionContext.RollbackTransaction() | ||
72 | + }() | ||
73 | + var clientVersionRepository domain.ClientVersionRepository | ||
74 | + if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | ||
75 | + "transactionContext": transactionContext, | ||
76 | + }); err != nil { | ||
77 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
78 | + } else { | ||
79 | + clientVersionRepository = value | ||
80 | + } | ||
81 | + clientVersion, err := clientVersionRepository.FindOne(map[string]interface{}{"clientVersionId": getClientVersionQuery.Id}) | ||
82 | + if err != nil { | ||
83 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
84 | + } | ||
85 | + if clientVersion == nil { | ||
86 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getClientVersionQuery.Id))) | ||
87 | + } else { | ||
88 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
89 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
90 | + } | ||
91 | + return clientVersion, nil | ||
92 | + } | ||
93 | +} | ||
94 | + | ||
95 | +// 返回列表 | ||
96 | +func (clientVersionService *ClientVersionService) ListClientVersion(listClientVersionQuery *query.ListClientVersionQuery) (interface{}, error) { | ||
97 | + if err := listClientVersionQuery.ValidateQuery(); err != nil { | ||
98 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
99 | + } | ||
100 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
101 | + if err != nil { | ||
102 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
103 | + } | ||
104 | + if err := transactionContext.StartTransaction(); err != nil { | ||
105 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
106 | + } | ||
107 | + defer func() { | ||
108 | + transactionContext.RollbackTransaction() | ||
109 | + }() | ||
110 | + var clientVersionRepository domain.ClientVersionRepository | ||
111 | + if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | ||
112 | + "transactionContext": transactionContext, | ||
113 | + }); err != nil { | ||
114 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
115 | + } else { | ||
116 | + clientVersionRepository = value | ||
117 | + } | ||
118 | + if count, clientVersions, err := clientVersionRepository.Find(tool_funs.SimpleStructToMap(listClientVersionQuery)); err != nil { | ||
119 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
120 | + } else { | ||
121 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
122 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
123 | + } | ||
124 | + return map[string]interface{}{ | ||
125 | + "count": count, | ||
126 | + "clientVersions": clientVersions, | ||
127 | + }, nil | ||
128 | + } | ||
129 | +} | ||
130 | + | ||
131 | +// 移除 | ||
132 | +func (clientVersionService *ClientVersionService) RemoveClientVersion(removeClientVersionCommand *command.RemoveClientVersionCommand) (interface{}, error) { | ||
133 | + if err := removeClientVersionCommand.ValidateCommand(); err != nil { | ||
134 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
135 | + } | ||
136 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
137 | + if err != nil { | ||
138 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
139 | + } | ||
140 | + if err := transactionContext.StartTransaction(); err != nil { | ||
141 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
142 | + } | ||
143 | + defer func() { | ||
144 | + transactionContext.RollbackTransaction() | ||
145 | + }() | ||
146 | + var clientVersionRepository domain.ClientVersionRepository | ||
147 | + if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | ||
148 | + "transactionContext": transactionContext, | ||
149 | + }); err != nil { | ||
150 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
151 | + } else { | ||
152 | + clientVersionRepository = value | ||
153 | + } | ||
154 | + clientVersion, err := clientVersionRepository.FindOne(map[string]interface{}{"clientVersionId": removeClientVersionCommand.Id}) | ||
155 | + if err != nil { | ||
156 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
157 | + } | ||
158 | + if clientVersion == nil { | ||
159 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeClientVersionCommand.Id))) | ||
160 | + } | ||
161 | + if clientVersion, err := clientVersionRepository.Remove(clientVersion); err != nil { | ||
162 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
163 | + } else { | ||
164 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
165 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
166 | + } | ||
167 | + return clientVersion, nil | ||
168 | + } | ||
169 | +} | ||
170 | + | ||
171 | +// 更新 | ||
172 | +func (clientVersionService *ClientVersionService) UpdateClientVersion(updateClientVersionCommand *command.UpdateClientVersionCommand) (interface{}, error) { | ||
173 | + if err := updateClientVersionCommand.ValidateCommand(); err != nil { | ||
174 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
175 | + } | ||
176 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
177 | + if err != nil { | ||
178 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
179 | + } | ||
180 | + if err := transactionContext.StartTransaction(); err != nil { | ||
181 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
182 | + } | ||
183 | + defer func() { | ||
184 | + transactionContext.RollbackTransaction() | ||
185 | + }() | ||
186 | + var clientVersionRepository domain.ClientVersionRepository | ||
187 | + if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | ||
188 | + "transactionContext": transactionContext, | ||
189 | + }); err != nil { | ||
190 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
191 | + } else { | ||
192 | + clientVersionRepository = value | ||
193 | + } | ||
194 | + clientVersion, err := clientVersionRepository.FindOne(map[string]interface{}{"clientVersionId": updateClientVersionCommand.Id}) | ||
195 | + if err != nil { | ||
196 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
197 | + } | ||
198 | + if clientVersion == nil { | ||
199 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateClientVersionCommand.Id))) | ||
200 | + } | ||
201 | + if err := clientVersion.Update(tool_funs.SimpleStructToMap(updateClientVersionCommand)); err != nil { | ||
202 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
203 | + } | ||
204 | + if clientVersion, err := clientVersionRepository.Save(clientVersion); err != nil { | ||
205 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
206 | + } else { | ||
207 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
208 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
209 | + } | ||
210 | + return clientVersion, nil | ||
211 | + } | ||
212 | +} | ||
213 | + | ||
214 | +func NewClientVersionService(options map[string]interface{}) *ClientVersionService { | ||
215 | + newClientVersionService := &ClientVersionService{} | ||
216 | + return newClientVersionService | ||
217 | +} |
@@ -39,3 +39,11 @@ func CreateRoleAccessRepository(options map[string]interface{}) (domain.RoleAcce | @@ -39,3 +39,11 @@ func CreateRoleAccessRepository(options map[string]interface{}) (domain.RoleAcce | ||
39 | } | 39 | } |
40 | return repository.NewRoleAccessRepository(transactionContext) | 40 | return repository.NewRoleAccessRepository(transactionContext) |
41 | } | 41 | } |
42 | + | ||
43 | +func CreateClientVersionRepository(options map[string]interface{}) (domain.ClientVersionRepository, error) { | ||
44 | + var transactionContext *pg.TransactionContext | ||
45 | + if value, ok := options["transactionContext"]; ok { | ||
46 | + transactionContext = value.(*pg.TransactionContext) | ||
47 | + } | ||
48 | + return repository.NewClientVersionRepository(transactionContext) | ||
49 | +} |
pkg/domain/client_package_info.go
0 → 100644
pkg/domain/client_version.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 客户端版本信息 | ||
6 | +type ClientVersion struct { | ||
7 | + // dcc | ||
8 | + Id int64 `json:"id"` | ||
9 | + // 提交人 | ||
10 | + Commiter string `json:"commiter"` | ||
11 | + // 项目名称 | ||
12 | + ProjectName string `json:"projectName"` | ||
13 | + // 版本号 | ||
14 | + Version string `json:"version"` | ||
15 | + // 标题 | ||
16 | + Title string `json:"title"` | ||
17 | + // 其他备注信息 | ||
18 | + Remark string `json:"remark"` | ||
19 | + // 客户端安装包信息 | ||
20 | + ClientPackageInfo []*ClientPackageInfo `json:"clientPackageInfo"` | ||
21 | + // 创建时间 | ||
22 | + CreateTime time.Time `json:"createTime"` | ||
23 | +} | ||
24 | + | ||
25 | +type ClientVersionRepository interface { | ||
26 | + Save(clientVersion *ClientVersion) (*ClientVersion, error) | ||
27 | + Remove(clientVersion *ClientVersion) (*ClientVersion, error) | ||
28 | + FindOne(queryOptions map[string]interface{}) (*ClientVersion, error) | ||
29 | + Find(queryOptions map[string]interface{}) (int64, []*ClientVersion, error) | ||
30 | +} | ||
31 | + | ||
32 | +func (clientVersion *ClientVersion) Identify() interface{} { | ||
33 | + if clientVersion.Id == 0 { | ||
34 | + return nil | ||
35 | + } | ||
36 | + return clientVersion.Id | ||
37 | +} | ||
38 | + | ||
39 | +func (clientVersion *ClientVersion) Update(data map[string]interface{}) error { | ||
40 | + if Id, ok := data["Id"]; ok { | ||
41 | + clientVersion.Id = Id.(int64) | ||
42 | + } | ||
43 | + if commiter, ok := data["commiter"]; ok { | ||
44 | + clientVersion.Commiter = commiter.(string) | ||
45 | + } | ||
46 | + if projectName, ok := data["projectName"]; ok { | ||
47 | + clientVersion.ProjectName = projectName.(string) | ||
48 | + } | ||
49 | + if version, ok := data["version"]; ok { | ||
50 | + clientVersion.Version = version.(string) | ||
51 | + } | ||
52 | + if title, ok := data["title"]; ok { | ||
53 | + clientVersion.Title = title.(string) | ||
54 | + } | ||
55 | + if remark, ok := data["remark"]; ok { | ||
56 | + clientVersion.Remark = remark.(string) | ||
57 | + } | ||
58 | + if clientPackageInfo, ok := data["clientPackageInfo"]; ok { | ||
59 | + clientVersion.ClientPackageInfo = clientPackageInfo.([]*ClientPackageInfo) | ||
60 | + } | ||
61 | + if createTime, ok := data["createTime"]; ok { | ||
62 | + clientVersion.CreateTime = createTime.(time.Time) | ||
63 | + } | ||
64 | + return nil | ||
65 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/tiptok/godevp/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type ClientVersion struct { | ||
9 | + TableName string `pg:"client_versions,alias:client_version"` | ||
10 | + // dcc | ||
11 | + Id int64 | ||
12 | + // 提交人 | ||
13 | + Commiter string | ||
14 | + // 项目名称 | ||
15 | + ProjectName string | ||
16 | + // 版本号 | ||
17 | + Version string | ||
18 | + // 标题 | ||
19 | + Title string | ||
20 | + // 其他备注信息 | ||
21 | + Remark string | ||
22 | + // 客户端安装包信息 | ||
23 | + ClientPackageInfo []*domain.ClientPackageInfo `pg:",array"` | ||
24 | + // 创建时间 | ||
25 | + CreateTime time.Time | ||
26 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/go-pg/pg/v10" | ||
7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
8 | + "github.com/tiptok/godevp/pkg/domain" | ||
9 | + "github.com/tiptok/godevp/pkg/infrastructure/pg/models" | ||
10 | +) | ||
11 | + | ||
12 | +type ClientVersionRepository struct { | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (repository *ClientVersionRepository) nextIdentify() (int64, error) { | ||
17 | + return 0, nil | ||
18 | +} | ||
19 | +func (repository *ClientVersionRepository) Save(clientVersion *domain.ClientVersion) (*domain.ClientVersion, error) { | ||
20 | + tx := repository.transactionContext.PgTx | ||
21 | + if clientVersion.Identify() == nil { | ||
22 | + _, err := repository.nextIdentify() | ||
23 | + if err != nil { | ||
24 | + return clientVersion, err | ||
25 | + } | ||
26 | + if _, err := tx.QueryOne( | ||
27 | + pg.Scan(&clientVersion.Id, &clientVersion.Commiter, &clientVersion.ProjectName, &clientVersion.Version, &clientVersion.Title, &clientVersion.Remark, pg.Array(&clientVersion.ClientPackageInfo), &clientVersion.CreateTime), | ||
28 | + "INSERT INTO client_versions (id, commiter, project_name, version, title, remark, client_package_info, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, commiter, project_name, version, title, remark, client_package_info, create_time", | ||
29 | + clientVersion.Id, clientVersion.Commiter, clientVersion.ProjectName, clientVersion.Version, clientVersion.Title, clientVersion.Remark, pg.Array(clientVersion.ClientPackageInfo), clientVersion.CreateTime); err != nil { | ||
30 | + return clientVersion, err | ||
31 | + } | ||
32 | + } else { | ||
33 | + if _, err := tx.QueryOne( | ||
34 | + pg.Scan(&clientVersion.Id, &clientVersion.Commiter, &clientVersion.ProjectName, &clientVersion.Version, &clientVersion.Title, &clientVersion.Remark, pg.Array(&clientVersion.ClientPackageInfo), &clientVersion.CreateTime), | ||
35 | + "UPDATE client_versions SET id=?, commiter=?, project_name=?, version=?, title=?, remark=?, client_package_info=?, create_time=? WHERE id=? RETURNING id, commiter, project_name, version, title, remark, client_package_info, create_time", | ||
36 | + clientVersion.Id, clientVersion.Commiter, clientVersion.ProjectName, clientVersion.Version, clientVersion.Title, clientVersion.Remark, pg.Array(clientVersion.ClientPackageInfo), clientVersion.CreateTime, clientVersion.Identify()); err != nil { | ||
37 | + return clientVersion, err | ||
38 | + } | ||
39 | + } | ||
40 | + return clientVersion, nil | ||
41 | +} | ||
42 | +func (repository *ClientVersionRepository) Remove(clientVersion *domain.ClientVersion) (*domain.ClientVersion, error) { | ||
43 | + tx := repository.transactionContext.PgTx | ||
44 | + clientVersionModel := new(models.ClientVersion) | ||
45 | + clientVersionModel.Id = clientVersion.Identify().(int64) | ||
46 | + if _, err := tx.Model(clientVersionModel).WherePK().Delete(); err != nil { | ||
47 | + return clientVersion, err | ||
48 | + } | ||
49 | + return clientVersion, nil | ||
50 | +} | ||
51 | +func (repository *ClientVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ClientVersion, error) { | ||
52 | + tx := repository.transactionContext.PgTx | ||
53 | + clientVersionModel := new(models.ClientVersion) | ||
54 | + query := tx.Model(clientVersionModel) | ||
55 | + if clientVersionId, ok := queryOptions["clientVersionId"]; ok { | ||
56 | + query = query.Where("client_version.id = ?", clientVersionId) | ||
57 | + } | ||
58 | + if err := query.First(); err != nil { | ||
59 | + if err.Error() == "pg: no rows in result set" { | ||
60 | + return nil, fmt.Errorf("没有此资源") | ||
61 | + } else { | ||
62 | + return nil, err | ||
63 | + } | ||
64 | + } | ||
65 | + if clientVersionModel.Id == 0 { | ||
66 | + return nil, nil | ||
67 | + } else { | ||
68 | + return repository.transformPgModelToDomainModel(clientVersionModel) | ||
69 | + } | ||
70 | +} | ||
71 | +func (repository *ClientVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ClientVersion, error) { | ||
72 | + tx := repository.transactionContext.PgTx | ||
73 | + var clientVersionModels []*models.ClientVersion | ||
74 | + clientVersions := make([]*domain.ClientVersion, 0) | ||
75 | + query := tx.Model(&clientVersionModels) | ||
76 | + if offset, ok := queryOptions["offset"]; ok { | ||
77 | + offset := offset.(int) | ||
78 | + if offset > -1 { | ||
79 | + query = query.Offset(offset) | ||
80 | + } | ||
81 | + } else { | ||
82 | + query = query.Offset(0) | ||
83 | + } | ||
84 | + if limit, ok := queryOptions["limit"]; ok { | ||
85 | + limit := limit.(int) | ||
86 | + if limit > -1 { | ||
87 | + query = query.Limit(limit) | ||
88 | + } | ||
89 | + } else { | ||
90 | + query = query.Limit(20) | ||
91 | + } | ||
92 | + if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | ||
93 | + return 0, clientVersions, err | ||
94 | + } else { | ||
95 | + for _, clientVersionModel := range clientVersionModels { | ||
96 | + if clientVersion, err := repository.transformPgModelToDomainModel(clientVersionModel); err != nil { | ||
97 | + return 0, clientVersions, err | ||
98 | + } else { | ||
99 | + clientVersions = append(clientVersions, clientVersion) | ||
100 | + } | ||
101 | + } | ||
102 | + return int64(count), clientVersions, nil | ||
103 | + } | ||
104 | +} | ||
105 | +func (repository *ClientVersionRepository) transformPgModelToDomainModel(clientVersionModel *models.ClientVersion) (*domain.ClientVersion, error) { | ||
106 | + return &domain.ClientVersion{ | ||
107 | + Id: clientVersionModel.Id, | ||
108 | + Commiter: clientVersionModel.Commiter, | ||
109 | + ProjectName: clientVersionModel.ProjectName, | ||
110 | + Version: clientVersionModel.Version, | ||
111 | + Title: clientVersionModel.Title, | ||
112 | + Remark: clientVersionModel.Remark, | ||
113 | + ClientPackageInfo: clientVersionModel.ClientPackageInfo, | ||
114 | + CreateTime: clientVersionModel.CreateTime, | ||
115 | + }, nil | ||
116 | +} | ||
117 | +func NewClientVersionRepository(transactionContext *pgTransaction.TransactionContext) (*ClientVersionRepository, error) { | ||
118 | + if transactionContext == nil { | ||
119 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
120 | + } else { | ||
121 | + return &ClientVersionRepository{ | ||
122 | + transactionContext: transactionContext, | ||
123 | + }, nil | ||
124 | + } | ||
125 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + | ||
6 | + "github.com/astaxie/beego" | ||
7 | + "github.com/linmadan/egglib-go/web/beego/utils" | ||
8 | + "github.com/tiptok/godevp/pkg/application/clientVersion/command" | ||
9 | + "github.com/tiptok/godevp/pkg/application/clientVersion/query" | ||
10 | + "github.com/tiptok/godevp/pkg/application/clientVersion/service" | ||
11 | +) | ||
12 | + | ||
13 | +type ClientVersionController struct { | ||
14 | + beego.Controller | ||
15 | +} | ||
16 | + | ||
17 | +func (controller *ClientVersionController) CreateClientVersion() { | ||
18 | + clientVersionService := service.NewClientVersionService(nil) | ||
19 | + createClientVersionCommand := &command.CreateClientVersionCommand{} | ||
20 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createClientVersionCommand) | ||
21 | + data, err := clientVersionService.CreateClientVersion(createClientVersionCommand) | ||
22 | + var response utils.JsonResponse | ||
23 | + if err != nil { | ||
24 | + response = utils.ResponseError(controller.Ctx, err) | ||
25 | + } else { | ||
26 | + response = utils.ResponseData(controller.Ctx, data) | ||
27 | + } | ||
28 | + controller.Data["json"] = response | ||
29 | + controller.ServeJSON() | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *ClientVersionController) UpdateClientVersion() { | ||
33 | + clientVersionService := service.NewClientVersionService(nil) | ||
34 | + updateClientVersionCommand := &command.UpdateClientVersionCommand{} | ||
35 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateClientVersionCommand) | ||
36 | + id, _ := controller.GetInt64(":id") | ||
37 | + updateClientVersionCommand.Id = id | ||
38 | + data, err := clientVersionService.UpdateClientVersion(updateClientVersionCommand) | ||
39 | + var response utils.JsonResponse | ||
40 | + if err != nil { | ||
41 | + response = utils.ResponseError(controller.Ctx, err) | ||
42 | + } else { | ||
43 | + response = utils.ResponseData(controller.Ctx, data) | ||
44 | + } | ||
45 | + controller.Data["json"] = response | ||
46 | + controller.ServeJSON() | ||
47 | +} | ||
48 | + | ||
49 | +func (controller *ClientVersionController) GetClientVersion() { | ||
50 | + clientVersionService := service.NewClientVersionService(nil) | ||
51 | + getClientVersionQuery := &query.GetClientVersionQuery{} | ||
52 | + id, _ := controller.GetInt64(":id") | ||
53 | + getClientVersionQuery.Id = id | ||
54 | + data, err := clientVersionService.GetClientVersion(getClientVersionQuery) | ||
55 | + var response utils.JsonResponse | ||
56 | + if err != nil { | ||
57 | + response = utils.ResponseError(controller.Ctx, err) | ||
58 | + } else { | ||
59 | + response = utils.ResponseData(controller.Ctx, data) | ||
60 | + } | ||
61 | + controller.Data["json"] = response | ||
62 | + controller.ServeJSON() | ||
63 | +} | ||
64 | + | ||
65 | +func (controller *ClientVersionController) RemoveClientVersion() { | ||
66 | + clientVersionService := service.NewClientVersionService(nil) | ||
67 | + removeClientVersionCommand := &command.RemoveClientVersionCommand{} | ||
68 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeClientVersionCommand) | ||
69 | + id, _ := controller.GetInt64(":id") | ||
70 | + removeClientVersionCommand.Id = id | ||
71 | + data, err := clientVersionService.RemoveClientVersion(removeClientVersionCommand) | ||
72 | + var response utils.JsonResponse | ||
73 | + if err != nil { | ||
74 | + response = utils.ResponseError(controller.Ctx, err) | ||
75 | + } else { | ||
76 | + response = utils.ResponseData(controller.Ctx, data) | ||
77 | + } | ||
78 | + controller.Data["json"] = response | ||
79 | + controller.ServeJSON() | ||
80 | +} | ||
81 | + | ||
82 | +func (controller *ClientVersionController) ListClientVersion() { | ||
83 | + clientVersionService := service.NewClientVersionService(nil) | ||
84 | + listClientVersionQuery := &query.ListClientVersionQuery{} | ||
85 | + offset, _ := controller.GetInt("offset") | ||
86 | + listClientVersionQuery.Offset = offset | ||
87 | + limit, _ := controller.GetInt("limit") | ||
88 | + listClientVersionQuery.Limit = limit | ||
89 | + data, err := clientVersionService.ListClientVersion(listClientVersionQuery) | ||
90 | + var response utils.JsonResponse | ||
91 | + if err != nil { | ||
92 | + response = utils.ResponseError(controller.Ctx, err) | ||
93 | + } else { | ||
94 | + response = utils.ResponseData(controller.Ctx, data) | ||
95 | + } | ||
96 | + controller.Data["json"] = response | ||
97 | + controller.ServeJSON() | ||
98 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego" | ||
5 | + "github.com/tiptok/godevp/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + beego.Router("/client-versions/", &controllers.ClientVersionController{}, "Post:CreateClientVersion") | ||
10 | + beego.Router("/client-versions/:id", &controllers.ClientVersionController{}, "Put:UpdateClientVersion") | ||
11 | + beego.Router("/client-versions/:id", &controllers.ClientVersionController{}, "Get:GetClientVersion") | ||
12 | + beego.Router("/client-versions/:id", &controllers.ClientVersionController{}, "Delete:RemoveClientVersion") | ||
13 | + beego.Router("/client-versions/", &controllers.ClientVersionController{}, "Get:ListClientVersion") | ||
14 | +} |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/astaxie/beego" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
12 | + _ "github.com/tiptok/godevp/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestClientVersion(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port ClientVersion Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = beego.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建", func() { | ||
13 | + Describe("提交数据创建", func() { | ||
14 | + Context("提交正确的新客户端版本信息数据", func() { | ||
15 | + It("返回客户端版本信息数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "commiter": "string", | ||
19 | + "projectName": "string", | ||
20 | + "version": "string", | ||
21 | + "title": "string", | ||
22 | + "remark": "string", | ||
23 | + "clientPackageInfo": "array", | ||
24 | + } | ||
25 | + httpExpect.POST("/client-versions/"). | ||
26 | + WithJSON(body). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object(). | ||
34 | + ContainsKey("id").ValueNotEqual("id", BeZero()) | ||
35 | + }) | ||
36 | + }) | ||
37 | + }) | ||
38 | + AfterEach(func() { | ||
39 | + _, err := pG.DB.Exec("DELETE FROM client_versions WHERE true") | ||
40 | + Expect(err).NotTo(HaveOccurred()) | ||
41 | + }) | ||
42 | +}) |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg/v10" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回", func() { | ||
14 | + var clientVersionId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&clientVersionId), | ||
18 | + "INSERT INTO client_versions (id, commiter, project_name, version, title, remark, client_package_info, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testId", "testCommiter", "testProjectName", "testVersion", "testTitle", "testRemark", "testClientPackageInfo", "testCreateTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据clientVersionId参数返回客户端版本信息", func() { | ||
23 | + Context("传入有效的clientVersionId", func() { | ||
24 | + It("返回客户端版本信息数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/client-versions/{id}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM client_versions WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg/v10" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回列表", func() { | ||
14 | + var clientVersionId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&clientVersionId), | ||
18 | + "INSERT INTO client_versions (id, commiter, project_name, version, title, remark, client_package_info, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testId", "testCommiter", "testProjectName", "testVersion", "testTitle", "testRemark", "testClientPackageInfo", "testCreateTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回客户端版本信息列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回客户端版本信息数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/client-versions/"). | ||
27 | + WithQuery("offset", "int"). | ||
28 | + WithQuery("limit", "int"). | ||
29 | + Expect(). | ||
30 | + Status(http.StatusOK). | ||
31 | + JSON(). | ||
32 | + Object(). | ||
33 | + ContainsKey("code").ValueEqual("code", 0). | ||
34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
35 | + ContainsKey("data").Value("data").Object(). | ||
36 | + ContainsKey("count").ValueEqual("count", 1). | ||
37 | + ContainsKey("clientVersions").Value("clientVersions").Array() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM client_versions WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg/v10" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除", func() { | ||
14 | + var clientVersionId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&clientVersionId), | ||
18 | + "INSERT INTO client_versions (id, commiter, project_name, version, title, remark, client_package_info, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testId", "testCommiter", "testProjectName", "testVersion", "testTitle", "testRemark", "testClientPackageInfo", "testCreateTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除", func() { | ||
23 | + Context("传入有效的clientVersionId", func() { | ||
24 | + It("返回被移除客户端版本信息的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/client-versions/{id}"). | ||
27 | + Expect(). | ||
28 | + Status(http.StatusOK). | ||
29 | + JSON(). | ||
30 | + Object(). | ||
31 | + ContainsKey("code").ValueEqual("code", 0). | ||
32 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | + ContainsKey("data").Value("data").Object() | ||
34 | + }) | ||
35 | + }) | ||
36 | + }) | ||
37 | + AfterEach(func() { | ||
38 | + _, err := pG.DB.Exec("DELETE FROM client_versions WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package client_version | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg/v10" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新", func() { | ||
14 | + var clientVersionId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&clientVersionId), | ||
18 | + "INSERT INTO client_versions (id, commiter, project_name, version, title, remark, client_package_info, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testId", "testCommiter", "testProjectName", "testVersion", "testTitle", "testRemark", "testClientPackageInfo", "testCreateTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新", func() { | ||
23 | + Context("提交正确的客户端版本信息数据", func() { | ||
24 | + It("返回更新后的客户端版本信息数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "Id": "int64", | ||
28 | + "commiter": "string", | ||
29 | + "projectName": "string", | ||
30 | + "version": "string", | ||
31 | + "title": "string", | ||
32 | + "remark": "string", | ||
33 | + "clientPackageInfo": "array", | ||
34 | + } | ||
35 | + httpExpect.PUT("/client-versions/{id}"). | ||
36 | + WithJSON(body). | ||
37 | + Expect(). | ||
38 | + Status(http.StatusOK). | ||
39 | + JSON(). | ||
40 | + Object(). | ||
41 | + ContainsKey("code").ValueEqual("code", 0). | ||
42 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
43 | + ContainsKey("data").Value("data").Object(). | ||
44 | + ContainsKey("id").ValueEqual("id", clientVersionId) | ||
45 | + }) | ||
46 | + }) | ||
47 | + }) | ||
48 | + AfterEach(func() { | ||
49 | + _, err := pG.DB.Exec("DELETE FROM client_versions WHERE true") | ||
50 | + Expect(err).NotTo(HaveOccurred()) | ||
51 | + }) | ||
52 | +}) |
@@ -4,7 +4,7 @@ import ( | @@ -4,7 +4,7 @@ import ( | ||
4 | "net/http" | 4 | "net/http" |
5 | 5 | ||
6 | "github.com/gavv/httpexpect" | 6 | "github.com/gavv/httpexpect" |
7 | - "github.com/go-pg/pg" | 7 | + "github.com/go-pg/pg/v10" |
8 | . "github.com/onsi/ginkgo" | 8 | . "github.com/onsi/ginkgo" |
9 | . "github.com/onsi/gomega" | 9 | . "github.com/onsi/gomega" |
10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | 10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" |
@@ -4,7 +4,7 @@ import ( | @@ -4,7 +4,7 @@ import ( | ||
4 | "net/http" | 4 | "net/http" |
5 | 5 | ||
6 | "github.com/gavv/httpexpect" | 6 | "github.com/gavv/httpexpect" |
7 | - "github.com/go-pg/pg" | 7 | + "github.com/go-pg/pg/v10" |
8 | . "github.com/onsi/ginkgo" | 8 | . "github.com/onsi/ginkgo" |
9 | . "github.com/onsi/gomega" | 9 | . "github.com/onsi/gomega" |
10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | 10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" |
@@ -4,7 +4,7 @@ import ( | @@ -4,7 +4,7 @@ import ( | ||
4 | "net/http" | 4 | "net/http" |
5 | 5 | ||
6 | "github.com/gavv/httpexpect" | 6 | "github.com/gavv/httpexpect" |
7 | - "github.com/go-pg/pg" | 7 | + "github.com/go-pg/pg/v10" |
8 | . "github.com/onsi/ginkgo" | 8 | . "github.com/onsi/ginkgo" |
9 | . "github.com/onsi/gomega" | 9 | . "github.com/onsi/gomega" |
10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" | 10 | pG "github.com/tiptok/godevp/pkg/infrastructure/pg" |
-
请 注册 或 登录 后发表评论