feat(t222): add freight ingestion admin flow
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"cmroubao/backend-api/internal/config"
|
||||
"cmroubao/backend-api/internal/platform/assetstore"
|
||||
"cmroubao/backend-api/internal/platform/database"
|
||||
"cmroubao/backend-api/internal/platform/erpconnector"
|
||||
"cmroubao/backend-api/internal/platform/migration"
|
||||
"cmroubao/backend-api/internal/platform/password"
|
||||
repository "cmroubao/backend-api/internal/repository/sqlite"
|
||||
@@ -217,6 +218,31 @@ func buildRouter(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
erpTimeout := cfg.ERPConnectorTimeout
|
||||
if erpTimeout <= 0 {
|
||||
erpTimeout = 90 * time.Second
|
||||
}
|
||||
erpClient, err := erpconnector.New(
|
||||
cfg.ERPConnectorURL,
|
||||
cfg.ERPConnectorAPIKey,
|
||||
erpTimeout,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
freight, err := usecase.NewFreightService(
|
||||
store,
|
||||
erpClient,
|
||||
clock,
|
||||
ids,
|
||||
erpTimeout,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := freight.RecoverInterrupted(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
passwords, err := password.NewBcrypt(12)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -249,6 +275,7 @@ func buildRouter(
|
||||
tasks,
|
||||
assets,
|
||||
authorizations,
|
||||
freight,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -294,6 +321,7 @@ func buildRouter(
|
||||
Tasks: tasks,
|
||||
Results: results,
|
||||
Authorizations: authorizations,
|
||||
Freight: freight,
|
||||
},
|
||||
webHandler,
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -158,6 +159,36 @@ func TestBuildRouterRegistersProtectedLogoutRoute(t *testing.T) {
|
||||
response.Header().Get("Location"),
|
||||
)
|
||||
}
|
||||
for _, target := range []string{"/freight", "/freight/import"} {
|
||||
request = httptest.NewRequest(http.MethodGet, target, nil)
|
||||
response = httptest.NewRecorder()
|
||||
router.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusSeeOther ||
|
||||
response.Header().Get("Location") !=
|
||||
"/login?next="+url.QueryEscape(target) {
|
||||
t.Fatalf(
|
||||
"%s status/location = %d / %q",
|
||||
target,
|
||||
response.Code,
|
||||
response.Header().Get("Location"),
|
||||
)
|
||||
}
|
||||
}
|
||||
request = httptest.NewRequest(
|
||||
http.MethodGet,
|
||||
"/api/v1/freight-orders",
|
||||
nil,
|
||||
)
|
||||
response = httptest.NewRecorder()
|
||||
router.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusUnauthorized ||
|
||||
response.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatalf(
|
||||
"freight API status/cache = %d / %q",
|
||||
response.Code,
|
||||
response.Header().Get("Cache-Control"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
type stubMigrationStatusReader struct {
|
||||
|
||||
Reference in New Issue
Block a user