diff --git a/api/search.go b/api/search.go index a6d2a4ce2..4da0068c0 100644 --- a/api/search.go +++ b/api/search.go @@ -68,7 +68,7 @@ func (s *SearchAPI) Get() { } } - projectSorter := &utils.ProjectSorter{Projects: projects} + projectSorter := &models.ProjectSorter{Projects: projects} sort.Sort(projectSorter) projectResult := []map[string]interface{}{} for _, p := range projects { diff --git a/models/project.go b/models/project.go index e16f0ce5f..0105f6a79 100644 --- a/models/project.go +++ b/models/project.go @@ -37,3 +37,23 @@ type Project struct { Role int `json:"current_user_role_id"` RepoCount int `json:"repo_count"` } + +// ProjectSorter holds an array of projects +type ProjectSorter struct { + Projects []Project +} + +// Len returns the length of array in ProjectSorter +func (ps *ProjectSorter) Len() int { + return len(ps.Projects) +} + +// Less defines the comparison rules of project +func (ps *ProjectSorter) Less(i, j int) bool { + return ps.Projects[i].Name < ps.Projects[j].Name +} + +// Swap swaps the position of i and j +func (ps *ProjectSorter) Swap(i, j int) { + ps.Projects[i], ps.Projects[j] = ps.Projects[j], ps.Projects[i] +} diff --git a/utils/utils.go b/utils/utils.go index 3a7d693e3..653e5409c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -18,8 +18,6 @@ package utils import ( "net/url" "strings" - - "github.com/vmware/harbor/models" ) // Repository holds information about repository @@ -35,26 +33,6 @@ func (r *Repository) GetProject() string { return r.Name[0:strings.LastIndex(r.Name, "/")] } -// ProjectSorter holds an array of projects -type ProjectSorter struct { - Projects []models.Project -} - -// Len returns the length of array in ProjectSorter -func (ps *ProjectSorter) Len() int { - return len(ps.Projects) -} - -// Less defines the comparison rules of project -func (ps *ProjectSorter) Less(i, j int) bool { - return ps.Projects[i].Name < ps.Projects[j].Name -} - -// Swap swaps the position of i and j -func (ps *ProjectSorter) Swap(i, j int) { - ps.Projects[i], ps.Projects[j] = ps.Projects[j], ps.Projects[i] -} - // FormatEndpoint formats endpoint func FormatEndpoint(endpoint string) string { endpoint = strings.TrimSpace(endpoint)