Implement the API to get the specified repository

Implement the API to get the specified repository

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2020-02-25 12:02:50 +08:00
parent aa71fc43cf
commit bb3ff0d752
2 changed files with 58 additions and 12 deletions

View File

@ -58,6 +58,37 @@ paths:
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories/{repository_name}:
get:
summary: Get repository
description: Get the repository specified by name
tags:
- repository
operationId: getRepository
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/repositoryName'
- name: repository
in: body
description: The JSON object of repository.
required: true
schema:
$ref: '#/definitions/Repository'
responses:
'200':
description: Success
schema:
$ref: '#/definitions/Repository'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
put:
summary: Update repository
description: Update the repository specified by name

View File

@ -79,23 +79,38 @@ func (r *repositoryAPI) ListRepositories(ctx context.Context, params operation.L
}
var repos []*models.Repository
for _, repository := range repositories {
repo := repository.ToSwagger()
total, err := r.artCtl.Count(ctx, &q.Query{
Keywords: map[string]interface{}{
"RepositoryID": repo.ID,
},
})
if err != nil {
log.Errorf("failed to get the count of artifacts under the repository %s: %v",
repo.Name, err)
}
repo.ArtifactCount = total
repos = append(repos, repo)
repos = append(repos, r.assembleRepository(ctx, repository))
}
// TODO add link header
return operation.NewListRepositoriesOK().WithXTotalCount(total).WithLink("").WithPayload(repos)
}
func (r *repositoryAPI) GetRepository(ctx context.Context, params operation.GetRepositoryParams) middleware.Responder {
if err := r.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionList, rbac.ResourceRepository); err != nil {
return r.SendError(ctx, err)
}
repository, err := r.repoCtl.GetByName(ctx, fmt.Sprintf("%s/%s", params.ProjectName, params.RepositoryName))
if err != nil {
return r.SendError(ctx, err)
}
return operation.NewGetRepositoryOK().WithPayload(r.assembleRepository(ctx, repository))
}
func (r *repositoryAPI) assembleRepository(ctx context.Context, repository *cmodels.RepoRecord) *models.Repository {
repo := repository.ToSwagger()
total, err := r.artCtl.Count(ctx, &q.Query{
Keywords: map[string]interface{}{
"RepositoryID": repo.ID,
},
})
if err != nil {
log.Errorf("failed to get the count of artifacts under the repository %s: %v",
repo.Name, err)
}
repo.ArtifactCount = total
return repo
}
func (r *repositoryAPI) UpdateRepository(ctx context.Context, params operation.UpdateRepositoryParams) middleware.Responder {
if err := r.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionUpdate, rbac.ResourceRepository); err != nil {
return r.SendError(ctx, err)