update frontend codes

This commit is contained in:
Wenkai Yin 2017-03-24 15:02:46 +08:00
parent d83554013b
commit 5c4808bf93
6 changed files with 84 additions and 71 deletions

View File

@ -438,64 +438,6 @@ paths:
description: Project ID does not exist.
500:
description: Unexpected internal errors.
/projects/{project_id}/repositories:
get:
summary: Get repositories accompany with relevant project and repo name.
description: |
This endpoint let user search repositories accompanying with relevant project ID and repo name.
parameters:
- name: project_id
in: path
type: integer
format: int32
required: true
description: Relevant project ID.
- name: detail
in: query
type: boolean
required: false
description: Get detail info or not.
- name: q
in: query
type: string
required: false
description: Repo name for filtering results.
- name: page
in: query
type: integer
format: int32
required: false
description: The page nubmer, default is 1.
- name: page_size
in: query
type: integer
format: int32
required: false
description: The size of per page, default is 10, maximum is 100.
tags:
- Products
responses:
200:
description: If detail is false, the response body is a string array which contains the names of repositories, or the response body contains an object array as described in schema.
schema:
type: array
items:
$ref: '#/definitions/Repository'
headers:
X-Total-Count:
description: The total count of repositories
type: integer
Link:
description: Link refers to the previous page and next page
type: string
400:
description: Invalid project ID.
403:
description: Project is not public or current user is irrelevant to the repository.
404:
description: Project ID does not exist.
500:
description: Unexpected internal errors.
/statistics:
get:
summary: Get projects number and repositories number relevant to the user
@ -702,6 +644,64 @@ paths:
description: User ID does not exist.
500:
description: Unexpected internal errors.
/repositories:
get:
summary: Get repositories accompany with relevant project and repo name.
description: |
This endpoint let user search repositories accompanying with relevant project ID and repo name.
parameters:
- name: project_id
in: query
type: integer
format: int32
required: true
description: Relevant project ID.
- name: detail
in: query
type: boolean
required: false
description: Get detail info or not.
- name: q
in: query
type: string
required: false
description: Repo name for filtering results.
- name: page
in: query
type: integer
format: int32
required: false
description: The page nubmer, default is 1.
- name: page_size
in: query
type: integer
format: int32
required: false
description: The size of per page, default is 10, maximum is 100.
tags:
- Products
responses:
200:
description: If detail is false, the response body is a string array which contains the names of repositories, or the response body contains an object array as described in schema.
schema:
type: array
items:
$ref: '#/definitions/Repository'
headers:
X-Total-Count:
description: The total count of repositories
type: integer
Link:
description: Link refers to the previous page and next page
type: string
400:
description: Invalid project ID.
403:
description: Project is not public or current user is irrelevant to the repository.
404:
description: Project ID does not exist.
500:
description: Unexpected internal errors.
/repositories/{repo_name}/tags/{tag}:
delete:
summary: Delete a tag in a repository.

View File

