From 653ced55965b7ef111fa381030864b7fb509454b Mon Sep 17 00:00:00 2001 From: erik Date: Mon, 25 Mar 2024 16:47:18 +0100 Subject: [PATCH] Validate before returning --- models/repo/repo_repository.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/models/repo/repo_repository.go b/models/repo/repo_repository.go index 74f74c55a0..f05c498607 100644 --- a/models/repo/repo_repository.go +++ b/models/repo/repo_repository.go @@ -15,13 +15,21 @@ func init() { db.RegisterModel(new(FederatedRepo)) } -// ToDo: Validate before returning func FindFederatedRepoByRepoID(ctx context.Context, repoId int64) ([]*FederatedRepo, error) { maxFederatedRepos := 10 sess := db.GetEngine(ctx).Where("repo_id=?", repoId) sess = sess.Limit(maxFederatedRepos, 0) federatedRepoList := make([]*FederatedRepo, 0, maxFederatedRepos) - return federatedRepoList, sess.Find(&federatedRepoList) + err := sess.Find(&federatedRepoList) + if err != nil { + return federatedRepoList, err + } + for _, federatedRepo := range federatedRepoList { + if res, err := validation.IsValid(*federatedRepo); !res { + return federatedRepoList, fmt.Errorf("FederationInfo is not valid: %v", err) + } + } + return federatedRepoList, nil } func StoreFederatedRepos(ctx context.Context, localRepoId int64, federatedRepoList []*FederatedRepo) error {