优化结构
This commit is contained in:
@@ -26,6 +26,7 @@ func emptyHandlers() *handler.Set {
|
||||
Version: &handler.Version{}, Dictionary: &handler.Dictionary{}, Parameter: &handler.Parameter{},
|
||||
APIToken: &handler.APIToken{}, SystemConfig: &handler.SystemConfig{}, Public: &handler.Public{},
|
||||
User: &handler.User{}, Navigation: &handler.Navigation{}, Session: &handler.Session{},
|
||||
IntegrationConfig: &handler.IntegrationConfig{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +44,21 @@ func TestGinRouteContract(t *testing.T) {
|
||||
actual = append(actual, key)
|
||||
}
|
||||
sort.Strings(actual)
|
||||
if value := strings.Join(actual, "\n"); value != expectedGinRouteContract {
|
||||
t.Fatalf("route contract changed:\n%s", value)
|
||||
value := strings.Join(actual, "\n")
|
||||
for _, route := range []string{
|
||||
"GET /integration/configs/:kind",
|
||||
"GET /integration/configs/:kind/:provider",
|
||||
"PUT /integration/configs/:kind/:provider",
|
||||
"DELETE /integration/configs/:kind/:provider",
|
||||
} {
|
||||
if !strings.Contains(value, route) {
|
||||
t.Fatalf("route contract missing %s:\n%s", route, value)
|
||||
}
|
||||
}
|
||||
for _, removed := range []string{"GET /payment/configs", "POST /payment/config"} {
|
||||
if strings.Contains(value, removed) {
|
||||
t.Fatalf("legacy payment config route still registered: %s", removed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +70,7 @@ func TestGinStartupLogsEveryRegisteredRoute(t *testing.T) {
|
||||
if got, want := strings.Count(text, `"msg":"router registered"`), len(engine.Routes()); got != want {
|
||||
t.Fatalf("registered route log count = %d, want %d", got, want)
|
||||
}
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":190`) {
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":192`) {
|
||||
t.Fatalf("startup route summary is missing: %s", text)
|
||||
}
|
||||
}
|
||||
@@ -256,7 +270,8 @@ GET /logViewer/content
|
||||
GET /logViewer/dates
|
||||
GET /logViewer/files
|
||||
GET /menu/getMenuRoles
|
||||
GET /payment/configs
|
||||
GET /integration/configs/:kind
|
||||
GET /integration/configs/:kind/:provider
|
||||
GET /payment/orders
|
||||
GET /payment/orders/:provider/:tradeNo
|
||||
GET /position/findPosition
|
||||
@@ -352,7 +367,6 @@ POST /menu/getMenuList
|
||||
POST /menu/setMenuRoles
|
||||
POST /menu/updateBaseMenu
|
||||
POST /payment/callback/:provider
|
||||
POST /payment/config
|
||||
POST /payment/create
|
||||
POST /payment/fulfill
|
||||
POST /payment/order
|
||||
@@ -394,6 +408,7 @@ POST /user/setUserPositions
|
||||
PUT /authority/updateAuthority
|
||||
PUT /department/updateDepartment
|
||||
PUT /info/updateInfo
|
||||
PUT /integration/configs/:kind/:provider
|
||||
PUT /position/updatePosition
|
||||
PUT /sysDictionary/updateSysDictionary
|
||||
PUT /sysDictionaryDetail/updateSysDictionaryDetail
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"kra/app/system/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type IntegrationConfig struct {
|
||||
service *service.IntegrationConfigService
|
||||
}
|
||||
|
||||
func NewIntegrationConfig(service *service.IntegrationConfigService) *IntegrationConfig {
|
||||
return &IntegrationConfig{service: service}
|
||||
}
|
||||
|
||||
func (h *IntegrationConfig) List(c *gin.Context) {
|
||||
configs, err := h.service.List(c.Request.Context(), c.Param("kind"))
|
||||
if err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OKWithData(c, configs)
|
||||
}
|
||||
|
||||
func (h *IntegrationConfig) Find(c *gin.Context) {
|
||||
config, err := h.service.Find(c.Request.Context(), c.Param("kind"), c.Param("provider"))
|
||||
if err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OKWithData(c, config)
|
||||
}
|
||||
|
||||
func (h *IntegrationConfig) Save(c *gin.Context) {
|
||||
var req service.IntegrationConfigRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := h.service.Save(c.Request.Context(), c.Param("kind"), c.Param("provider"), &req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OK(c)
|
||||
}
|
||||
|
||||
func (h *IntegrationConfig) Delete(c *gin.Context) {
|
||||
if err := h.service.Delete(c.Request.Context(), c.Param("kind"), c.Param("provider")); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OK(c)
|
||||
}
|
||||
@@ -11,26 +11,6 @@ import (
|
||||
type Payment struct{ service *service.PaymentService }
|
||||
|
||||
func NewPayment(service *service.PaymentService) *Payment { return &Payment{service: service} }
|
||||
func (h *Payment) Configs(c *gin.Context) {
|
||||
v, err := h.service.Configs(c.Request.Context())
|
||||
if err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OKWithData(c, v)
|
||||
}
|
||||
func (h *Payment) SaveConfig(c *gin.Context) {
|
||||
var req service.PaymentConfigRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if err := h.service.SaveConfig(c.Request.Context(), &req); err != nil {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
OK(c)
|
||||
}
|
||||
func (h *Payment) Order(c *gin.Context) {
|
||||
var req service.PaymentQueryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -8,4 +8,5 @@ var ProviderSet = wire.NewSet(
|
||||
NewAnnouncement, NewEmail, NewPayment, NewTask, NewMedia, NewAudit,
|
||||
NewExport, NewVersion, NewDictionary, NewParameter, NewAPIToken,
|
||||
NewSystemConfig, NewPublic, NewUser, NewNavigation, NewSession, NewSet,
|
||||
NewIntegrationConfig,
|
||||
)
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
package handler
|
||||
|
||||
type Set struct {
|
||||
Authority *Authority
|
||||
Menu *Menu
|
||||
API *API
|
||||
Permission *Permission
|
||||
Organization *Organization
|
||||
Announcement *Announcement
|
||||
Email *Email
|
||||
Payment *Payment
|
||||
Task *Task
|
||||
Media *Media
|
||||
Audit *Audit
|
||||
Export *Export
|
||||
Version *Version
|
||||
Dictionary *Dictionary
|
||||
Parameter *Parameter
|
||||
APIToken *APIToken
|
||||
SystemConfig *SystemConfig
|
||||
Public *Public
|
||||
User *User
|
||||
Navigation *Navigation
|
||||
Session *Session
|
||||
Authority *Authority
|
||||
Menu *Menu
|
||||
API *API
|
||||
Permission *Permission
|
||||
Organization *Organization
|
||||
Announcement *Announcement
|
||||
Email *Email
|
||||
Payment *Payment
|
||||
Task *Task
|
||||
Media *Media
|
||||
Audit *Audit
|
||||
Export *Export
|
||||
Version *Version
|
||||
Dictionary *Dictionary
|
||||
Parameter *Parameter
|
||||
APIToken *APIToken
|
||||
SystemConfig *SystemConfig
|
||||
Public *Public
|
||||
User *User
|
||||
Navigation *Navigation
|
||||
Session *Session
|
||||
IntegrationConfig *IntegrationConfig
|
||||
}
|
||||
|
||||
func NewSet(authority *Authority, menu *Menu, api *API, permission *Permission, organization *Organization, announcement *Announcement, email *Email, payment *Payment, task *Task, media *Media, audit *Audit, export *Export, version *Version, dictionary *Dictionary, parameter *Parameter, apiToken *APIToken, systemConfig *SystemConfig, public *Public, user *User, navigation *Navigation, session *Session) *Set {
|
||||
return &Set{Authority: authority, Menu: menu, API: api, Permission: permission, Organization: organization, Announcement: announcement, Email: email, Payment: payment, Task: task, Media: media, Audit: audit, Export: export, Version: version, Dictionary: dictionary, Parameter: parameter, APIToken: apiToken, SystemConfig: systemConfig, Public: public, User: user, Navigation: navigation, Session: session}
|
||||
func NewSet(authority *Authority, menu *Menu, api *API, permission *Permission, organization *Organization, announcement *Announcement, email *Email, payment *Payment, task *Task, media *Media, audit *Audit, export *Export, version *Version, dictionary *Dictionary, parameter *Parameter, apiToken *APIToken, systemConfig *SystemConfig, public *Public, user *User, navigation *Navigation, session *Session, integrationConfig *IntegrationConfig) *Set {
|
||||
return &Set{Authority: authority, Menu: menu, API: api, Permission: permission, Organization: organization, Announcement: announcement, Email: email, Payment: payment, Task: task, Media: media, Audit: audit, Export: export, Version: version, Dictionary: dictionary, Parameter: parameter, APIToken: apiToken, SystemConfig: systemConfig, Public: public, User: user, Navigation: navigation, Session: session, IntegrationConfig: integrationConfig}
|
||||
}
|
||||
|
||||
@@ -24,3 +24,4 @@ type SystemConfig = handler.SystemConfig
|
||||
type Task = handler.Task
|
||||
type User = handler.User
|
||||
type Version = handler.Version
|
||||
type IntegrationConfig = handler.IntegrationConfig
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package router
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func RegisterIntegrationConfig(group *gin.RouterGroup, handler *IntegrationConfig) {
|
||||
configs := group.Group("/integration/configs")
|
||||
configs.GET("/:kind", handler.List)
|
||||
configs.GET("/:kind/:provider", handler.Find)
|
||||
configs.PUT("/:kind/:provider", handler.Save)
|
||||
configs.DELETE("/:kind/:provider", handler.Delete)
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
func RegisterPayment(group, public *gin.RouterGroup, h *Payment) {
|
||||
payment := group.Group("/payment")
|
||||
payment.GET("/configs", h.Configs)
|
||||
payment.POST("/config", h.SaveConfig)
|
||||
payment.GET("/orders", h.Orders)
|
||||
payment.POST("/order", h.Order)
|
||||
payment.GET("/orders/:provider/:tradeNo", h.OrderByPath)
|
||||
|
||||
@@ -38,5 +38,6 @@ func (r *Routes) RegisterRoutes(public, private *gin.RouterGroup, engine *gin.En
|
||||
RegisterMedia(private, r.handlers.Media)
|
||||
RegisterAnnouncement(private, public, r.handlers.Announcement)
|
||||
RegisterEmail(private, r.handlers.Email)
|
||||
RegisterIntegrationConfig(private, r.handlers.IntegrationConfig)
|
||||
RegisterPayment(private, public, r.handlers.Payment)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user