新增:开源大赛战队同步保存至gitlink

This commit is contained in:
yystopf 2024-05-22 11:05:40 +08:00
parent c6ae30f2cd
commit caa7acc654
5 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,37 @@
class Api::V1::GitlinkCompetitionAppliesController < Api::V1::BaseController
def create
return render_error("请输入正确的竞赛ID") unless params[:competition_id].present?
return render_error("请输入正确的队伍ID") unless params[:team_id].present?
return render_error("请输入正确的队伍成员信息") unless params[:team_members].is_a?(Array)
params[:team_members].each do |member|
apply = GitlinkCompetitionApply.find_or_create_by(competition_id: params[:competition_id], team_id: params[:team_id], educoder_login: member[:login])
apply.competition_identifier = params[:competition_identifier]
apply.team_name = params[:team_name]
apply.school_name = member[:school_name]
apply.nickname = member[:nickname]
apply.identity = member[:identity]
apply.role = member[:role]
apply.email = member[:email]
user_info = get_user_info_by_educoder_login(member[:login])
apply.phone = user_info["phone"]
apply.save
end
render_ok
end
def get_user_info_by_educoder_login(edu_login)
req_params = { "login" => "#{edu_login}", "private_token" => "hriEn3UwXfJs3PmyXnqQ" }
api_url= "https://data.educoder.net"
client = Faraday.new(url: api_url)
response = client.public_send("get", "/api/sources/get_user_info_by_login", req_params)
result = JSON.parse(response.body)
return nil if result["status"].to_s != "0"
# login 邮箱 手机号 姓名 学校/单位
user_info = result["data"]
return user_info
end
end

View File

@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: gitlink_competition_applies
#
# id :integer not null, primary key
# competition_id :integer
# competition_identifier :string(255)
# team_id :integer
# team_name :string(255)
# school_name :string(255)
# login :string(255)
# nickname :string(255)
# phone :string(255)
# identity :string(255)
# role :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class GitlinkCompetitionApply < ApplicationRecord
end

View File

@ -159,6 +159,7 @@ defaults format: :json do
resources :projects, only: [:index]
resources :project_topics, only: [:index, :create, :destroy]
resources :project_datasets, only: [:index]
resources :gitlink_competition_applies, only: [:create]
end
end

View File

@ -0,0 +1,19 @@
class CreateGitlinkCompetitionApplies < ActiveRecord::Migration[5.2]
def change
create_table :gitlink_competition_applies do |t|
t.integer :competition_id
t.string :competition_identifier
t.integer :team_id
t.string :team_name
t.string :school_name
t.string :educoder_login
t.string :nickname
t.string :phone
t.string :email
t.string :identity
t.string :role
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe GitlinkCompetitionApply, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end