基础架构
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// CreateWalletCommand 创建钱包命令
|
||||
type CreateWalletCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
}
|
||||
|
||||
// UpdateWalletCommand 更新钱包命令
|
||||
type UpdateWalletCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
Balance decimal.Decimal `json:"balance"`
|
||||
IsActive *bool `json:"is_active"`
|
||||
}
|
||||
|
||||
// RechargeWalletCommand 充值钱包命令
|
||||
type RechargeWalletCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
Amount decimal.Decimal `json:"amount" binding:"required"`
|
||||
}
|
||||
|
||||
// RechargeCommand 充值命令
|
||||
type RechargeCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
Amount decimal.Decimal `json:"amount" binding:"required"`
|
||||
}
|
||||
|
||||
// WithdrawWalletCommand 提现钱包命令
|
||||
type WithdrawWalletCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
Amount decimal.Decimal `json:"amount" binding:"required"`
|
||||
}
|
||||
|
||||
// WithdrawCommand 提现命令
|
||||
type WithdrawCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
Amount decimal.Decimal `json:"amount" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateUserSecretsCommand 创建用户密钥命令
|
||||
type CreateUserSecretsCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
}
|
||||
|
||||
// RegenerateAccessKeyCommand 重新生成访问密钥命令
|
||||
type RegenerateAccessKeyCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
}
|
||||
|
||||
// DeactivateUserSecretsCommand 停用用户密钥命令
|
||||
type DeactivateUserSecretsCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
}
|
||||
|
||||
// WalletTransactionCommand 钱包交易命令
|
||||
type WalletTransactionCommand struct {
|
||||
UserID string `json:"user_id" binding:"required"`
|
||||
FromUserID string `json:"from_user_id" binding:"required"`
|
||||
ToUserID string `json:"to_user_id" binding:"required"`
|
||||
Amount decimal.Decimal `json:"amount" binding:"required"`
|
||||
Notes string `json:"notes"`
|
||||
}
|
||||
21
internal/application/finance/dto/queries/finance_queries.go
Normal file
21
internal/application/finance/dto/queries/finance_queries.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package queries
|
||||
|
||||
// GetWalletInfoQuery 获取钱包信息查询
|
||||
type GetWalletInfoQuery struct {
|
||||
UserID string `form:"user_id" binding:"required"`
|
||||
}
|
||||
|
||||
// GetWalletQuery 获取钱包查询
|
||||
type GetWalletQuery struct {
|
||||
UserID string `form:"user_id" binding:"required"`
|
||||
}
|
||||
|
||||
// GetWalletStatsQuery 获取钱包统计查询
|
||||
type GetWalletStatsQuery struct {
|
||||
UserID string `form:"user_id" binding:"required"`
|
||||
}
|
||||
|
||||
// GetUserSecretsQuery 获取用户密钥查询
|
||||
type GetUserSecretsQuery struct {
|
||||
UserID string `form:"user_id" binding:"required"`
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// WalletResponse 钱包响应
|
||||
type WalletResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
IsActive bool `json:"is_active"`
|
||||
Balance decimal.Decimal `json:"balance"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TransactionResponse 交易响应
|
||||
type TransactionResponse struct {
|
||||
TransactionID string `json:"transaction_id"`
|
||||
FromUserID string `json:"from_user_id"`
|
||||
ToUserID string `json:"to_user_id"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
FromBalance decimal.Decimal `json:"from_balance"`
|
||||
ToBalance decimal.Decimal `json:"to_balance"`
|
||||
Notes string `json:"notes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// UserSecretsResponse 用户密钥响应
|
||||
type UserSecretsResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
AccessID string `json:"access_id"`
|
||||
AccessKey string `json:"access_key"`
|
||||
IsActive bool `json:"is_active"`
|
||||
LastUsedAt *time.Time `json:"last_used_at"`
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// WalletStatsResponse 钱包统计响应
|
||||
type WalletStatsResponse struct {
|
||||
TotalWallets int64 `json:"total_wallets"`
|
||||
ActiveWallets int64 `json:"active_wallets"`
|
||||
TotalBalance decimal.Decimal `json:"total_balance"`
|
||||
TodayTransactions int64 `json:"today_transactions"`
|
||||
TodayVolume decimal.Decimal `json:"today_volume"`
|
||||
}
|
||||
24
internal/application/finance/finance_application_service.go
Normal file
24
internal/application/finance/finance_application_service.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package finance
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/application/finance/dto/commands"
|
||||
"tyapi-server/internal/application/finance/dto/queries"
|
||||
"tyapi-server/internal/application/finance/dto/responses"
|
||||
)
|
||||
|
||||
// FinanceApplicationService 财务应用服务接口
|
||||
type FinanceApplicationService interface {
|
||||
CreateWallet(ctx context.Context, cmd *commands.CreateWalletCommand) (*responses.WalletResponse, error)
|
||||
GetWallet(ctx context.Context, query *queries.GetWalletInfoQuery) (*responses.WalletResponse, error)
|
||||
UpdateWallet(ctx context.Context, cmd *commands.UpdateWalletCommand) error
|
||||
Recharge(ctx context.Context, cmd *commands.RechargeWalletCommand) (*responses.TransactionResponse, error)
|
||||
Withdraw(ctx context.Context, cmd *commands.WithdrawWalletCommand) (*responses.TransactionResponse, error)
|
||||
CreateUserSecrets(ctx context.Context, cmd *commands.CreateUserSecretsCommand) (*responses.UserSecretsResponse, error)
|
||||
GetUserSecrets(ctx context.Context, query *queries.GetUserSecretsQuery) (*responses.UserSecretsResponse, error)
|
||||
RegenerateAccessKey(ctx context.Context, cmd *commands.RegenerateAccessKeyCommand) (*responses.UserSecretsResponse, error)
|
||||
DeactivateUserSecrets(ctx context.Context, cmd *commands.DeactivateUserSecretsCommand) error
|
||||
WalletTransaction(ctx context.Context, cmd *commands.WalletTransactionCommand) (*responses.TransactionResponse, error)
|
||||
GetWalletStats(ctx context.Context) (*responses.WalletStatsResponse, error)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package finance
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"tyapi-server/internal/application/finance/dto/commands"
|
||||
"tyapi-server/internal/application/finance/dto/queries"
|
||||
"tyapi-server/internal/application/finance/dto/responses"
|
||||
"tyapi-server/internal/domains/finance/repositories"
|
||||
)
|
||||
|
||||
// FinanceApplicationServiceImpl 财务应用服务实现
|
||||
type FinanceApplicationServiceImpl struct {
|
||||
walletRepo repositories.WalletRepository
|
||||
userSecretsRepo repositories.UserSecretsRepository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewFinanceApplicationService 创建财务应用服务
|
||||
func NewFinanceApplicationService(
|
||||
walletRepo repositories.WalletRepository,
|
||||
userSecretsRepo repositories.UserSecretsRepository,
|
||||
logger *zap.Logger,
|
||||
) FinanceApplicationService {
|
||||
return &FinanceApplicationServiceImpl{
|
||||
walletRepo: walletRepo,
|
||||
userSecretsRepo: userSecretsRepo,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) CreateWallet(ctx context.Context, cmd *commands.CreateWalletCommand) (*responses.WalletResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) GetWallet(ctx context.Context, query *queries.GetWalletInfoQuery) (*responses.WalletResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) UpdateWallet(ctx context.Context, cmd *commands.UpdateWalletCommand) error {
|
||||
// ... implementation from old service
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) Recharge(ctx context.Context, cmd *commands.RechargeWalletCommand) (*responses.TransactionResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) Withdraw(ctx context.Context, cmd *commands.WithdrawWalletCommand) (*responses.TransactionResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) CreateUserSecrets(ctx context.Context, cmd *commands.CreateUserSecretsCommand) (*responses.UserSecretsResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) GetUserSecrets(ctx context.Context, query *queries.GetUserSecretsQuery) (*responses.UserSecretsResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) RegenerateAccessKey(ctx context.Context, cmd *commands.RegenerateAccessKeyCommand) (*responses.UserSecretsResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) DeactivateUserSecrets(ctx context.Context, cmd *commands.DeactivateUserSecretsCommand) error {
|
||||
// ... implementation from old service
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) WalletTransaction(ctx context.Context, cmd *commands.WalletTransactionCommand) (*responses.TransactionResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *FinanceApplicationServiceImpl) GetWalletStats(ctx context.Context) (*responses.WalletStatsResponse, error) {
|
||||
// ... implementation from old service
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
Reference in New Issue
Block a user