aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/review.go
diff options
context:
space:
mode:
authordelvh <dev.lh@web.de>2023-12-25 21:25:29 +0100
committerGitHub <noreply@github.com>2023-12-25 21:25:29 +0100
commit778ad795fd4a19dc15723b59a846a250034c7c3a (patch)
tree8d64a21734517a9826655955d77cb0bcc187f784 /models/issues/review.go
parentb41925cee3d67a1fe546c7a219174e4a8b2302b7 (diff)
downloadgitea-778ad795fd4a19dc15723b59a846a250034c7c3a.tar.gz
gitea-778ad795fd4a19dc15723b59a846a250034c7c3a.zip
Refactor deletion (#28610)
Introduce the new generic deletion methods - `func DeleteByID[T any](ctx context.Context, id int64) (int64, error)` - `func DeleteByIDs[T any](ctx context.Context, ids ...int64) error` - `func Delete[T any](ctx context.Context, opts FindOptions) (int64, error)` So, we no longer need any specific deletion method and can just use the generic ones instead. Replacement of #28450 Closes #28450 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/issues/review.go')
-rw-r--r--models/issues/review.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/models/issues/review.go b/models/issues/review.go
index e2f65e369f..e06670c9a1 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -446,7 +446,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
continue
}
- if _, err := sess.ID(teamReviewRequest.ID).NoAutoCondition().Delete(teamReviewRequest); err != nil {
+ if _, err := db.DeleteByID[Review](ctx, teamReviewRequest.ID); err != nil {
return nil, nil, err
}
}
@@ -869,7 +869,6 @@ func DeleteReview(ctx context.Context, r *Review) error {
return err
}
defer committer.Close()
- sess := db.GetEngine(ctx)
if r.ID == 0 {
return fmt.Errorf("review is not allowed to be 0")
@@ -885,7 +884,7 @@ func DeleteReview(ctx context.Context, r *Review) error {
ReviewID: r.ID,
}
- if _, err := sess.Where(opts.ToConds()).Delete(new(Comment)); err != nil {
+ if _, err := db.Delete[Comment](ctx, opts); err != nil {
return err
}
@@ -895,7 +894,7 @@ func DeleteReview(ctx context.Context, r *Review) error {
ReviewID: r.ID,
}
- if _, err := sess.Where(opts.ToConds()).Delete(new(Comment)); err != nil {
+ if _, err := db.Delete[Comment](ctx, opts); err != nil {
return err
}
@@ -905,11 +904,11 @@ func DeleteReview(ctx context.Context, r *Review) error {
ReviewID: r.ID,
}
- if _, err := sess.Where(opts.ToConds()).Delete(new(Comment)); err != nil {
+ if _, err := db.Delete[Comment](ctx, opts); err != nil {
return err
}
- if _, err := sess.ID(r.ID).Delete(new(Review)); err != nil {
+ if _, err := db.DeleteByID[Review](ctx, r.ID); err != nil {
return err
}