From 47a8f1707302e0a2fcf1643ba00a6180ce6792a0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 11:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BD=AC=E8=B4=A6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E4=BD=BF=E7=94=A8json=20builder=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E8=B4=A1=E7=8C=AE=E8=80=85=E6=96=B0=E5=A2=9E=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E5=8D=A0=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- app/models/concerns/watchable.rb | 8 +++----- app/queries/blockchain/balance_query.rb | 2 +- app/views/repositories/_contributor.json.jbuilder | 1 + app/views/repositories/contributors.json.jbuilder | 2 +- app/views/users/blockchain_balance.json.jbuilder | 5 +++++ 6 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 app/views/users/blockchain_balance.json.jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6aee4b58..1b51e3b1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -423,7 +423,7 @@ class UsersController < ApplicationController @projects = [] end - render json: { status: results[:status], projects: @projects, total_count: @total_count } + # render json: { status: results[:status], projects: @projects, total_count: @total_count } end # query one balance diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 9eb0172d..dc2b67f6 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,11 +31,9 @@ module Watchable following.size end - def contribution_perc - project_identifier = params[:project_identifier] - user_login = params[:id] - @project = Project.find_by_identifier(project_identifier) - @user = User.find_by_login(user_login) + def contribution_perc(project) + @project = project + @user = self def cal_perc(count_user, count_all) (count_user * 1.0 / (count_all + 0.000000001)).round(5) diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index 669370a5..a1bb76ee 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -20,7 +20,7 @@ class Blockchain::BalanceQuery < ApplicationQuery if owner.nil? || project.nil? else balance = t['balance'] - result_list << [owner, project, balance] + result_list << {project: project, balance: balance} end end results = {"status": 0, "projects": result_list} diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 56fa9ce8..2efaa007 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -13,4 +13,5 @@ else json.type user["type"] json.name user["name"] json.image_url user["avatar_url"] + json.blockchain_perc user.contribution_perc(project) end diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index 2fb6abae..4534de69 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,6 +1,6 @@ total_count = @contributors.size json.list @contributors.each do |contributor| - json.partial! 'contributor', locals: { contributor: contributor } + json.partial! 'contributor', locals: { contributor: contributor, project: @project } end json.total_count total_count diff --git a/app/views/users/blockchain_balance.json.jbuilder b/app/views/users/blockchain_balance.json.jbuilder new file mode 100644 index 00000000..83293cf0 --- /dev/null +++ b/app/views/users/blockchain_balance.json.jbuilder @@ -0,0 +1,5 @@ +json.total_count @total_count +json.projects @projects.each do |p| + json.partial! 'projects/detail', locals: { project: p[:project] } + json.balance p[:balance] +end \ No newline at end of file