@ -82,7 +82,7 @@ func init() {
beego.Router("/api/projects/:id/publicity", &ProjectAPI{}, "put:ToggleProjectPublic")
beego.Router("/api/projects/:id([0-9]+)/logs/filter", &ProjectAPI{}, "post:FilterAccessLog")
beego.Router("/api/projects/:pid([0-9]+)/members/?:mid", &ProjectMemberAPI{}, "get:Get;post:Post;delete:Delete;put:Put")
beego.Router("/api/projects/:id([0-9]+)/repositories", &RepositoryAPI{}, "get:Get")
beego.Router("/api/repositories", &RepositoryAPI{})
beego.Router("/api/statistics", &StatisticAPI{})
beego.Router("/api/users/?:id", &UserAPI{})
beego.Router("/api/logs", &LogAPI{})
@ -463,16 +463,18 @@ func (a testapi) GetRepos(authInfo usrInfo, projectID,
keyword, detail string) (int, interface{}, error) {
_sling := sling.New().Get(a.basePath)
path := fmt.Sprintf("/api/projects/%s/repositories", projectID)
path := "/api/repositories/"
_sling = _sling.Path(path)
type QueryParams struct {
ProjectID string `url:"project_id"`
Detail string `url:"detail"`
Keyword string `url:"q"`
}
_sling = _sling.QueryStruct(&QueryParams{
ProjectID: projectID,
Detail: detail,
Keyword: keyword,
})

View File

@ -70,8 +70,8 @@ type manifestResp struct {
// Get ...
func (ra *RepositoryAPI) Get() {
projectID, err := ra.GetInt64(":id")
if err != nil {
projectID, err := ra.GetInt64("project_id")
if err != nil || projectID <= 0 {
ra.CustomAbort(http.StatusBadRequest, "invalid project_id")
}

View File

@ -60,6 +60,17 @@ func TestGetRepos(t *testing.T) {
}
}
//-------------------case 4 : response code = 400------------------------//
fmt.Println("case 4 : response code = 400,invalid project_id")
projectID = "ccc"
httpStatusCode, _, err = apiTest.GetRepos(*admin, projectID, keyword, detail)
if err != nil {
t.Error("Error whihle get repos by projectID", err.Error())
t.Log(err)
} else {
assert.Equal(int(400), httpStatusCode, "httpStatusCode should be 400")
}
fmt.Printf("\n")
}

View File

@ -66,11 +66,11 @@ func initRouters() {
beego.Router("/api/projects/:id([0-9]+)", &api.ProjectAPI{})
beego.Router("/api/projects/:id([0-9]+)/publicity", &api.ProjectAPI{}, "put:ToggleProjectPublic")
beego.Router("/api/projects/:id([0-9]+)/logs/filter", &api.ProjectAPI{}, "post:FilterAccessLog")
beego.Router("/api/projects/:id([0-9]+)/repositories", &api.RepositoryAPI{}, "get:Get")
beego.Router("/api/statistics", &api.StatisticAPI{})
beego.Router("/api/users/?:id", &api.UserAPI{})
beego.Router("/api/users/:id([0-9]+)/password", &api.UserAPI{}, "put:ChangePassword")
beego.Router("/api/internal/syncregistry", &api.InternalAPI{}, "post:SyncRegistry")
beego.Router("/api/repositories", &api.RepositoryAPI{})
beego.Router("/api/repositories/*/tags/?:tag", &api.RepositoryAPI{}, "delete:Delete")
beego.Router("/api/repositories/*/tags", &api.RepositoryAPI{}, "get:GetTags")
beego.Router("/api/repositories/*/tags/:tag/manifest", &api.RepositoryAPI{}, "get:GetManifests")

View File

@ -27,14 +27,14 @@ export class RepositoryService {
listTags(repoName: string): Observable<Tag[]> {
return this.http
.get(`/api/repositories/tags?repo_name=${repoName}&detail=1`)
.get(`/api/repositories/${repoName}/tags?detail=1`)
.map(response=>response.json())
.catch(error=>Observable.throw(error));
}
listNotarySignatures(repoName: string): Observable<VerifiedSignature[]> {
return this.http
.get(`/api/repositories/signatures?repo_name=${repoName}`)
.get(`/api/repositories/${repoName}/signatures`)
.map(response=>response.json())
.catch(error=>Observable.throw(error));
}
@ -64,7 +64,7 @@ export class RepositoryService {
deleteRepository(repoName: string): Observable<any> {
console.log('Delete repository with repo name:' + repoName);
return this.http
.delete(`/api/repositories?repo_name=${repoName}`)
.delete(`/api/repositories/${repoName}/tags`)
.map(response=>response.status)
.catch(error=>Observable.throw(error));
}
@ -72,7 +72,7 @@ export class RepositoryService {
deleteRepoByTag(repoName: string, tag: string): Observable<any> {
console.log('Delete repository with repo name:' + repoName + ', tag:' + tag);
return this.http
.delete(`/api/repositories?repo_name=${repoName}&tag=${tag}`)
.delete(`/api/repositories/${repoName}/tags/${tag}`)
.map(response=>response.status)
.catch(error=>Observable.throw(error));
}