u
This commit is contained in:
1 parent
cb4562361a
commit
b38583a9fe
11 files changed
+174
-85
No files matched your search
@@ -87,7 +87,7 @@ func RegisterDefault(ctx context.Context, c *app.RequestContext) {
|
||||
}
|
||||
|
||||
// 初始化用户分类
|
||||
err = initMoneyCategoryTx(ctx, tx, params.ID)
|
||||
err = InitMoneyCategoryTx(ctx, tx, params.ID)
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
@@ -97,8 +97,15 @@ func RegisterDefault(ctx context.Context, c *app.RequestContext) {
|
||||
response.Success(c).Message("注册成功").Send()
|
||||
}
|
||||
|
||||
func initMoneyCategoryTx(ctx context.Context, tx pgx.Tx, userId int64) error {
|
||||
sysCategories, err := db.Queries.ListMoneySysCategory(ctx)
|
||||
func InitMoneyCategoryTx(
|
||||
ctx context.Context,
|
||||
tx pgx.Tx,
|
||||
userId int64,
|
||||
) error {
|
||||
|
||||
q := db.Queries.WithTx(tx)
|
||||
|
||||
sysCategories, err := q.ListMoneySysCategory(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -118,9 +125,12 @@ func initMoneyCategoryTx(ctx context.Context, tx pgx.Tx, userId int64) error {
|
||||
})
|
||||
}
|
||||
|
||||
_, err = db.Queries.WithTx(tx).BatchInsertMoneyUserCategories(ctx, userCategories)
|
||||
// ⚠️ 注意:这里是 DeleteMoneyCategoryByUserId,不是 ById(你代码里疑似写错)
|
||||
if err := q.DeleteMoneyCategoryByUserId(ctx, userId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if _, err := q.BatchInsertMoneyUserCategories(ctx, userCategories); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func DeleteUserMoneyCategory(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.Queries.DeleteUserMoneyCategoryById(ctx, req.Id)
|
||||
err = db.Queries.DeleteMoneyCategoryById(ctx, req.Id)
|
||||
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
|
||||
Reference in new issue
Block a user