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)
|
||||
|
||||
@@ -7,7 +7,7 @@ SELECT *
|
||||
FROM money_user_category
|
||||
WHERE user_id = $1;
|
||||
|
||||
-- name: DeleteUserMoneyCategoryById :exec
|
||||
-- name: DeleteMoneyCategoryById :exec
|
||||
DELETE FROM money_user_category
|
||||
WHERE id = $1;
|
||||
|
||||
@@ -15,3 +15,7 @@ WHERE id = $1;
|
||||
UPDATE money_user_category
|
||||
SET sort_number = $2
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: DeleteMoneyCategoryByUserId :exec
|
||||
DELETE FROM money_user_category
|
||||
WHERE user_id = $1;
|
||||
@@ -18,13 +18,23 @@ type BatchInsertMoneyUserCategoriesParams struct {
|
||||
SortNumber int32
|
||||
}
|
||||
|
||||
const deleteUserMoneyCategoryById = `-- name: DeleteUserMoneyCategoryById :exec
|
||||
const deleteMoneyCategoryById = `-- name: DeleteMoneyCategoryById :exec
|
||||
DELETE FROM money_user_category
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUserMoneyCategoryById(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserMoneyCategoryById, id)
|
||||
func (q *Queries) DeleteMoneyCategoryById(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteMoneyCategoryById, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteMoneyCategoryByUserId = `-- name: DeleteMoneyCategoryByUserId :exec
|
||||
DELETE FROM money_user_category
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteMoneyCategoryByUserId(ctx context.Context, userID int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteMoneyCategoryByUserId, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user