|
@ -4,6 +4,7 @@ import ( |
|
|
"context" |
|
|
"context" |
|
|
"database/sql" |
|
|
"database/sql" |
|
|
"errors" |
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
"git.aiterp.net/rpdata/api/database/postgres/psqlcore" |
|
|
"git.aiterp.net/rpdata/api/database/postgres/psqlcore" |
|
|
"git.aiterp.net/rpdata/api/internal/generate" |
|
|
"git.aiterp.net/rpdata/api/internal/generate" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
@ -255,7 +256,7 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error { |
|
|
|
|
|
|
|
|
err = q.MovePost(ctx, psqlcore.MovePostParams{ID: post.ID, Position: -1}) |
|
|
err = q.MovePost(ctx, psqlcore.MovePostParams{ID: post.ID, Position: -1}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
return fmt.Errorf("pre-delete move failed: %s", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{ |
|
|
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{ |
|
@ -264,17 +265,17 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error { |
|
|
FromPosition: int32(post.Position + 1), |
|
|
FromPosition: int32(post.Position + 1), |
|
|
}) |
|
|
}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
return fmt.Errorf("shift failed: %s", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = q.DeletePost(ctx, post.ID) |
|
|
err = q.DeletePost(ctx, post.ID) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
return fmt.Errorf("delete failed: %s", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = tx.Commit() |
|
|
err = tx.Commit() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
return fmt.Errorf("tx commit failed: %s", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID) |
|
|
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID) |
|
|