From ddb3ff5f5b8c419f5737d3b79b4b25c62ce58d42 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 14 Jan 2020 16:06:25 +0800 Subject: [PATCH 1/2] FIX repository show api --- README.md | 18 +++++++++++++----- app/controllers/repositories_controller.rb | 1 + app/views/repositories/show.json.jbuilder | 6 +++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 311e91aea..9d456b372 100644 --- a/README.md +++ b/README.md @@ -470,10 +470,10 @@ http://localhost:3000/api/projects/3263 | jq |参数名|必选|类型|说明| -|-|-|- |id |是|int |项目id | -|name |是|string |项目名称 | -|description |是|string |项目描述 | -|project_category_id|是|int |项目类别id | -|project_language_id|是|int |项目语言id | +|name |否|string |项目名称 | +|description |否|string |项目描述 | +|project_category_id|否|int |项目类别id | +|project_language_id|否|int |项目语言id | |private |否|boolean|项目是否私有, true:为私有,false: 公开,默认为公开 | @@ -1274,11 +1274,15 @@ http://localhost:3000/api/18816895620/mirror_demo | jq |参数名|类型|说明| -|-|- |identifier |string|仓库标识| +|project_id |int|项目id| +|project_identifier|string|项目标识| |praises_count |int|点赞数量| |forked_count |int|fork数量| |watchers_count |int|关注数量| |branches_count |int|分支数量| |commits_count |int|总提交记录数量| +|praised |boolean|当前登录用户是否已点赞,true:已点赞,fasle:未点赞, 用户未登录状态为null| +|watched |boolean|当前登录用户是否已关注,true:已关注,fasle:未关注, 用户未登录状态为null| |permission |string|当前登录用户对该仓库的操作权限, Manager:管理员,可以在线编辑文件、在线新建文件、可以设置仓库的基本信息; Developer:开发人员,可在线编辑文件、在线新建文件、不能设置仓库信息; Reporter: 报告人员,只能查看信息,不能设置仓库信息、不能在线编辑文件、不能在线新建文件;用户未登录时也会返回Reporter, 说明也只有读取文件的权限 | |mirror_url |string|镜像地址, 只有通过镜像过来的项目才会有这个地址| |author |object|提交用户| @@ -1289,6 +1293,8 @@ http://localhost:3000/api/18816895620/mirror_demo | jq 返回值 ``` { + "project_id": 3263, + "project_identifier": "mirror_demo", "identifier": "mirror_demo", "praises_count": 1, "forked_count": 0, @@ -1296,6 +1302,8 @@ http://localhost:3000/api/18816895620/mirror_demo | jq "branches_count": 6, "commits_count": 105, "permission": "Manager", + "watched": true, + "praised": true, "mirror_url": "https://gitea.com/CasperVector/slew.git", "author": { "name": "18816895620", @@ -1488,7 +1496,7 @@ http://localhost:3000/api/projects/3263/praise_tread | jq |参数名|类型|说明| -|-|- |total_count |int|总条数| -|praises |array|关注数据| +|praises |array|点赞数据| |-- name |string|用户名称| |-- login |string|用户标识/登录名(login)| |-- image_url |string|用户头像| diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c68c4eaa8..9a53d6191 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -3,6 +3,7 @@ class RepositoriesController < ApplicationController before_action :find_user, :find_repository, :authorizate! def show + @project = @repo.project @branches_count = Gitea::Repository::BranchesService.new(@user, @repo.identifier).call.size @commits_count = Gitea::Repository::Commits::ListService.new(@user, @repo.identifier).call[:total_count] end diff --git a/app/views/repositories/show.json.jbuilder b/app/views/repositories/show.json.jbuilder index 1fc9700f7..7b1a5abe1 100644 --- a/app/views/repositories/show.json.jbuilder +++ b/app/views/repositories/show.json.jbuilder @@ -1,9 +1,13 @@ json.identifier @repo.identifier +json.project_id @project.id +json.project_identifier @project.identifier json.praises_count @repo.project.praises_count json.forked_count @repo.project.forked_count json.watchers_count @repo.project.watchers_count json.branches_count @branches_count json.commits_count @commits_count -json.permission render_edit_project_permission(current_user, @repo.project) +json.permission render_edit_project_permission(current_user, @project) json.mirror_url @repo.mirror_url +json.watched current_user&.watched?(@project) +json.praised current_user&.liked?(@project) json.partial! 'author', locals: { user: @repo.user } From f32b215dc0e2f16eba2dd510d98ba0885c127202 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 14 Jan 2020 16:07:26 +0800 Subject: [PATCH 2/2] FIX Merge --- app/controllers/application_controller.rb | 44 ++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 456f503a3..36f14edbf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -329,6 +329,7 @@ class ApplicationController < ActionController::Base def current_user # User.current User.find_by_id 36401 + # nil end ## 默认输出json @@ -355,21 +356,21 @@ class ApplicationController < ActionController::Base # 通关后,把最后一次成功的代码存到数据库 # type 0 创始内容, 1 最新内容 - def game_passed_code(path, myshixun, game_id) - # 如果代码窗口是隐藏的,则不用保存代码 - return if myshixun.shixun.hide_code || myshixun.shixun.vnc - file_content = git_fle_content myshixun.repo_path, path - #unless file_content.present? - # raise("获取文件代码异常") - #end - logger.info("#######game_id:#{game_id}, file_content:#{file_content}") - game_code = GameCode.where(:game_id => game_id, :path => path).first - if game_code.nil? - GameCode.create!(:game_id => game_id, :new_code => file_content, :path => path) - else - game_code.update_attributes!(:new_code => file_content) - end - end + # def game_passed_code(path, myshixun, game_id) + # # 如果代码窗口是隐藏的,则不用保存代码 + # return if myshixun.shixun.hide_code || myshixun.shixun.vnc + # file_content = git_fle_content myshixun.repo_path, path + # #unless file_content.present? + # # raise("获取文件代码异常") + # #end + # logger.info("#######game_id:#{game_id}, file_content:#{file_content}") + # game_code = GameCode.where(:game_id => game_id, :path => path).first + # if game_code.nil? + # GameCode.create!(:game_id => game_id, :new_code => file_content, :path => path) + # else + # game_code.update_attributes!(:new_code => file_content) + # end + # end # Post请求 def uri_post(uri, params) @@ -647,19 +648,20 @@ class ApplicationController < ActionController::Base render_not_found("未找到’#{params[:id]}’相关的项目") unless @project end + def find_project_with_identifier + @project = Project.find_by_identifier! params[:id] + render_not_found("未找到’#{params[:id]}’相关的项目") unless @project + end + def find_project_with_id - @project = Project.find params[:project_id] + @project = Project.find(params[:project_id] || params[:id]) rescue Exception => e logger_error(e.message) tip_exception(e.message) end def render_response(interactor) - if interactor.success? - render_ok - else - render_error(interactor.error) - end + interactor.success? ? render_ok : render_error(interactor.error) end private