aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo/pushmirror.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/repo/pushmirror.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/repo/pushmirror.go')
-rw-r--r--models/repo/pushmirror.go22
1 files changed, 3 insertions, 19 deletions
diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go
index 61cf1849b0..24c58faf84 100644
--- a/models/repo/pushmirror.go
+++ b/models/repo/pushmirror.go
@@ -34,12 +34,13 @@ type PushMirror struct {
}
type PushMirrorOptions struct {
+ db.ListOptions
ID int64
RepoID int64
RemoteName string
}
-func (opts *PushMirrorOptions) toConds() builder.Cond {
+func (opts PushMirrorOptions) ToConds() builder.Cond {
cond := builder.NewCond()
if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
@@ -75,12 +76,6 @@ func (m *PushMirror) GetRemoteName() string {
return m.RemoteName
}
-// InsertPushMirror inserts a push-mirror to database
-func InsertPushMirror(ctx context.Context, m *PushMirror) error {
- _, err := db.GetEngine(ctx).Insert(m)
- return err
-}
-
// UpdatePushMirror updates the push-mirror
func UpdatePushMirror(ctx context.Context, m *PushMirror) error {
_, err := db.GetEngine(ctx).ID(m.ID).AllCols().Update(m)
@@ -95,23 +90,12 @@ func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error {
func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error {
if opts.RepoID > 0 {
- _, err := db.GetEngine(ctx).Where(opts.toConds()).Delete(&PushMirror{})
+ _, err := db.Delete[PushMirror](ctx, opts)
return err
}
return util.NewInvalidArgumentErrorf("repoID required and must be set")
}
-func GetPushMirror(ctx context.Context, opts PushMirrorOptions) (*PushMirror, error) {
- mirror := &PushMirror{}
- exist, err := db.GetEngine(ctx).Where(opts.toConds()).Get(mirror)
- if err != nil {
- return nil, err
- } else if !exist {
- return nil, ErrPushMirrorNotExist
- }
- return mirror, nil
-}
-
// GetPushMirrorsByRepoID returns push-mirror information of a repository.
func GetPushMirrorsByRepoID(ctx context.Context, repoID int64, listOptions db.ListOptions) ([]*PushMirror, int64, error) {
sess := db.GetEngine(ctx).Where("repo_id = ?", repoID)