add blockchain api

This commit is contained in:
nigel007 2019-04-14 16:24:47 +08:00
parent 4dfef1b571
commit 60415e1182
1 changed files with 33 additions and 15 deletions
app/api/mobile/apis

View File

@ -4,28 +4,46 @@ module Mobile
module Apis
class Blockchains < Grape::API
resources :blockchains do
desc "获取项目列表"
params do
requires :token, type: String
end
get do
ps = ProjectsService.new
projects = ps.user_projects(current_user)
present :data, projects, with: Mobile::Entities::Project,user: current_user
present :status, 0
end
desc "创建项目"
params do
requires :token, type: String
requires :project_name, type: String
requires :username, type: String
requires :reponame, type: String
requires :password, type: String
requires :genesis_content, type: String
requires :network_id, type: Integer
requires :connect_ip, type: String
requires :port, type: Integer
requires :enode, type: String
# user_id, created_at, updated_at需要在程序中创建
end
post 'create' do
# authenticate! # 可能需要修改认证函数
authenticate!
ps = ProjectsService.new # 创建项目
status = ps.createNewProject params,current_user
present :status, 0
user = current_user
status, project = ps.createNewProjectBlockchain params,user
if status == 0
# 表示项目创建成功
bs = BlockchainsService.new
status, blockchain = bs.create_item project, user, params # 创建blockchain item
present :status, status # status -1:表示创建失败; 1:表示创建成功
end
present :status, status # status -1:表示创建失败; 1:表示创建成功
end
desc "获取用户已经创建的东西"
params do
requires :username, type: String
requires :password, type: String
end
post 'get_already_things' do
authenticate!
bs = BlockchainsService.new
user = current_user
result_hash = bs.get_already_things(user)
present result_hash
end
end
end
end