正在显示
19 个修改的文件
包含
1042 行增加
和
0 行删除
pkg/application/order/command/cancel.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type CancelCommand struct { | ||
11 | + // 订单编号 | ||
12 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
13 | + // 公司id | ||
14 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
15 | + // 是否是公司负责人 | ||
16 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
17 | + // 统一用户id | ||
18 | + Uid int64 `json:"uid" valid:"Required"` | ||
19 | + // 用户账号 | ||
20 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
21 | + // 用户头像URL | ||
22 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
23 | + // 用户名称 | ||
24 | + UserName string `json:"userName" valid:"Required"` | ||
25 | + // 邮件地址 | ||
26 | + Email string `json:"email" valid:"Required"` | ||
27 | + // 性别 | ||
28 | + Gender int `json:"gender" valid:"Required"` | ||
29 | + // 入职时间 | ||
30 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
31 | + // 分机 | ||
32 | + Extension string `json:"extension" valid:"Required"` | ||
33 | + // 工作地 | ||
34 | + Workplace string `json:"workplace" valid:"Required"` | ||
35 | + // 私人电话 | ||
36 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
37 | + // 工号 | ||
38 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
39 | +} | ||
40 | + | ||
41 | +func (cancelCommand *CancelCommand) Valid(validation *validation.Validation) { | ||
42 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | +} | ||
44 | + | ||
45 | +func (cancelCommand *CancelCommand) ValidateCommand() error { | ||
46 | + valid := validation.Validation{} | ||
47 | + b, err := valid.Valid(cancelCommand) | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if !b { | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type CreateOrderCommand struct { | ||
10 | + // 订单编号 | ||
11 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
12 | + // 公司Id | ||
13 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
14 | + // 买家名称 | ||
15 | + BuyerName string `json:"buyerName,omitempty"` | ||
16 | + // 联系信息 | ||
17 | + ContactInfo string `json:"contactInfo,omitempty"` | ||
18 | + // 发货地址 | ||
19 | + ShippingAddress string `json:"shippingAddress,omitempty"` | ||
20 | + // 订单商品总数 | ||
21 | + OrderNum int64 `json:"orderNum" valid:"Required"` | ||
22 | + // 订单总价 | ||
23 | + TotalPrice float64 `json:"totalPrice" valid:"Required"` | ||
24 | +} | ||
25 | + | ||
26 | +func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { | ||
27 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
28 | +} | ||
29 | + | ||
30 | +func (createOrderCommand *CreateOrderCommand) ValidateCommand() error { | ||
31 | + valid := validation.Validation{} | ||
32 | + b, err := valid.Valid(createOrderCommand) | ||
33 | + if err != nil { | ||
34 | + return err | ||
35 | + } | ||
36 | + if !b { | ||
37 | + for _, validErr := range valid.Errors { | ||
38 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
39 | + } | ||
40 | + } | ||
41 | + return nil | ||
42 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type DrawDividendsCommand struct { | ||
10 | + // 参与分红的合伙人 | ||
11 | + PartnerId int64 `json:"partnerId" valid:"Required"` | ||
12 | + // 进行分红的订单编号 | ||
13 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(drawDividendsCommand) | ||
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 | +} |
pkg/application/order/command/receiving.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type ReceivingCommand struct { | ||
11 | + // 订单号 | ||
12 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
13 | + // 是否是公司负责人 | ||
14 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
15 | + // 统一用户id | ||
16 | + Uid int64 `json:"uid" valid:"Required"` | ||
17 | + // 用户账号 | ||
18 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
19 | + // 用户头像URL | ||
20 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
21 | + // 用户名称 | ||
22 | + UserName string `json:"userName" valid:"Required"` | ||
23 | + // 邮件地址 | ||
24 | + Email string `json:"email" valid:"Required"` | ||
25 | + // 性别 | ||
26 | + Gender int `json:"gender" valid:"Required"` | ||
27 | + // 入职时间 | ||
28 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
29 | + // 分机 | ||
30 | + Extension string `json:"extension" valid:"Required"` | ||
31 | + // 工作地 | ||
32 | + Workplace string `json:"workplace" valid:"Required"` | ||
33 | + // 私人电话 | ||
34 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
35 | + // 工号 | ||
36 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
37 | + // 公司id | ||
38 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
39 | +} | ||
40 | + | ||
41 | +func (receivingCommand *ReceivingCommand) Valid(validation *validation.Validation) { | ||
42 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | +} | ||
44 | + | ||
45 | +func (receivingCommand *ReceivingCommand) ValidateCommand() error { | ||
46 | + valid := validation.Validation{} | ||
47 | + b, err := valid.Valid(receivingCommand) | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if !b { | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveOrderCommand struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(removeOrderCommand) | ||
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 | +} |
pkg/application/order/command/return.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/core/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type ReturnCommand struct { | ||
11 | + // 订单号 | ||
12 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
13 | + // 是否是公司负责人 | ||
14 | + IsPrincipal bool `json:"isPrincipal" valid:"Required"` | ||
15 | + // 统一用户id | ||
16 | + Uid int64 `json:"uid" valid:"Required"` | ||
17 | + // 用户账号 | ||
18 | + UserAccount string `json:"userAccount" valid:"Required"` | ||
19 | + // 用户头像URL | ||
20 | + UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"` | ||
21 | + // 用户名称 | ||
22 | + UserName string `json:"userName" valid:"Required"` | ||
23 | + // 邮件地址 | ||
24 | + Email string `json:"email" valid:"Required"` | ||
25 | + // 性别 | ||
26 | + Gender int `json:"gender" valid:"Required"` | ||
27 | + // 入职时间 | ||
28 | + EntryTime time.Time `json:"entryTime" valid:"Required"` | ||
29 | + // 分机 | ||
30 | + Extension string `json:"extension" valid:"Required"` | ||
31 | + // 工作地 | ||
32 | + Workplace string `json:"workplace" valid:"Required"` | ||
33 | + // 私人电话 | ||
34 | + PrivateNumber string `json:"privateNumber" valid:"Required"` | ||
35 | + // 工号 | ||
36 | + JobNumber string `json:"jobNumber" valid:"Required"` | ||
37 | + // 公司id | ||
38 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
39 | +} | ||
40 | + | ||
41 | +func (returnCommand *ReturnCommand) Valid(validation *validation.Validation) { | ||
42 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | +} | ||
44 | + | ||
45 | +func (returnCommand *ReturnCommand) ValidateCommand() error { | ||
46 | + valid := validation.Validation{} | ||
47 | + b, err := valid.Valid(returnCommand) | ||
48 | + if err != nil { | ||
49 | + return err | ||
50 | + } | ||
51 | + if !b { | ||
52 | + for _, validErr := range valid.Errors { | ||
53 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
54 | + } | ||
55 | + } | ||
56 | + return nil | ||
57 | +} |
pkg/application/order/command/shipping.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ShippingCommand struct { | ||
10 | + // 发货单号 | ||
11 | + DeliveryCode string `json:"deliveryCode" valid:"Required"` | ||
12 | + // 订单编号 | ||
13 | + OrderNo string `json:"orderNo" valid:"Required"` | ||
14 | + // 订单数量 | ||
15 | + OrderNum int64 `json:"orderNum" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +func (shippingCommand *ShippingCommand) Valid(validation *validation.Validation) { | ||
19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (shippingCommand *ShippingCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(shippingCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type UpdateOrderCommand struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(updateOrderCommand) | ||
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 | +} |
pkg/application/order/query/get_order.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetOrderQuery struct { | ||
10 | + // 订单id | ||
11 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (getOrderQuery *GetOrderQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(getOrderQuery) | ||
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 | +} |
pkg/application/order/query/list_order.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListOrderQuery struct { | ||
10 | + // 查询偏离量 | ||
11 | + Offset int `json:"offset" valid:"Required"` | ||
12 | + // 查询限制 | ||
13 | + Limit int `json:"limit" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (listOrderQuery *ListOrderQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(listOrderQuery) | ||
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 | +} |
pkg/application/order/service/order.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/mmm-go-pp/partner01/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/command" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
11 | + "strconv" | ||
12 | +) | ||
13 | + | ||
14 | +// 订单基础服务 | ||
15 | +type OrderService struct { | ||
16 | +} | ||
17 | + | ||
18 | +// 取消订单服务 | ||
19 | +func (orderService *OrderService) Cancel(cancelCommand *command.CancelCommand) (interface{}, error) { | ||
20 | + if err := cancelCommand.ValidateCommand(); err != nil { | ||
21 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
22 | + } | ||
23 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
24 | + if err != nil { | ||
25 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
26 | + } | ||
27 | + if err := transactionContext.StartTransaction(); err != nil { | ||
28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
29 | + } | ||
30 | + defer func() { | ||
31 | + _ = transactionContext.RollbackTransaction() | ||
32 | + }() | ||
33 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
34 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
35 | + } | ||
36 | + return nil, nil | ||
37 | +} | ||
38 | + | ||
39 | +// 创建订单增删改查 | ||
40 | +func (orderService *OrderService) CreateOrder(createOrderCommand *command.CreateOrderCommand) (interface{}, error) { | ||
41 | + if err := createOrderCommand.ValidateCommand(); err != nil { | ||
42 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
43 | + } | ||
44 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
45 | + if err != nil { | ||
46 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
47 | + } | ||
48 | + if err := transactionContext.StartTransaction(); err != nil { | ||
49 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
50 | + } | ||
51 | + defer func() { | ||
52 | + _ = transactionContext.RollbackTransaction() | ||
53 | + }() | ||
54 | + newOrder := &domain.Order{ | ||
55 | + OrderNo: createOrderCommand.OrderNo, | ||
56 | + CompanyId: createOrderCommand.CompanyId, | ||
57 | + Buyer: &domain.BuyerInfo{ | ||
58 | + BuyerName: createOrderCommand.BuyerName, | ||
59 | + }, | ||
60 | + TotalPrice: createOrderCommand.TotalPrice, | ||
61 | + } | ||
62 | + var orderRepository domain.OrderRepository | ||
63 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
64 | + "transactionContext": transactionContext, | ||
65 | + }); err != nil { | ||
66 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
67 | + } else { | ||
68 | + orderRepository = value | ||
69 | + } | ||
70 | + if order, err := orderRepository.Save(newOrder); err != nil { | ||
71 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
72 | + } else { | ||
73 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
74 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
75 | + } | ||
76 | + return order, nil | ||
77 | + } | ||
78 | +} | ||
79 | + | ||
80 | +// 订单分红服务 | ||
81 | +func (orderService *OrderService) DarwDividends(darwDividendsCommand *command.DrawDividendsCommand) (interface{}, error) { | ||
82 | + if err := darwDividendsCommand.ValidateCommand(); err != nil { | ||
83 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
84 | + } | ||
85 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
86 | + if err != nil { | ||
87 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
88 | + } | ||
89 | + if err := transactionContext.StartTransaction(); err != nil { | ||
90 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
91 | + } | ||
92 | + defer func() { | ||
93 | + _ = transactionContext.RollbackTransaction() | ||
94 | + }() | ||
95 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
96 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
97 | + } | ||
98 | + return nil, nil | ||
99 | +} | ||
100 | + | ||
101 | +// 返回订单增删改查 | ||
102 | +func (orderService *OrderService) GetOrder(getOrderQuery *query.GetOrderQuery) (interface{}, error) { | ||
103 | + if err := getOrderQuery.ValidateQuery(); err != nil { | ||
104 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
105 | + } | ||
106 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
107 | + if err != nil { | ||
108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
109 | + } | ||
110 | + if err := transactionContext.StartTransaction(); err != nil { | ||
111 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
112 | + } | ||
113 | + defer func() { | ||
114 | + _ = transactionContext.RollbackTransaction() | ||
115 | + }() | ||
116 | + var orderRepository domain.OrderRepository | ||
117 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
118 | + "transactionContext": transactionContext, | ||
119 | + }); err != nil { | ||
120 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
121 | + } else { | ||
122 | + orderRepository = value | ||
123 | + } | ||
124 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": getOrderQuery.OrderId}) | ||
125 | + if err != nil { | ||
126 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
127 | + } | ||
128 | + if order == nil { | ||
129 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getOrderQuery.OrderId, 10))) | ||
130 | + } else { | ||
131 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
132 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
133 | + } | ||
134 | + return order, nil | ||
135 | + } | ||
136 | +} | ||
137 | + | ||
138 | +// 返回订单增删改查列表 | ||
139 | +func (orderService *OrderService) ListOrder(listOrderQuery *query.ListOrderQuery) (interface{}, error) { | ||
140 | + if err := listOrderQuery.ValidateQuery(); err != nil { | ||
141 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
142 | + } | ||
143 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
144 | + if err != nil { | ||
145 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
146 | + } | ||
147 | + if err := transactionContext.StartTransaction(); err != nil { | ||
148 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
149 | + } | ||
150 | + defer func() { | ||
151 | + _ = transactionContext.RollbackTransaction() | ||
152 | + }() | ||
153 | + var orderRepository domain.OrderRepository | ||
154 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
155 | + "transactionContext": transactionContext, | ||
156 | + }); err != nil { | ||
157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
158 | + } else { | ||
159 | + orderRepository = value | ||
160 | + } | ||
161 | + if count, orders, err := orderRepository.Find(tool_funs.SimpleStructToMap(listOrderQuery)); 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 map[string]interface{}{ | ||
168 | + "count": count, | ||
169 | + "orders": orders, | ||
170 | + }, nil | ||
171 | + } | ||
172 | +} | ||
173 | + | ||
174 | +// 订单收货服务 | ||
175 | +func (orderService *OrderService) Receiving(receivingCommand *command.ReceivingCommand) (interface{}, error) { | ||
176 | + if err := receivingCommand.ValidateCommand(); err != nil { | ||
177 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
178 | + } | ||
179 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
180 | + if err != nil { | ||
181 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
182 | + } | ||
183 | + if err := transactionContext.StartTransaction(); err != nil { | ||
184 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
185 | + } | ||
186 | + defer func() { | ||
187 | + _ = transactionContext.RollbackTransaction() | ||
188 | + }() | ||
189 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
190 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
191 | + } | ||
192 | + return nil, nil | ||
193 | +} | ||
194 | + | ||
195 | +// 移除订单增删改查 | ||
196 | +func (orderService *OrderService) RemoveOrder(removeOrderCommand *command.RemoveOrderCommand) (interface{}, error) { | ||
197 | + if err := removeOrderCommand.ValidateCommand(); err != nil { | ||
198 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
199 | + } | ||
200 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
201 | + if err != nil { | ||
202 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
203 | + } | ||
204 | + if err := transactionContext.StartTransaction(); err != nil { | ||
205 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
206 | + } | ||
207 | + defer func() { | ||
208 | + _ = transactionContext.RollbackTransaction() | ||
209 | + }() | ||
210 | + var orderRepository domain.OrderRepository | ||
211 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
212 | + "transactionContext": transactionContext, | ||
213 | + }); err != nil { | ||
214 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
215 | + } else { | ||
216 | + orderRepository = value | ||
217 | + } | ||
218 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": removeOrderCommand.OrderId}) | ||
219 | + if err != nil { | ||
220 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
221 | + } | ||
222 | + if order == nil { | ||
223 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeOrderCommand.OrderId, 10))) | ||
224 | + } | ||
225 | + if order, err := orderRepository.Remove(order); err != nil { | ||
226 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
227 | + } else { | ||
228 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
229 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
230 | + } | ||
231 | + return order, nil | ||
232 | + } | ||
233 | +} | ||
234 | + | ||
235 | +// 订单退货服务 | ||
236 | +func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) (interface{}, error) { | ||
237 | + if err := returnCommand.ValidateCommand(); err != nil { | ||
238 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
239 | + } | ||
240 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
241 | + if err != nil { | ||
242 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
243 | + } | ||
244 | + if err := transactionContext.StartTransaction(); err != nil { | ||
245 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
246 | + } | ||
247 | + defer func() { | ||
248 | + _ = transactionContext.RollbackTransaction() | ||
249 | + }() | ||
250 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
251 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
252 | + } | ||
253 | + return nil, nil | ||
254 | +} | ||
255 | + | ||
256 | +// 订单发货服务 | ||
257 | +func (orderService *OrderService) Shipping(shippingCommand *command.ShippingCommand) (interface{}, error) { | ||
258 | + if err := shippingCommand.ValidateCommand(); err != nil { | ||
259 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
260 | + } | ||
261 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
262 | + if err != nil { | ||
263 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
264 | + } | ||
265 | + if err := transactionContext.StartTransaction(); err != nil { | ||
266 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
267 | + } | ||
268 | + defer func() { | ||
269 | + _ = transactionContext.RollbackTransaction() | ||
270 | + }() | ||
271 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
272 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
273 | + } | ||
274 | + return nil, nil | ||
275 | +} | ||
276 | + | ||
277 | +// 更新订单增删改查 | ||
278 | +func (orderService *OrderService) UpdateOrder(updateOrderCommand *command.UpdateOrderCommand) (interface{}, error) { | ||
279 | + if err := updateOrderCommand.ValidateCommand(); err != nil { | ||
280 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
281 | + } | ||
282 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
283 | + if err != nil { | ||
284 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
285 | + } | ||
286 | + if err := transactionContext.StartTransaction(); err != nil { | ||
287 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
288 | + } | ||
289 | + defer func() { | ||
290 | + _ = transactionContext.RollbackTransaction() | ||
291 | + }() | ||
292 | + var orderRepository domain.OrderRepository | ||
293 | + if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
294 | + "transactionContext": transactionContext, | ||
295 | + }); err != nil { | ||
296 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
297 | + } else { | ||
298 | + orderRepository = value | ||
299 | + } | ||
300 | + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": updateOrderCommand.OrderId}) | ||
301 | + if err != nil { | ||
302 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
303 | + } | ||
304 | + if order == nil { | ||
305 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(updateOrderCommand.OrderId, 10))) | ||
306 | + } | ||
307 | + if err := order.Update(tool_funs.SimpleStructToMap(updateOrderCommand)); err != nil { | ||
308 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
309 | + } | ||
310 | + if order, err := orderRepository.Save(order); err != nil { | ||
311 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
312 | + } else { | ||
313 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
314 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
315 | + } | ||
316 | + return order, nil | ||
317 | + } | ||
318 | +} | ||
319 | + | ||
320 | +func NewOrderService(options map[string]interface{}) *OrderService { | ||
321 | + newOrderService := &OrderService{} | ||
322 | + return newOrderService | ||
323 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/command" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/service" | ||
8 | +) | ||
9 | + | ||
10 | +type OrderController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +func (controller *OrderController) CreateOrder() { | ||
15 | + orderService := service.NewOrderService(nil) | ||
16 | + createOrderCommand := &command.CreateOrderCommand{} | ||
17 | + controller.Unmarshal(createOrderCommand) | ||
18 | + data, err := orderService.CreateOrder(createOrderCommand) | ||
19 | + controller.Response(data, err) | ||
20 | +} | ||
21 | + | ||
22 | +func (controller *OrderController) UpdateOrder() { | ||
23 | + orderService := service.NewOrderService(nil) | ||
24 | + updateOrderCommand := &command.UpdateOrderCommand{} | ||
25 | + controller.Unmarshal(updateOrderCommand) | ||
26 | + orderId, _ := controller.GetInt64(":orderId") | ||
27 | + updateOrderCommand.OrderId = orderId | ||
28 | + data, err := orderService.UpdateOrder(updateOrderCommand) | ||
29 | + controller.Response(data, err) | ||
30 | +} | ||
31 | + | ||
32 | +func (controller *OrderController) GetOrder() { | ||
33 | + orderService := service.NewOrderService(nil) | ||
34 | + getOrderQuery := &query.GetOrderQuery{} | ||
35 | + orderId, _ := controller.GetInt64(":orderId") | ||
36 | + getOrderQuery.OrderId = orderId | ||
37 | + data, err := orderService.GetOrder(getOrderQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *OrderController) RemoveOrder() { | ||
42 | + orderService := service.NewOrderService(nil) | ||
43 | + removeOrderCommand := &command.RemoveOrderCommand{} | ||
44 | + controller.Unmarshal(removeOrderCommand) | ||
45 | + orderId, _ := controller.GetInt64(":orderId") | ||
46 | + removeOrderCommand.OrderId = orderId | ||
47 | + data, err := orderService.RemoveOrder(removeOrderCommand) | ||
48 | + controller.Response(data, err) | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *OrderController) ListOrder() { | ||
52 | + orderService := service.NewOrderService(nil) | ||
53 | + listOrderQuery := &query.ListOrderQuery{} | ||
54 | + offset, _ := controller.GetInt("offset") | ||
55 | + listOrderQuery.Offset = offset | ||
56 | + limit, _ := controller.GetInt("limit") | ||
57 | + listOrderQuery.Limit = limit | ||
58 | + data, err := orderService.ListOrder(listOrderQuery) | ||
59 | + controller.Response(data, err) | ||
60 | +} |
pkg/port/beego/routers/order_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/orders/", &controllers.OrderController{}, "Post:CreateOrder") | ||
10 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Put:UpdateOrder") | ||
11 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Get:GetOrder") | ||
12 | + web.Router("/orders/:orderId", &controllers.OrderController{}, "Delete:RemoveOrder") | ||
13 | + web.Router("/orders/", &controllers.OrderController{}, "Get:ListOrder") | ||
14 | +} |
1 | +package order | ||
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/mmm-go-pp/partner01/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 | + "orderNo": "string", | ||
19 | + "companyId": "int64", | ||
20 | + "buyerName": "string", | ||
21 | + "contactInfo": "string", | ||
22 | + "shippingAddress": "string", | ||
23 | + "orderNum": "int64", | ||
24 | + "totalPrice": "float64", | ||
25 | + } | ||
26 | + httpExpect.POST("/orders/"). | ||
27 | + WithJSON(body). | ||
28 | + Expect(). | ||
29 | + Status(http.StatusOK). | ||
30 | + JSON(). | ||
31 | + Object(). | ||
32 | + ContainsKey("code").ValueEqual("code", 0). | ||
33 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
34 | + ContainsKey("data").Value("data").Object(). | ||
35 | + ContainsKey("orderId").ValueNotEqual("orderId", BeZero()) | ||
36 | + }) | ||
37 | + }) | ||
38 | + }) | ||
39 | + AfterEach(func() { | ||
40 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
41 | + Expect(err).NotTo(HaveOccurred()) | ||
42 | + }) | ||
43 | +}) |
1 | +package order | ||
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/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据orderId参数返回订单实体", func() { | ||
23 | + Context("传入有效的orderId", func() { | ||
24 | + It("返回订单实体数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/orders/{orderId}"). | ||
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 orders WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package order | ||
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/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回订单增删改查列表", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
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("/orders/"). | ||
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("orders").Value("orders").Array() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package order | ||
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/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestOrder(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Order 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 order | ||
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/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数移除订单增删改查", func() { | ||
23 | + Context("传入有效的orderId", func() { | ||
24 | + It("返回被移除订单实体的数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.DELETE("/orders/{orderId}"). | ||
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 orders WHERE true") | ||
39 | + Expect(err).NotTo(HaveOccurred()) | ||
40 | + }) | ||
41 | +}) |
1 | +package order | ||
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/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新订单增删改查", func() { | ||
14 | + var orderId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&orderId), | ||
18 | + "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | + "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
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 | + httpExpect.PUT("/orders/{orderId}"). | ||
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("orderId").ValueEqual("orderId", orderId) | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | + AfterEach(func() { | ||
41 | + _, err := pG.DB.Exec("DELETE FROM orders WHERE true") | ||
42 | + Expect(err).NotTo(HaveOccurred()) | ||
43 | + }) | ||
44 | +}) |
-
请 注册 或 登录 后发表评论