This commit is contained in:
vipg
2025-11-17 18:10:40 +08:00
parent a47e544657
commit 44e2d7c1f6
2 changed files with 31 additions and 11 deletions

View File

@@ -1,27 +1,47 @@
curl -X POST "127.0.0.1:20000/user/register" \ curl -X POST "https://api.fishestlife.com/user/register" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"account": "test", "account": "test",
"password": "test12341234" "password": "test12341234"
}' }'
--- ---
# 创建美国 # 创建美国
curl -X POST "127.0.0.1:20000/country/create" \ curl -X POST "https://api.fishestlife.com/country/create" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"name": "美国", "code": "US"}' -d '{"name": "美国", "code": "US"}'
# 创建中国 # 创建中国
curl -X POST "127.0.0.1:20000/country/create" \ curl -X POST "https://api.fishestlife.com/country/create" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"name": "中国", "code": "CN"}' -d '{"name": "中国", "code": "CN"}'
# 创建日本 # 创建日本
curl -X POST "127.0.0.1:20000/country/create" \ curl -X POST "https://api.fishestlife.com/country/create" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"name": "日本", "code": "JP"}' -d '{"name": "日本", "code": "JP"}'
# 创建香港 # 创建香港
curl -X POST "127.0.0.1:20000/country/create" \ curl -X POST "https://api.fishestlife.com/country/create" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"name": "香港", "code": "HK"}' -d '{"name": "香港", "code": "HK"}'
--- ---
# 创建美国
curl -X POST "https://api.fishestlife.com/currency/create" \
-H "Content-Type: application/json" \
-d '{"name": "美元", "code": "USD"}'
# 创建中国
curl -X POST "https://api.fishestlife.com/currency/create" \
-H "Content-Type: application/json" \
-d '{"name": "人民币", "code": "CNY"}'
# 创建日本
curl -X POST "https://api.fishestlife.com/currency/create" \
-H "Content-Type: application/json" \
-d '{"name": "日元", "code": "JPY"}'
# 创建香港
curl -X POST "https://api.fishestlife.com/currency/create" \
-H "Content-Type: application/json" \
-d '{"name": "港币", "code": "HKD"}'
---

View File

@@ -129,10 +129,10 @@ func CreateHandler(c *gin.Context) {
) )
// 2. 插入国家名称到name表与currency_id关联 // 2. 插入国家名称到name表与currency_id关联
_, err = tx.Exec("INSERT INTO name (currency_id, name) VALUES ($1, $2)", currencyID, req.Name) _, err = tx.Exec("INSERT INTO currency_name (currency_id, name) VALUES ($1, $2)", currencyID, req.Name)
if err != nil { if err != nil {
tx.Rollback() // 操作失败,回滚事务 tx.Rollback() // 操作失败,回滚事务
zap.L().Error("❌ name表插入失败", zap.L().Error("❌ currency_name表插入失败",
zap.String("req_id", reqID), zap.String("req_id", reqID),
zap.String("currency_id", currencyID), zap.String("currency_id", currencyID),
zap.Error(err), zap.Error(err),
@@ -145,10 +145,10 @@ func CreateHandler(c *gin.Context) {
} }
// 3. 插入国家代码到code表与currency_id关联 // 3. 插入国家代码到code表与currency_id关联
_, err = tx.Exec("INSERT INTO code (currency_id, code) VALUES ($1, $2)", currencyID, req.Code) _, err = tx.Exec("INSERT INTO currency_code (currency_id, code) VALUES ($1, $2)", currencyID, req.Code)
if err != nil { if err != nil {
tx.Rollback() // 操作失败,回滚事务 tx.Rollback() // 操作失败,回滚事务
zap.L().Error("❌ code表插入失败", zap.L().Error("❌ currency_code表插入失败",
zap.String("req_id", reqID), zap.String("req_id", reqID),
zap.String("currency_id", currencyID), zap.String("currency_id", currencyID),
zap.Error(err), zap.Error(err),