mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 23:33:15 -05:00
Validate before returning
This commit is contained in:
parent
35d3fc199c
commit
653ced5596
1 changed files with 10 additions and 2 deletions
|
@ -15,13 +15,21 @@ func init() {
|
||||||
db.RegisterModel(new(FederatedRepo))
|
db.RegisterModel(new(FederatedRepo))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: Validate before returning
|
|
||||||
func FindFederatedRepoByRepoID(ctx context.Context, repoId int64) ([]*FederatedRepo, error) {
|
func FindFederatedRepoByRepoID(ctx context.Context, repoId int64) ([]*FederatedRepo, error) {
|
||||||
maxFederatedRepos := 10
|
maxFederatedRepos := 10
|
||||||
sess := db.GetEngine(ctx).Where("repo_id=?", repoId)
|
sess := db.GetEngine(ctx).Where("repo_id=?", repoId)
|
||||||
sess = sess.Limit(maxFederatedRepos, 0)
|
sess = sess.Limit(maxFederatedRepos, 0)
|
||||||
federatedRepoList := make([]*FederatedRepo, 0, maxFederatedRepos)
|
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 {
|
func StoreFederatedRepos(ctx context.Context, localRepoId int64, federatedRepoList []*FederatedRepo) error {
|
||||||
|
|
Loading…
Reference in a new issue