feat(platform): complete finance content audit APIs
This commit is contained in:
@@ -29,6 +29,9 @@ func RegisterPlatform(serviceKey string, engine *gin.Engine) {
|
||||
registerDeviceRoute(protected)
|
||||
registerSafetyRoute(protected)
|
||||
registerCommerceRoute(protected)
|
||||
registerFinanceRoute(protected)
|
||||
registerContentRoute(protected)
|
||||
registerAuditRoute(protected)
|
||||
registerPlatformRoute(protected)
|
||||
}
|
||||
|
||||
@@ -101,6 +104,33 @@ func registerPlatformRoute(group *gin.RouterGroup) {
|
||||
registerWritableResource(group, "/platform/platform_menu", platform.ListPlatformMenu, platform.CreatePlatformMenu, platform.GetPlatformMenu, platform.UpdatePlatformMenu, &models.PlatformMenu{})
|
||||
}
|
||||
|
||||
func registerFinanceRoute(group *gin.RouterGroup) {
|
||||
registerRestrictedWritableResource(group, "/finance/fin_payment", &models.FinPayment{}, []string{"channel", "amount", "paid_at"}, requiredRelation("ec_order_identity", "ec_order_id", &models.EcOrder{}))
|
||||
registerRestrictedWritableResource(group, "/finance/fin_settlement", &models.FinSettlement{}, []string{"settlement_no", "subject_type", "subject_id", "period_start", "period_end"})
|
||||
registerRestrictedWritableResource(group, "/finance/fin_reconciliation", &models.FinReconciliation{}, []string{"channel", "bill_date", "difference_amount"})
|
||||
|
||||
registerReadOnlyResource(group, "/wallet/wallet", &models.Wallet{})
|
||||
registerReadOnlyResource(group, "/wallet/wallet_ledger", &models.WalletLedger{})
|
||||
registerReadOnlyResource(group, "/wallet/wallet_recharge", &models.WalletRecharge{})
|
||||
registerReadOnlyResource(group, "/wallet/wallet_withdrawal", &models.WalletWithdrawal{})
|
||||
registerReadOnlyResource(group, "/report/report", &models.Report{})
|
||||
registerReadOnlyResource(group, "/report/report_item", &models.ReportItem{})
|
||||
registerReadOnlyResource(group, "/report/report_metric_snapshot", &models.ReportMetricSnapshot{})
|
||||
}
|
||||
|
||||
func registerContentRoute(group *gin.RouterGroup) {
|
||||
registerRestrictedWritableResource(group, "/content/cnt_content", &models.CntContent{}, []string{"content_type", "title", "body", "version_no", "publish_status"})
|
||||
registerRestrictedWritableResource(group, "/notification/ntf_template", &models.NtfTemplate{}, []string{"template_code", "channel", "content"})
|
||||
registerRestrictedWritableResource(group, "/customer_service/cs_ticket", &models.CsTicket{}, []string{"ticket_no", "category", "priority"}, requiredRelation("user_account_identity", "user_account_id", &models.UserAccount{}))
|
||||
}
|
||||
|
||||
func registerAuditRoute(group *gin.RouterGroup) {
|
||||
registerReadOnlyResource(group, "/audit/aud_operation_log", &models.AudOperationLog{})
|
||||
registerReadOnlyResource(group, "/audit/aud_export_log", &models.AudExportLog{})
|
||||
registerReadOnlyResource(group, "/audit/aud_approval", &models.AudApproval{})
|
||||
group.POST("/audit/aud_approval/:identity/approve", platform.ApproveAudit)
|
||||
}
|
||||
|
||||
func registerWritableResource(group *gin.RouterGroup, path string, list, create, get, update gin.HandlerFunc, model any) {
|
||||
resource := group.Group(path)
|
||||
resource.GET("", list)
|
||||
@@ -116,6 +146,13 @@ func registerRestrictedWritableResource(group *gin.RouterGroup, path string, mod
|
||||
registerWritableResource(group, path, list, create, get, update, model)
|
||||
}
|
||||
|
||||
func registerReadOnlyResource(group *gin.RouterGroup, path string, model any) {
|
||||
list, _, get, _ := platform.ResourceHandlers(model, nil, nil)
|
||||
resource := group.Group(path)
|
||||
resource.GET("", list)
|
||||
resource.GET("/:identity", get)
|
||||
}
|
||||
|
||||
func requiredRelation(input, column string, model any) platform.ResourceRelation {
|
||||
return platform.ResourceRelation{Input: input, Column: column, Model: model, Required: true}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,45 @@ func TestPlatformDeviceSafetyCommerceAndDeliveryRoutesFollowTheirContracts(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformFinanceContentAndAuditRoutesFollowTheirContracts(t *testing.T) {
|
||||
engine := gin.New()
|
||||
RegisterPlatform("heqi", engine)
|
||||
|
||||
routes := make(map[string]map[string]bool)
|
||||
for _, route := range engine.Routes() {
|
||||
if routes[route.Path] == nil {
|
||||
routes[route.Path] = make(map[string]bool)
|
||||
}
|
||||
routes[route.Path][route.Method] = true
|
||||
}
|
||||
|
||||
for _, resource := range []string{
|
||||
"/finance/fin_payment", "/finance/fin_settlement", "/finance/fin_reconciliation",
|
||||
"/content/cnt_content", "/notification/ntf_template", "/customer_service/cs_ticket",
|
||||
} {
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource, http.MethodGet, http.MethodPost)
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/:identity", http.MethodGet, http.MethodPut, http.MethodDelete)
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/:identity/status", http.MethodPatch)
|
||||
}
|
||||
|
||||
for _, resource := range []string{
|
||||
"/wallet/wallet", "/wallet/wallet_ledger", "/wallet/wallet_recharge", "/wallet/wallet_withdrawal",
|
||||
"/report/report", "/report/report_item", "/report/report_metric_snapshot",
|
||||
"/audit/aud_operation_log", "/audit/aud_export_log", "/audit/aud_approval",
|
||||
} {
|
||||
path := "/heqi/platform/v1" + resource
|
||||
assertRouteMethods(t, routes, path, http.MethodGet)
|
||||
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet)
|
||||
for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete} {
|
||||
if routes[path][method] || routes[path+"/:identity"][method] {
|
||||
t.Errorf("read-only resource %s unexpectedly permits %s", resource, method)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1/audit/aud_approval/:identity/approve", http.MethodPost)
|
||||
}
|
||||
|
||||
func assertRouteMethods(t *testing.T, routes map[string]map[string]bool, path string, methods ...string) {
|
||||
t.Helper()
|
||||
for _, method := range methods {
|
||||
|
||||
Reference in New Issue
Block a user