迁移订单 Repository 应用端口
This commit is contained in:
1 parent
5c70b9ea6a
commit
7deee4a023
4 files changed
+39
-34
No files matched your search
@@ -728,3 +728,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-15 | P1 凭证快照与账号操作协调器(Engine Token 刷新切片) | 已完成 | `refreshTokenWithMinGap` 保留 `refreshMu` 的同账号 Token 刷新和风控重试串行语义,但网络请求、风控恢复均在共享凭证锁外执行;每次响应提交前重读最新 Cookie/metadata,检测到并发变化时丢弃旧 Token 响应并使用最新快照重试;新增慢 I/O、锁可获取和并发 Cookie 变化重试测试,Engine 全量测试、聚焦 race、注释门禁通过。Automation、Server 其他调用方和版本化持久化冲突控制仍未完成,阶段 2/4/5/8/9 继续保持“进行中” |
|
||||
| 2026-08-15 | P0 敏感系统设置命令语义切片 | 已完成 | 管理端系统设置更新新增 `values`/`secrets` 分离 DTO;敏感设置仅接受 `retain`、`replace`、`clear` 命令,普通 `values` 和旧版顶层字段均拒绝敏感键;数据库原子应用普通设置与敏感命令;补充 Go 数据库/HTTP 回归和 React API 请求体测试,定向 Go/React 测试与前端类型检查通过。P0 三库迁移回归、所有运维输出和敏感访问审计仍待完成 |
|
||||
| 2026-08-15 | P1 订单运行时 Port 边界切片 | 已完成 | 订单应用服务不再持有 `*Server`,改由 `orderRuntimePort` 接收平台、自动化、通知和运行时 Cookie 能力;`serverOrderRuntimeAdapter` 仅在 Server 装配边界桥接现有实现;订单行为、凭证锁和错误语义保持不变;Server 全量测试、架构门禁和中文注释门禁通过。订单 Port 仍位于 `internal/server`,repository 仍有基础设施适配职责,其他应用服务和 `sql.Tx`/`db.*` 全面隔离尚未完成 |
|
||||
| 2026-08-15 | P1 订单 Repository Port 迁移切片 | 已完成 | 将 `orderRepository` 从 `internal/server` 迁移为 `internal/application/orders.Repository`;应用 Port 只暴露领域模型、`Writer`/`UnitOfWork`、凭证协调和平台运行视图,不出现 `sql.Tx`、`db.*`、HTTP 或 Server 类型;Server 仅保留 `storeOrderRepository` 基础设施适配器;订单全量测试、架构门禁和中文注释门禁通过。订单运行时 Port 仍依赖 Server 适配边界,其他应用服务及事务/批量治理仍未完成 |
|
||||
@@ -0,0 +1,34 @@
|
||||
package orders
|
||||
|
||||
import "context"
|
||||
|
||||
// Repository 定义订单用例所需的持久化、凭证锁和平台运行视图能力。
|
||||
// 实现由基础设施适配器提供,本包不依赖数据库、HTTP 或 Server。
|
||||
type Repository interface {
|
||||
// ExistsOwned 判断账号是否归属于用户。
|
||||
ExistsOwned(ctx context.Context, userID int64, cookieID string) (bool, error)
|
||||
// ListOwnedIDs 返回用户拥有的账号 ID。
|
||||
ListOwnedIDs(ctx context.Context, userID int64) ([]string, error)
|
||||
// ListOrdersForUser 查询用户范围内的订单列表。
|
||||
ListOrdersForUser(ctx context.Context, filter ListFilter) ([]OrderRow, int, error)
|
||||
// GetOrder 查询单个订单。
|
||||
GetOrder(ctx context.Context, orderID string) (*Order, error)
|
||||
// GetItem 查询账号下的商品信息。
|
||||
GetItem(ctx context.Context, cookieID, itemID string) (*ItemInfo, error)
|
||||
// SoftDeleteOrder 逻辑删除订单。
|
||||
SoftDeleteOrder(ctx context.Context, orderID string) (bool, error)
|
||||
// WithTransaction 在订单写入用例中执行单个事务。
|
||||
WithTransaction(ctx context.Context, work func(Writer) error) error
|
||||
// UpsertOrder 写入订单。
|
||||
UpsertOrder(ctx context.Context, orderID string, options UpsertOptions) error
|
||||
// LockCredentials 串行化账号凭证状态变更。
|
||||
LockCredentials(cookieID string) func()
|
||||
// LoadCookiePlatformDetail 读取订单平台请求需要的最小账号视图。
|
||||
LoadCookiePlatformDetail(ctx context.Context, cookieID string) (*PlatformRuntimeData, error)
|
||||
// UpdateRenewalCookie 更新账号续期 Cookie 和 metadata。
|
||||
UpdateRenewalCookie(ctx context.Context, cookieID, value, metadata string, at int64) error
|
||||
// SoftDeleteMissingOrders 删除账号下远端已不存在的订单。
|
||||
SoftDeleteMissingOrders(ctx context.Context, cookieID string, activeIDs map[string]struct{}) (int, error)
|
||||
// ListOrdersByCookiePage 分页读取账号订单。
|
||||
ListOrdersByCookiePage(ctx context.Context, cookieID string, limit, offset int) ([]OrderRow, error)
|
||||
}
|
||||
@@ -7,36 +7,6 @@ import (
|
||||
"xianyu-go/internal/db"
|
||||
)
|
||||
|
||||
// orderRepository 定义订单应用服务执行订单、商品、归属、事务和凭证锁操作所需的最小能力。
|
||||
type orderRepository interface {
|
||||
// ExistsOwned 判断账号是否归属于用户。
|
||||
ExistsOwned(ctx context.Context, userID int64, cookieID string) (bool, error)
|
||||
// ListOwnedIDs 返回用户拥有的账号 ID。
|
||||
ListOwnedIDs(ctx context.Context, userID int64) ([]string, error)
|
||||
// ListOrdersForUser 查询用户范围内的订单列表。
|
||||
ListOrdersForUser(ctx context.Context, filter orderapp.ListFilter) ([]orderapp.OrderRow, int, error)
|
||||
// GetOrder 查询单个订单。
|
||||
GetOrder(ctx context.Context, orderID string) (*orderapp.Order, error)
|
||||
// GetItem 查询账号下的商品信息。
|
||||
GetItem(ctx context.Context, cookieID, itemID string) (*orderapp.ItemInfo, error)
|
||||
// SoftDeleteOrder 逻辑删除订单。
|
||||
SoftDeleteOrder(ctx context.Context, orderID string) (bool, error)
|
||||
// WithTransaction 在应用层 Writer 中执行订单持久化操作。
|
||||
WithTransaction(ctx context.Context, work func(orderapp.Writer) error) error
|
||||
// UpsertOrder 写入订单。
|
||||
UpsertOrder(ctx context.Context, orderID string, opts orderapp.UpsertOptions) error
|
||||
// LockCredentials 串行化账号凭证状态变更。
|
||||
LockCredentials(cookieID string) func()
|
||||
// LoadCookiePlatformDetail 读取账号平台凭证详情。
|
||||
LoadCookiePlatformDetail(ctx context.Context, cookieID string) (*orderapp.PlatformRuntimeData, error)
|
||||
// UpdateRenewalCookie 更新账号续期 Cookie 和 metadata。
|
||||
UpdateRenewalCookie(ctx context.Context, cookieID, value, metadata string, at int64) error
|
||||
// SoftDeleteMissingOrders 删除账号下远端已不存在的订单。
|
||||
SoftDeleteMissingOrders(ctx context.Context, cookieID string, activeIDs map[string]struct{}) (int, error)
|
||||
// ListOrdersByCookiePage 分页读取账号订单。
|
||||
ListOrdersByCookiePage(ctx context.Context, cookieID string, limit, offset int) ([]orderapp.OrderRow, error)
|
||||
}
|
||||
|
||||
// storeOrderRepository 将完整 Store 适配为订单应用服务窄 repository。
|
||||
type storeOrderRepository struct {
|
||||
// store 保存数据库聚合入口,仅在适配器内部使用。
|
||||
@@ -265,7 +235,7 @@ func (r storeOrderRepository) ListOrdersByCookiePage(ctx context.Context, cookie
|
||||
}
|
||||
|
||||
// newStoreOrderRepository 从完整 Store 构造订单应用服务窄 repository。
|
||||
func newStoreOrderRepository(store *db.Store) orderRepository {
|
||||
func newStoreOrderRepository(store *db.Store) orderapp.Repository {
|
||||
if store == nil || store.Cookies == nil || store.Orders == nil || store.Items == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -273,6 +243,6 @@ func newStoreOrderRepository(store *db.Store) orderRepository {
|
||||
}
|
||||
|
||||
// 确保 Store 适配器始终覆盖订单应用服务所需的全部能力。
|
||||
var _ orderRepository = storeOrderRepository{}
|
||||
var _ orderapp.Repository = storeOrderRepository{}
|
||||
var _ orderapp.UnitOfWork = storeOrderRepository{}
|
||||
var _ orderapp.Writer = storeOrderWriter{}
|
||||
@@ -134,8 +134,8 @@ func (a serverOrderRuntimeAdapter) logger() *slog.Logger {
|
||||
type orderApplicationService struct {
|
||||
// server 是订单运行时 Port,名称保留以降低本次迁移的调用面。
|
||||
server orderRuntimePort
|
||||
// repository 提供订单用例所需的最小持久化与凭证锁能力。
|
||||
repository orderRepository
|
||||
// repository 提供订单用例所需的应用层持久化与凭证锁 Port。
|
||||
repository orderapp.Repository
|
||||
}
|
||||
|
||||
// errOrderDetailUnsupported 保存err订单DetailUnsupported,供当前处理流程使用
|
||||
|
||||
Reference in new issue
Block a user