正在显示
18 个修改的文件
包含
987 行增加
和
0 行删除
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/beego/beego/v2/core/validation" | ||
10 | +) | ||
11 | + | ||
12 | +type CreateCompanyCommand struct { | ||
13 | + // 企业名称 | ||
14 | + CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"` | ||
15 | + // 规模 | ||
16 | + Scale string `cname:"规模" json:"scale" valid:"Required"` | ||
17 | + // 公司Logo地址 | ||
18 | + Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"` | ||
19 | + // 公司地址 | ||
20 | + Address string `cname:"公司地址" json:"address" valid:"Required"` | ||
21 | + // 所属行业 | ||
22 | + IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"` | ||
23 | + // 联系人 | ||
24 | + Contacts string `cname:"联系人" json:"contacts" valid:"Required"` | ||
25 | + // 注册时间 | ||
26 | + RegisteredTime time.Time `cname:"注册时间" json:"registeredTime,omitempty"` | ||
27 | + // 注册状态 1:已注册 2:待认证 3:已认证 | ||
28 | + Status int `cname:"注册状态 1:已注册 2:待认证 3:已认证" json:"status,omitempty"` | ||
29 | +} | ||
30 | + | ||
31 | +func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) { | ||
32 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
33 | +} | ||
34 | + | ||
35 | +func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error { | ||
36 | + valid := validation.Validation{} | ||
37 | + b, err := valid.Valid(createCompanyCommand) | ||
38 | + if err != nil { | ||
39 | + return err | ||
40 | + } | ||
41 | + if !b { | ||
42 | + elem := reflect.TypeOf(createCompanyCommand).Elem() | ||
43 | + for _, validErr := range valid.Errors { | ||
44 | + field, isExist := elem.FieldByName(validErr.Field) | ||
45 | + if isExist { | ||
46 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
47 | + } else { | ||
48 | + return fmt.Errorf(validErr.Message) | ||
49 | + } | ||
50 | + } | ||
51 | + } | ||
52 | + return nil | ||
53 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type ListCompanyCustomizeMenusCommand struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listCompanyCustomizeMenusCommand *ListCompanyCustomizeMenusCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listCompanyCustomizeMenusCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(listCompanyCustomizeMenusCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type RemoveCompanyCommand struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(removeCompanyCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(removeCompanyCommand).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateCompanyCommand struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
14 | + // 企业名称 | ||
15 | + CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"` | ||
16 | + // 公司地址 | ||
17 | + Address string `cname:"公司地址" json:"address" valid:"Required"` | ||
18 | + // 系统名称 | ||
19 | + SystemName string `cname:"系统名称" json:"systemName" valid:"Required"` | ||
20 | + // 公司Logo地址 | ||
21 | + Logo string `cname:"公司Logo地址" json:"logo" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) { | ||
25 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(updateCompanyCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(updateCompanyCommand).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateCompanyCustomizeMenusCommand struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
14 | + // 菜单编号 | ||
15 | + MenuId int64 `cname:"菜单编号" json:"menuId,string" valid:"Required"` | ||
16 | + // 菜单名称 | ||
17 | + MenuName string `cname:"菜单名称" json:"menuName" valid:"Required"` | ||
18 | + // 菜单别名 | ||
19 | + MenuAlias string `cname:"菜单别名" json:"menuAlias" valid:"Required"` | ||
20 | + // 排序 | ||
21 | + Sort int `cname:"排序" json:"sort" valid:"Required"` | ||
22 | +} | ||
23 | + | ||
24 | +func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) Valid(validation *validation.Validation) { | ||
25 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
26 | +} | ||
27 | + | ||
28 | +func (updateCompanyCustomizeMenusCommand *UpdateCompanyCustomizeMenusCommand) ValidateCommand() error { | ||
29 | + valid := validation.Validation{} | ||
30 | + b, err := valid.Valid(updateCompanyCustomizeMenusCommand) | ||
31 | + if err != nil { | ||
32 | + return err | ||
33 | + } | ||
34 | + if !b { | ||
35 | + elem := reflect.TypeOf(updateCompanyCustomizeMenusCommand).Elem() | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
38 | + if isExist { | ||
39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
40 | + } else { | ||
41 | + return fmt.Errorf(validErr.Message) | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
pkg/application/company/query/get_company.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type GetCompanyQuery struct { | ||
12 | + // 企业id | ||
13 | + CompanyId int64 `cname:"企业id" json:"companyId,string" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(getCompanyQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + elem := reflect.TypeOf(getCompanyQuery).Elem() | ||
28 | + for _, validErr := range valid.Errors { | ||
29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
30 | + if isExist { | ||
31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
32 | + } else { | ||
33 | + return fmt.Errorf(validErr.Message) | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + return nil | ||
38 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "reflect" | ||
6 | + "strings" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/core/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type ListCompanyQuery struct { | ||
12 | + // 查询偏离量 | ||
13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
14 | + // 查询限制 | ||
15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) { | ||
19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(listCompanyQuery) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + elem := reflect.TypeOf(listCompanyQuery).Elem() | ||
30 | + for _, validErr := range valid.Errors { | ||
31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
32 | + if isExist { | ||
33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
34 | + } else { | ||
35 | + return fmt.Errorf(validErr.Message) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + return nil | ||
40 | +} |
pkg/application/company/service/company.go
0 → 100644
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 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/company/command" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/company/query" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 企业 | ||
14 | +type CompanyService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 创建企业 | ||
18 | +func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) { | ||
19 | + if err := createCompanyCommand.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 | + newCompany := &domain.Company{ | ||
33 | + //CompanyInfo: createCompanyCommand.CompanyInfo, | ||
34 | + } | ||
35 | + var companyRepository domain.CompanyRepository | ||
36 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
37 | + "transactionContext": transactionContext, | ||
38 | + }); err != nil { | ||
39 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
40 | + } else { | ||
41 | + companyRepository = value | ||
42 | + } | ||
43 | + if company, err := companyRepository.Save(newCompany); err != nil { | ||
44 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
45 | + } else { | ||
46 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
47 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
48 | + } | ||
49 | + return company, nil | ||
50 | + } | ||
51 | +} | ||
52 | + | ||
53 | +// 返回企业 | ||
54 | +func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) { | ||
55 | + if err := getCompanyQuery.ValidateQuery(); err != nil { | ||
56 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
57 | + } | ||
58 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
59 | + if err != nil { | ||
60 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
61 | + } | ||
62 | + if err := transactionContext.StartTransaction(); err != nil { | ||
63 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
64 | + } | ||
65 | + defer func() { | ||
66 | + transactionContext.RollbackTransaction() | ||
67 | + }() | ||
68 | + var companyRepository domain.CompanyRepository | ||
69 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
70 | + "transactionContext": transactionContext, | ||
71 | + }); err != nil { | ||
72 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
73 | + } else { | ||
74 | + companyRepository = value | ||
75 | + } | ||
76 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": getCompanyQuery.CompanyId}) | ||
77 | + if err != nil { | ||
78 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
79 | + } | ||
80 | + if company == nil { | ||
81 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCompanyQuery.CompanyId))) | ||
82 | + } else { | ||
83 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
84 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
85 | + } | ||
86 | + return company, nil | ||
87 | + } | ||
88 | +} | ||
89 | + | ||
90 | +// 返回企业列表 | ||
91 | +func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) { | ||
92 | + if err := listCompanyQuery.ValidateQuery(); err != nil { | ||
93 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
94 | + } | ||
95 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
96 | + if err != nil { | ||
97 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
98 | + } | ||
99 | + if err := transactionContext.StartTransaction(); err != nil { | ||
100 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
101 | + } | ||
102 | + defer func() { | ||
103 | + transactionContext.RollbackTransaction() | ||
104 | + }() | ||
105 | + var companyRepository domain.CompanyRepository | ||
106 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
107 | + "transactionContext": transactionContext, | ||
108 | + }); err != nil { | ||
109 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
110 | + } else { | ||
111 | + companyRepository = value | ||
112 | + } | ||
113 | + if count, companys, err := companyRepository.Find(tool_funs.SimpleStructToMap(listCompanyQuery)); err != nil { | ||
114 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
115 | + } else { | ||
116 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
117 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
118 | + } | ||
119 | + return map[string]interface{}{ | ||
120 | + "count": count, | ||
121 | + "companys": companys, | ||
122 | + }, nil | ||
123 | + } | ||
124 | +} | ||
125 | + | ||
126 | +// 返回自定义菜单列表 | ||
127 | +func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) { | ||
128 | + if err := listCompanyCustomizeMenusCommand.ValidateCommand(); err != nil { | ||
129 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
130 | + } | ||
131 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
132 | + if err != nil { | ||
133 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
134 | + } | ||
135 | + if err := transactionContext.StartTransaction(); err != nil { | ||
136 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
137 | + } | ||
138 | + defer func() { | ||
139 | + transactionContext.RollbackTransaction() | ||
140 | + }() | ||
141 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
142 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
143 | + } | ||
144 | + return nil, nil | ||
145 | +} | ||
146 | + | ||
147 | +// 移除企业 | ||
148 | +func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) { | ||
149 | + if err := removeCompanyCommand.ValidateCommand(); err != nil { | ||
150 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
151 | + } | ||
152 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
153 | + if err != nil { | ||
154 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
155 | + } | ||
156 | + if err := transactionContext.StartTransaction(); err != nil { | ||
157 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
158 | + } | ||
159 | + defer func() { | ||
160 | + transactionContext.RollbackTransaction() | ||
161 | + }() | ||
162 | + var companyRepository domain.CompanyRepository | ||
163 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
164 | + "transactionContext": transactionContext, | ||
165 | + }); err != nil { | ||
166 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
167 | + } else { | ||
168 | + companyRepository = value | ||
169 | + } | ||
170 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": removeCompanyCommand.CompanyId}) | ||
171 | + if err != nil { | ||
172 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
173 | + } | ||
174 | + if company == nil { | ||
175 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCompanyCommand.CompanyId))) | ||
176 | + } | ||
177 | + if company, err := companyRepository.Remove(company); err != nil { | ||
178 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
179 | + } else { | ||
180 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
181 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
182 | + } | ||
183 | + return company, nil | ||
184 | + } | ||
185 | +} | ||
186 | + | ||
187 | +// 更新企业 | ||
188 | +func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) { | ||
189 | + if err := updateCompanyCommand.ValidateCommand(); err != nil { | ||
190 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
191 | + } | ||
192 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
193 | + if err != nil { | ||
194 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
195 | + } | ||
196 | + if err := transactionContext.StartTransaction(); err != nil { | ||
197 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
198 | + } | ||
199 | + defer func() { | ||
200 | + transactionContext.RollbackTransaction() | ||
201 | + }() | ||
202 | + var companyRepository domain.CompanyRepository | ||
203 | + if value, err := factory.CreateCompanyRepository(map[string]interface{}{ | ||
204 | + "transactionContext": transactionContext, | ||
205 | + }); err != nil { | ||
206 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
207 | + } else { | ||
208 | + companyRepository = value | ||
209 | + } | ||
210 | + company, err := companyRepository.FindOne(map[string]interface{}{"companyId": updateCompanyCommand.CompanyId}) | ||
211 | + if err != nil { | ||
212 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
213 | + } | ||
214 | + if company == nil { | ||
215 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCompanyCommand.CompanyId))) | ||
216 | + } | ||
217 | + if err := company.Update(tool_funs.SimpleStructToMap(updateCompanyCommand)); err != nil { | ||
218 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
219 | + } | ||
220 | + if company, err := companyRepository.Save(company); err != nil { | ||
221 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
222 | + } else { | ||
223 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
224 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
225 | + } | ||
226 | + return company, nil | ||
227 | + } | ||
228 | +} | ||
229 | + | ||
230 | +// 更新自定义菜单 | ||
231 | +func (companyService *CompanyService) UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand *command.UpdateCompanyCustomizeMenusCommand) (interface{}, error) { | ||
232 | + if err := updateCompanyCustomizeMenusCommand.ValidateCommand(); err != nil { | ||
233 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
234 | + } | ||
235 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
236 | + if err != nil { | ||
237 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
238 | + } | ||
239 | + if err := transactionContext.StartTransaction(); err != nil { | ||
240 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
241 | + } | ||
242 | + defer func() { | ||
243 | + transactionContext.RollbackTransaction() | ||
244 | + }() | ||
245 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
246 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
247 | + } | ||
248 | + return nil, nil | ||
249 | +} | ||
250 | + | ||
251 | +func NewCompanyService(options map[string]interface{}) *CompanyService { | ||
252 | + newCompanyService := &CompanyService{} | ||
253 | + return newCompanyService | ||
254 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/company/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/company/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/company/service" | ||
8 | +) | ||
9 | + | ||
10 | +type CompanyController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *CompanyController) CreateCompany() { | ||
15 | + companyService := service.NewCompanyService(nil) | ||
16 | + createCompanyCommand := &command.CreateCompanyCommand{} | ||
17 | + controller.Unmarshal(createCompanyCommand) | ||
18 | + data, err := companyService.CreateCompany(createCompanyCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *CompanyController) UpdateCompany() { | ||
23 | + companyService := service.NewCompanyService(nil) | ||
24 | + updateCompanyCommand := &command.UpdateCompanyCommand{} | ||
25 | + controller.Unmarshal(updateCompanyCommand) | ||
26 | + companyId, _ := controller.GetInt64(":companyId") | ||
27 | + updateCompanyCommand.CompanyId = companyId | ||
28 | + data, err := companyService.UpdateCompany(updateCompanyCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *CompanyController) GetCompany() { | ||
33 | + companyService := service.NewCompanyService(nil) | ||
34 | + getCompanyQuery := &query.GetCompanyQuery{} | ||
35 | + companyId, _ := controller.GetInt64(":companyId") | ||
36 | + getCompanyQuery.CompanyId = companyId | ||
37 | + data, err := companyService.GetCompany(getCompanyQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *CompanyController) RemoveCompany() { | ||
42 | + companyService := service.NewCompanyService(nil) | ||
43 | + removeCompanyCommand := &command.RemoveCompanyCommand{} | ||
44 | + controller.Unmarshal(removeCompanyCommand) | ||
45 | + companyId, _ := controller.GetInt64(":companyId") | ||
46 | + removeCompanyCommand.CompanyId = companyId | ||
47 | + data, err := companyService.RemoveCompany(removeCompanyCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *CompanyController) ListCompany() { | ||
52 | + companyService := service.NewCompanyService(nil) | ||
53 | + listCompanyQuery := &query.ListCompanyQuery{} | ||
54 | + data, err := companyService.ListCompany(listCompanyQuery) | ||
55 | + controller.Response(data, err) | ||
56 | +} | ||
57 | + | ||
58 | +func (controller *CompanyController) ListCompanyCustomizeMenus() { | ||
59 | + companyService := service.NewCompanyService(nil) | ||
60 | + listCompanyCustomizeMenusCommand := &command.ListCompanyCustomizeMenusCommand{} | ||
61 | + controller.Unmarshal(listCompanyCustomizeMenusCommand) | ||
62 | + companyId, _ := controller.GetInt64(":companyId") | ||
63 | + listCompanyCustomizeMenusCommand.CompanyId = companyId | ||
64 | + data, err := companyService.ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand) | ||
65 | + controller.Response(data, err) | ||
66 | +} | ||
67 | + | ||
68 | +func (controller *CompanyController) UpdateCompanyCustomizeMenus() { | ||
69 | + companyService := service.NewCompanyService(nil) | ||
70 | + updateCompanyCustomizeMenusCommand := &command.UpdateCompanyCustomizeMenusCommand{} | ||
71 | + controller.Unmarshal(updateCompanyCustomizeMenusCommand) | ||
72 | + companyId, _ := controller.GetInt64(":companyId") | ||
73 | + updateCompanyCustomizeMenusCommand.CompanyId = companyId | ||
74 | + data, err := companyService.UpdateCompanyCustomizeMenus(updateCompanyCustomizeMenusCommand) | ||
75 | + controller.Response(data, err) | ||
76 | +} |
pkg/port/beego/routers/company_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/company/", &controllers.CompanyController{}, "Post:CreateCompany") | ||
10 | + web.Router("/company/:companyId", &controllers.CompanyController{}, "Put:UpdateCompany") | ||
11 | + web.Router("/company/:companyId", &controllers.CompanyController{}, "Get:GetCompany") | ||
12 | + web.Router("/company/:companyId", &controllers.CompanyController{}, "Delete:RemoveCompany") | ||
13 | + web.Router("/company/search", &controllers.CompanyController{}, "Post:ListCompany") | ||
14 | + web.Router("/company/:companyId/customize-menus/", &controllers.CompanyController{}, "Get:ListCompanyCustomizeMenus") | ||
15 | + web.Router("/company/:companyId/customize-menus", &controllers.CompanyController{}, "Put:UpdateCompanyCustomizeMenus") | ||
16 | +} |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/beego/beego/v2/server/web" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestCompany(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Company Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = web.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + . "github.com/onsi/ginkgo" | ||
8 | + . "github.com/onsi/gomega" | ||
9 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
10 | +) | ||
11 | + | ||
12 | +var _ = Describe("创建企业", func() { | ||
13 | + Describe("提交数据创建企业", func() { | ||
14 | + Context("提交正确的新企业信息 (base)数据", func() { | ||
15 | + It("返回企业信息 (base)数据", func() { | ||
16 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
17 | + body := map[string]interface{}{ | ||
18 | + "companyName": "string", | ||
19 | + "scale": "string", | ||
20 | + "logo": "string", | ||
21 | + "address": "string", | ||
22 | + "industryCategory": "string", | ||
23 | + "contacts": "string", | ||
24 | + "registeredTime": "datetime", | ||
25 | + "status": "int", | ||
26 | + } | ||
27 | + httpExpect.POST("/company/"). | ||
28 | + WithJSON(body). | ||
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("companyId").ValueNotEqual("companyId", BeZero()) | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM company WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回企业", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据companyId参数返回企业信息 (base)", func() { | ||
23 | + Context("传入有效的companyId", func() { | ||
24 | + It("返回企业信息 (base)数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/company/{companyId}"). | ||
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 company WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回自定义菜单列表", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
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("/company/{companyId}/customize-menus/"). | ||
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 companys WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回企业列表", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回企业信息 (base)列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回企业信息 (base)数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "offset": "int", | ||
28 | + "limit": "int", | ||
29 | + } | ||
30 | + httpExpect.POST("/company/search"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object(). | ||
39 | + ContainsKey("count").ValueEqual("count", 1). | ||
40 | + ContainsKey("companys").Value("companys").Array() | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM companys WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除企业", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除企业", func() { | ||
23 | + Context("传入有效的companyId", func() { | ||
24 | + It("返回被移除企业信息 (base)的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/company/{companyId}"). | ||
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 companys WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新自定义菜单", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
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 | + "menuId": "int64", | ||
28 | + "menuName": "string", | ||
29 | + "menuAlias": "string", | ||
30 | + "sort": "int", | ||
31 | + } | ||
32 | + httpExpect.PUT("/company/{companyId}/customize-menus"). | ||
33 | + WithJSON(body). | ||
34 | + Expect(). | ||
35 | + Status(http.StatusOK). | ||
36 | + JSON(). | ||
37 | + Object(). | ||
38 | + ContainsKey("code").ValueEqual("code", 0). | ||
39 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
40 | + ContainsKey("data").Value("data").Object() | ||
41 | + }) | ||
42 | + }) | ||
43 | + }) | ||
44 | + AfterEach(func() { | ||
45 | + _, err := pG.DB.Exec("DELETE FROM company WHERE true") | ||
46 | + Expect(err).NotTo(HaveOccurred()) | ||
47 | + }) | ||
48 | +}) |
1 | +package company | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg/v10" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新企业", func() { | ||
14 | + var companyId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&companyId), | ||
18 | + "INSERT INTO company (company_id, company_config, company_info, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) RETURNING company_id", | ||
19 | + "testCompanyId", "testCompanyConfig", "testCompanyInfo", "testStatus", "testCreatedAt", "testUpdatedAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据更新企业", func() { | ||
23 | + Context("提交正确的企业信息 (base)数据", func() { | ||
24 | + It("返回更新后的企业信息 (base)数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "companyName": "string", | ||
28 | + "address": "string", | ||
29 | + "systemName": "string", | ||
30 | + "logo": "string", | ||
31 | + } | ||
32 | + httpExpect.PUT("/company/{companyId}"). | ||
33 | + WithJSON(body). | ||
34 | + Expect(). | ||
35 | + Status(http.StatusOK). | ||
36 | + JSON(). | ||
37 | + Object(). | ||
38 | + ContainsKey("code").ValueEqual("code", 0). | ||
39 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
40 | + ContainsKey("data").Value("data").Object(). | ||
41 | + ContainsKey("companyId").ValueEqual("companyId", companyId) | ||
42 | + }) | ||
43 | + }) | ||
44 | + }) | ||
45 | + AfterEach(func() { | ||
46 | + _, err := pG.DB.Exec("DELETE FROM company WHERE true") | ||
47 | + Expect(err).NotTo(HaveOccurred()) | ||
48 | + }) | ||
49 | +}) |
-
请 注册 或 登录 后发表评论