mirror of
https://github.com/goharbor/harbor
synced 2025-04-16 19:31:28 +00:00
change code according to review
This commit is contained in:
parent
ccbe297bba
commit
267152f8e6
|
@ -291,7 +291,23 @@ func (ra *RepositoryAPI) getUsername() (string, error) {
|
|||
|
||||
//GetTopTenRepos handles request GET /api/repositories/toprepos
|
||||
func (ra *RepositoryAPI) GetTopTenRepos() {
|
||||
repos, err := dao.GetTop10Repos()
|
||||
var err error
|
||||
var countNum int
|
||||
count := ra.GetString("count")
|
||||
if len(count) == 0 {
|
||||
countNum = 10
|
||||
} else {
|
||||
countNum, err = strconv.Atoi(count)
|
||||
if err != nil {
|
||||
log.Errorf("Get parameters error--count, err: %v", err)
|
||||
ra.CustomAbort(http.StatusBadRequest, "bad request of count")
|
||||
}
|
||||
if countNum <= 0 {
|
||||
log.Warning("count must be a positive integer")
|
||||
ra.CustomAbort(http.StatusBadRequest, "count is 0 or negative")
|
||||
}
|
||||
}
|
||||
repos, err := dao.GetTop10Repos(countNum)
|
||||
if err != nil {
|
||||
log.Errorf("error occured in get top 10 repos: %v", err)
|
||||
ra.CustomAbort(http.StatusInternalServerError, "internal server error")
|
||||
|
|
|
@ -149,12 +149,15 @@ func GetRecentLogs(userID, linesNum int, startTime, endTime string) ([]models.Ac
|
|||
}
|
||||
|
||||
//GetTop10Repos return top 10 accessed public repos
|
||||
func GetTop10Repos() ([]orm.ParamsList, error) {
|
||||
func GetTop10Repos(countNum int) ([]orm.ParamsList, error) {
|
||||
|
||||
o := GetOrmer()
|
||||
sql := "select log_id, access_log.user_id, access_log.project_id, repo_name, repo_tag, GUID, operation, op_time, COUNT(repo_name) as access_count from access_log left join project on access_log.project_id=project.project_id where project.public=1 and access_log.operation<>'create' group by repo_name order by access_count desc limit 10"
|
||||
|
||||
sql := "select log_id, access_log.user_id, access_log.project_id, repo_name, repo_tag, GUID, operation, op_time, COUNT(repo_name) as access_count from access_log left join project on access_log.project_id=project.project_id where project.public=1 and (access_log.operation = 'push' or access_log.operation = 'pull') group by repo_name order by access_count desc limit ? "
|
||||
queryParam := make([]interface{}, 1)
|
||||
queryParam = append(queryParam, countNum)
|
||||
var lists []orm.ParamsList
|
||||
_, err := o.Raw(sql).ValuesList(&lists)
|
||||
_, err := o.Raw(sql, queryParam).ValuesList(&lists)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func initRouters() {
|
|||
beego.Router("/api/repositories", &api.RepositoryAPI{})
|
||||
beego.Router("/api/repositories/tags", &api.RepositoryAPI{}, "get:GetTags")
|
||||
beego.Router("/api/repositories/manifests", &api.RepositoryAPI{}, "get:GetManifests")
|
||||
beego.Router("/api/repositories/toprepos", &api.RepositoryAPI{}, "get:GetTopTenRepos")
|
||||
beego.Router("/api/repositories/top", &api.RepositoryAPI{}, "get:GetTopTenRepos")
|
||||
beego.Router("api/logs", &api.LogAPI{})
|
||||
|
||||
//external service that hosted on harbor process:
|
||||
|
|
Loading…
Reference in New Issue
Block a user