优化结构
This commit is contained in:
@@ -25,16 +25,16 @@ func TestCatalogContainsBuiltInModulesInDependencyOrder(t *testing.T) {
|
||||
t.Fatalf("definition[%d] = %q, want %q", index, got, name)
|
||||
}
|
||||
}
|
||||
if got := catalog.MigrationSteps(); len(got) != 8 {
|
||||
t.Fatalf("module migrations = %d, want 8", len(got))
|
||||
if got := catalog.MigrationSteps(); len(got) != 11 {
|
||||
t.Fatalf("module migrations = %d, want 11", len(got))
|
||||
}
|
||||
var menus, apis int
|
||||
for _, definition := range catalog.Definitions {
|
||||
menus += len(definition.Surface.Menus)
|
||||
apis += len(definition.Surface.APIs)
|
||||
}
|
||||
if menus != 3 || apis != 15 {
|
||||
t.Fatalf("admin surface = %d menus/%d APIs, want 3/15", menus, apis)
|
||||
if menus != 3 || apis != 17 {
|
||||
t.Fatalf("admin surface = %d menus/%d APIs, want 3/17", menus, apis)
|
||||
}
|
||||
if got := catalog.DefaultTimedTasks(); len(got) != 2 {
|
||||
t.Fatalf("default timed tasks = %d, want 2", len(got))
|
||||
|
||||
@@ -4,21 +4,60 @@ package payment
|
||||
|
||||
import (
|
||||
datapayment "kra/internal/data/payment"
|
||||
datasystem "kra/internal/data/system"
|
||||
"kra/internal/modules/surface"
|
||||
"kra/pkg/database/migration"
|
||||
"kra/pkg/module"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Definition declares the payment-owned schema and administration surface.
|
||||
func Definition() module.Definition {
|
||||
menus := []module.Menu{
|
||||
{Name: "paymentOrders", Path: "paymentOrders", ParentName: "extensions", Component: "view/systemTools/payment/orders.vue", Title: "支付订单", Icon: "wallet", Sort: 6},
|
||||
{Name: "paymentConfig", Path: "paymentConfig", ParentName: "extensions", Component: "view/systemTools/payment/config.vue", Title: "支付配置", Icon: "credit-card", Sort: 7},
|
||||
}
|
||||
adminSurface := module.Surface{
|
||||
Menus: menus,
|
||||
APIs: surface.APIsForPrefix("/payment", 12),
|
||||
}
|
||||
// Keep the contents of shipped migrations immutable. Future payment routes
|
||||
// belong in a new migration instead of silently changing this snapshot.
|
||||
upgradeSurface := module.Surface{Menus: menus, APIs: []module.API{
|
||||
{Path: "/payment/orders", Method: "GET", Group: "支付", Description: "分页查询支付订单"},
|
||||
{Path: "/payment/orders/summary", Method: "GET", Group: "支付", Description: "汇总支付订单运营指标"},
|
||||
{Path: "/payment/orders/:provider/:tradeNo", Method: "GET", Group: "支付", Description: "按路径查询支付订单"},
|
||||
{Path: "/payment/orders/:provider/:tradeNo/events", Method: "GET", Group: "支付", Description: "查询支付订单事件流水"},
|
||||
{Path: "/payment/create", Method: "POST", Group: "支付", Description: "创建支付订单"},
|
||||
{Path: "/payment/fulfill", Method: "POST", Group: "支付", Description: "重试支付订单发货"},
|
||||
{Path: "/payment/order", Method: "POST", Group: "支付", Description: "查询支付订单"},
|
||||
{Path: "/payment/orders/:provider/:tradeNo/fulfill", Method: "POST", Group: "支付", Description: "按路径重试支付订单发货"},
|
||||
{Path: "/payment/orders/:provider/:tradeNo/refund", Method: "POST", Group: "支付", Description: "按路径申请支付订单退款"},
|
||||
{Path: "/payment/providers/:provider/test", Method: "POST", Group: "支付", Description: "测试支付渠道配置与沙箱交易链路"},
|
||||
{Path: "/payment/query", Method: "POST", Group: "支付", Description: "同步支付订单状态"},
|
||||
{Path: "/payment/refund", Method: "POST", Group: "支付", Description: "申请支付订单退款"},
|
||||
}}
|
||||
orderReadAPIs := make([]module.API, 0, 4)
|
||||
for _, api := range upgradeSurface.APIs {
|
||||
if api.Method == "GET" && (api.Path == "/payment/orders" || api.Path == "/payment/orders/summary" || api.Path == "/payment/orders/:provider/:tradeNo" || api.Path == "/payment/orders/:provider/:tradeNo/events") {
|
||||
orderReadAPIs = append(orderReadAPIs, api)
|
||||
}
|
||||
}
|
||||
migrations := append(datapayment.Migrations(), migration.Step{ID: "202608290002_payment_admin_surface", Migrate: func(db *gorm.DB) error {
|
||||
if err := datasystem.EnsureAdminSurface(db, upgradeSurface, 888); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := datasystem.InheritAPIPolicy(db, "/payment/orders", "GET", "/payment/orders/summary", "GET"); err != nil {
|
||||
return err
|
||||
}
|
||||
return datasystem.InheritAPIPolicy(db, "/payment/orders/:provider/:tradeNo", "GET", "/payment/orders/:provider/:tradeNo/events", "GET")
|
||||
}}, migration.Step{ID: "202608290003_payment_order_read_permissions", Migrate: func(db *gorm.DB) error {
|
||||
return datasystem.GrantMenuAPIs(db, "paymentOrders", orderReadAPIs)
|
||||
}})
|
||||
return module.Definition{
|
||||
Name: "payment",
|
||||
Migrations: datapayment.Migrations(),
|
||||
Surface: module.Surface{
|
||||
Menus: []module.Menu{
|
||||
{Name: "paymentOrders", Path: "paymentOrders", ParentName: "extensions", Component: "view/systemTools/payment/orders.vue", Title: "支付订单", Icon: "wallet", Sort: 6},
|
||||
{Name: "paymentConfig", Path: "paymentConfig", ParentName: "extensions", Component: "view/systemTools/payment/config.vue", Title: "支付配置", Icon: "credit-card", Sort: 7},
|
||||
},
|
||||
APIs: surface.APIsForPrefix("/payment", 10),
|
||||
},
|
||||
Migrations: migrations,
|
||||
Surface: adminSurface,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ func TestDefinitionOwnsPaymentContributions(t *testing.T) {
|
||||
if definition.Name != "payment" {
|
||||
t.Fatalf("name = %q, want payment", definition.Name)
|
||||
}
|
||||
if len(definition.Migrations) != 1 {
|
||||
t.Fatalf("migrations = %d, want 1", len(definition.Migrations))
|
||||
if len(definition.Migrations) != 4 {
|
||||
t.Fatalf("migrations = %d, want 4", len(definition.Migrations))
|
||||
}
|
||||
if len(definition.Surface.Menus) != 2 || len(definition.Surface.APIs) != 10 {
|
||||
t.Fatalf("surface = %d menus/%d APIs, want 2/10", len(definition.Surface.Menus), len(definition.Surface.APIs))
|
||||
if len(definition.Surface.Menus) != 2 || len(definition.Surface.APIs) != 12 {
|
||||
t.Fatalf("surface = %d menus/%d APIs, want 2/12", len(definition.Surface.Menus), len(definition.Surface.APIs))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user