From a0bd1bd9b484259c8fd7d269d240e5353cea2e6a Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Fri, 21 Feb 2020 16:35:26 +0800 Subject: [PATCH] ADD edit repository api --- README.md | 36 ++++++++++++++++++++++ app/controllers/repositories_controller.rb | 4 +++ app/views/repositories/edit.json.jbuilder | 7 +++++ config/routes.rb | 1 + 4 files changed, 48 insertions(+) create mode 100644 app/views/repositories/edit.json.jbuilder diff --git a/README.md b/README.md index 4181dd66c..f9708111c 100644 --- a/README.md +++ b/README.md @@ -451,6 +451,42 @@ curl -X GET http://localhost:3000/api/projects/3263 | jq ``` --- +#### 编辑仓库信息 +``` +GET /api/:login/:repo_identifier/edit.json +``` +*示例* +``` +curl -X GET http://localhost:3000/api/18816895620/mirror_demo/edit.json | jq +``` + +*返回参数说明:* + +|参数名|类型|说明| +-|-|- +|identifier |string |仓库标识 | +|project_id |int|项目id| +|project_name |string|项目名称| +|project_identifier |string|项目标识| +|project_description |string|项目简介| +|project_category_id |int|项目类别id| +|project_language_id |int|项目语言id| + + +返回值 +``` +{ + "identifier": "mirror_demo", + "project_id": 3263, + "project_name": "ni项目", + "project_identifier": "mirror_demo", + "project_description": "my first project mirror_demo", + "project_category_id": 1, + "project_language_id": 2 +} +``` +--- + #### 修改项目信息 ``` PATCH api/projects/:id diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 2e5d5cd67..abb891cc3 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,6 +1,7 @@ class RepositoriesController < ApplicationController include ApplicationHelper before_action :find_user, :find_repository, :authorizate! + before_action :require_login, only: %i[edit] def show @project = @repo.project @@ -43,6 +44,9 @@ class RepositoriesController < ApplicationController @tags = Gitea::Repository::Tags::ListService.new(@user, @repo.identifier).call end + def edit + end + private def authorizate! if @repo.hidden? && @repo.user != current_user diff --git a/app/views/repositories/edit.json.jbuilder b/app/views/repositories/edit.json.jbuilder new file mode 100644 index 000000000..1d1324cb3 --- /dev/null +++ b/app/views/repositories/edit.json.jbuilder @@ -0,0 +1,7 @@ +json.identifier @repo.identifier +json.project_id @repo&.project.id +json.project_name @repo&.project.name +json.project_identifier @repo.project.identifier +json.project_description @repo&.project.description +json.project_category_id @repo&.project.project_category_id +json.project_language_id @repo&.project.project_language_id diff --git a/config/routes.rb b/config/routes.rb index b119eb11e..6d7c9eac5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -161,6 +161,7 @@ Rails.application.routes.draw do end get '/:login/:repo_identifier', to: 'repositories#show' + get '/:login/:repo_identifier/edit', to: 'repositories#edit' resources :repositories, path: '/:login/:repo_identifier', only: [:index] do collection do get :entries