mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +01:00
add a new func to reuse code
This commit is contained in:
parent
2cd1226ac8
commit
1f44e2aa8b
@ -218,31 +218,33 @@ func GetUserRelevantProjects(userID int, projectName string) ([]models.Project,
|
|||||||
|
|
||||||
//GetPublicProjects returns all public projects whose name like projectName
|
//GetPublicProjects returns all public projects whose name like projectName
|
||||||
func GetPublicProjects(projectName string) ([]models.Project, error) {
|
func GetPublicProjects(projectName string) ([]models.Project, error) {
|
||||||
o := orm.NewOrm()
|
publicProjects, err := getProjects(1, projectName)
|
||||||
var publicProjects []models.Project
|
|
||||||
sql := `select project_id, owner_id, creation_time, update_time, name, public
|
|
||||||
from project
|
|
||||||
where deleted = 0 and public=1`
|
|
||||||
queryParam := make([]interface{}, 1)
|
|
||||||
if len(projectName) > 0 {
|
|
||||||
sql += " and name like ? "
|
|
||||||
queryParam = append(queryParam, projectName)
|
|
||||||
}
|
|
||||||
sql += " order by name "
|
|
||||||
_, err := o.Raw(sql, queryParam).QueryRows(&publicProjects)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
return publicProjects, nil
|
return publicProjects, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllProjects returns all projects which are not deleted and name like projectName
|
// GetAllProjects returns all projects which are not deleted and name like projectName
|
||||||
func GetAllProjects(projectName string) ([]models.Project, error) {
|
func GetAllProjects(projectName string) ([]models.Project, error) {
|
||||||
|
allProjects, err := getProjects(0, projectName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return allProjects, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getProjects(public int, projectName string) ([]models.Project, error) {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
sql := `select project_id, owner_id, creation_time, update_time, name, public
|
sql := `select project_id, owner_id, creation_time, update_time, name, public
|
||||||
from project
|
from project
|
||||||
where deleted = 0`
|
where deleted = 0`
|
||||||
queryParam := make([]interface{}, 1)
|
queryParam := make([]interface{}, 1)
|
||||||
|
if public == 1 {
|
||||||
|
sql += "and public = ?"
|
||||||
|
queryParam = append(queryParam, public)
|
||||||
|
}
|
||||||
if len(projectName) > 0 {
|
if len(projectName) > 0 {
|
||||||
sql += " and name like ? "
|
sql += " and name like ? "
|
||||||
queryParam = append(queryParam, projectName)
|
queryParam = append(queryParam, projectName)
|
||||||
|
Loading…
Reference in New Issue
Block a user