This commit is contained in:
anph 2023-08-15 00:15:10 +08:00
parent 4fa10a3683
commit b8f9deb1ed
34 changed files with 325 additions and 205 deletions

0
.rake_tasks~ Normal file
View File

View File

@ -124,20 +124,26 @@ class AccountsController < ApplicationController
password = register_params[:password].strip
# gitea用户注册, email, username, password
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
if interactor.success?
gitea_user = interactor.result
result = Gitea::User::GenerateTokenService.call(user.login, password)
user.gitea_token = result['sha1']
user.gitea_uid = gitea_user[:body]['id']
# interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
# if interactor.success?
# gitea_user = interactor.result
# result = Gitea::User::GenerateTokenService.call(user.login, password)
# user.gitea_token = result['sha1']
# user.gitea_uid = gitea_user[:body]['id']
# if user.save!
# UserExtension.create!(user_id: user.id)
# successful_authentication(user)
# render_ok
# end
# else
# tip_exception(-1, interactor.error)
# end
if user.save!
UserExtension.create!(user_id: user.id)
successful_authentication(user)
render_ok
end
else
tip_exception(-1, interactor.error)
end
rescue Register::BaseForm::EmailError => e
render_error(-2, e.message)
rescue Register::BaseForm::LoginError => e

View File

@ -18,6 +18,20 @@ class RepositoriesController < ApplicationController
render json: result
end
def preload_badge
end
def badges
@badge = RepositoryBadge.where(project_id: @project.id).pluck(:popular_project, :recommend_project, :many_stars).first
popular_project = @badge[0]
recommend_project = @badge[1]
many_stars = @badge[2]
render :json => {popular_project: popular_project, recommend_project: recommend_project, many_stars: many_stars}
end
# 新版项目详情
def detail
@user = current_user

View File

@ -1,5 +1,6 @@
class Users::StatisticsController < Users::BaseController
before_action :preload_develop_data, only: [:develop]
before_action :preload_badge_data, only: [:badges]
# 近期活动统计
def activity
@ -20,6 +21,21 @@ class Users::StatisticsController < Users::BaseController
render :json => {dates: @date_data, issues_count: @issue_data, pull_requests_count: @pull_request_data, commits_count: @commit_data}
end
###############change###############
# badges 接口 url 路径为/api/users/:user_id/statistic/badges
def badges
@badge = Badge.where(user_id: observed_user.id).pluck(:watcher, :pullrequest, :many_fans, :amazing_project_owner).first
watcher = @badge[0]
pullrequest = @badge[1]
many_fans = @badge[2]
amazing_project_owner = @badge[3]
render :json => {watcher: watcher, pullrequest: pullrequest, many_fans: many_fans, amazing_project_owner: amazing_project_owner}
end
###############change###############
# 开发能力
def develop
if params[:start_time].present? && params[:end_time].present?
@ -217,3 +233,45 @@ class Users::StatisticsController < Users::BaseController
end
end
end
def preload_badge_data
#从缓存中读取
@user_result = Cache::V2::UserStatisticService.new(observed_user.id).read
# 用户被follow数量
@follow_count = @user_result["follow-count"].to_i
# 用户pr数量
@pullrequest_count = @user_result["pullrequest-count"].to_i
# 用户issue数量
@issues_count = @user_result["issue-count"].to_i
# 用户总项目数
@project_count = @user_result["project-count"].to_i
# 用户项目被fork数量
@fork_count = @user_result["fork-count"].to_i
# 用户项目关注数
@project_watchers_count = @user_result["project-watcher-count"].to_i
# 用户项目点赞数
@project_praises_count = @user_result["project-praise-count"].to_i
# 用户不同语言项目数量
@project_languages_count = JSON.parse(@user_result["project-language"])
@stars_stuck = @follow_count >= 16 ? true : false
@pr_stuck = @pullrequest_count >= 5 ? true : false
@many_fans = @fork_count >= 10 ? true : false
@amazing_project_owner = @project_praises_count >= 20 ? true : false
updateService @stars_stuck ,@pr_stuck, @many_fans, @amazing_project_owner
end
def updateService(stars_stuck, pr_stuck, many_fans, amazing_project_owner)
@badge = Badge.find_or_create_by(user_id: observed_user.id)
@badge.watcher = stars_stuck
@badge.pullrequest = pr_stuck
@badge.many_fans = many_fans
@badge.amazing_project_owner = amazing_project_owner
@badge.save
end

View File

@ -41,7 +41,7 @@ module Register
def check_verifi_code(verifi_code, code)
code = strip(code)
# return if code == "123123" # TODO 万能验证码,用于测试
return if code == "123123" # TODO 万能验证码,用于测试
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?

View File

@ -17,7 +17,7 @@
# disk_directory :string(255)
# attachtype :integer default("1")
# is_public :integer default("1")
# copy_from :string(255)
# copy_from :integer
# quotes :integer default("0")
# is_publish :integer default("1")
# publish_time :datetime
@ -26,15 +26,15 @@
# cloud_url :string(255) default("")
# course_second_category_id :integer default("0")
# delay_publish :boolean default("0")
# link :string(255)
# clone_id :integer
#
# Indexes
#
# index_attachments_on_author_id (author_id)
# index_attachments_on_clone_id (clone_id)
# index_attachments_on_container_id_and_container_type (container_id,container_type)
# index_attachments_on_course_second_category_id (course_second_category_id)
# index_attachments_on_created_on (created_on)
# index_attachments_on_is_public (is_public)
# index_attachments_on_quotes (quotes)
#

16
app/models/badge.rb Normal file
View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: badges
#
# id :integer not null, primary key
# user_id :integer
# watcher :boolean default("0")
# pullrequest :boolean default("0")
# many_fans :boolean default("0")
# amazing_project_owner :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#
class Badge < ApplicationRecord
end

View File

@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#

View File

@ -14,6 +14,7 @@
# index_edu_settings_on_name (name) UNIQUE
#
class EduSetting < ApplicationRecord
after_commit :expire_value_cache

View File

@ -10,7 +10,6 @@
# sync_course :boolean default("0")
# sync_subject :boolean default("0")
# sync_shixun :boolean default("0")
# is_local :boolean default("0")
#
# Indexes
#

View File

@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#

View File

@ -16,6 +16,7 @@
#
class PraiseTread < ApplicationRecord
belongs_to :user
belongs_to :praise_tread_object, polymorphic: true, counter_cache: :praises_count

View File

@ -81,6 +81,7 @@
class Project < ApplicationRecord
include Matchable
include Publicable

View File

@ -3,8 +3,8 @@
# Table name: pull_requests
#
# id :integer not null, primary key
# pull_request_id :integer
# gpid :integer
# gitea_id :integer
# gitea_number :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null

View File

@ -27,6 +27,7 @@
#
# Indexes
#
# index_repositories_on_identifier (identifier)
# index_repositories_on_project_id (project_id)
# index_repositories_on_user_id (user_id)
#

View File

@ -0,0 +1,2 @@
class RepositoryBadge < ApplicationRecord
end

View File

@ -3,14 +3,14 @@
# Table name: system_notification_histories
#
# id :integer not null, primary key
# system_message_id :integer
# system_notification_id :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_system_notification_histories_on_system_message_id (system_message_id)
# index_system_notification_histories_on_system_notification_id (system_notification_id)
# index_system_notification_histories_on_user_id (user_id)
#

View File

@ -6,9 +6,9 @@
# type :string(255)
# name :string(255)
# key :string(255)
# openning :boolean
# notification_disabled :boolean
# email_disabled :boolean
# openning :boolean default("1")
# notification_disabled :boolean default("1")
# email_disabled :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@ -6,9 +6,9 @@
# type :string(255)
# name :string(255)
# key :string(255)
# openning :boolean
# notification_disabled :boolean
# email_disabled :boolean
# openning :boolean default("1")
# notification_disabled :boolean default("1")
# email_disabled :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@ -6,9 +6,9 @@
# type :string(255)
# name :string(255)
# key :string(255)
# openning :boolean
# notification_disabled :boolean
# email_disabled :boolean
# openning :boolean default("1")
# notification_disabled :boolean default("1")
# email_disabled :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@ -6,9 +6,9 @@
# type :string(255)
# name :string(255)
# key :string(255)
# openning :boolean
# notification_disabled :boolean
# email_disabled :boolean
# openning :boolean default("1")
# notification_disabled :boolean default("1")
# email_disabled :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@ -6,9 +6,9 @@
# type :string(255)
# name :string(255)
# key :string(255)
# openning :boolean
# notification_disabled :boolean
# email_disabled :boolean
# openning :boolean default("1")
# notification_disabled :boolean default("1")
# email_disabled :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@ -14,6 +14,7 @@
# tokens_value (value) UNIQUE
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -1,4 +1,4 @@
# == Schema Information
``# == Schema Information
#
# Table name: users
#
@ -39,15 +39,13 @@
# business :boolean default("0")
# profile_completed :boolean default("0")
# laboratory_id :integer
# is_shixun_marker :boolean default("0")
# admin_visitable :boolean default("0")
# collaborator :boolean default("0")
# platform :string(255) default("0")
# gitea_token :string(255)
# gitea_uid :integer
# is_shixun_marker :boolean default("0")
# is_sync_pwd :boolean default("1")
# watchers_count :integer default("0")
# devops_step :integer default("0")
# gitea_token :string(255)
# platform :string(255)
#
# Indexes
#
@ -55,9 +53,8 @@
# index_users_on_homepage_engineer (homepage_engineer)
# index_users_on_homepage_teacher (homepage_teacher)
# index_users_on_laboratory_id (laboratory_id)
# index_users_on_login (login) UNIQUE
# index_users_on_mail (mail) UNIQUE
# index_users_on_phone (phone) UNIQUE
# index_users_on_login (login)
# index_users_on_mail (mail)
# index_users_on_type (type)
#
@ -155,6 +152,8 @@ class User < Owner
has_many :team_users, dependent: :destroy
has_many :teams, through: :team_users
# 教学案例
# has_many :libraries, dependent: :destroy
has_many :project_trends, dependent: :destroy

View File

@ -13,8 +13,6 @@
# Indexes
#
# index_user_actions_on_ip (ip)
# index_user_actions_on_user_id (user_id)
# index_user_actions_on_user_id_and_action_type (user_id,action_type)
#
class UserAction < ApplicationRecord

View File

@ -10,13 +10,10 @@
# updated_at :datetime not null
# register_status :integer default("0")
# action_status :integer default("0")
# is_delete :boolean default("0")
# user_id :integer
#
# Indexes
#
# index_user_agents_on_ip (ip)
# index_user_agents_on_user_id (user_id)
# index_user_agents_on_ip (ip) UNIQUE
#
class UserAgent < ApplicationRecord

View File

@ -22,9 +22,6 @@
# school_id :integer
# description :string(255) default("")
# department_id :integer
# honor :text(65535)
# edu_background :integer
# edu_entry_year :integer
# province :string(255)
# city :string(255)
# custom_department :string(255)

View File

@ -12,7 +12,7 @@ class Users::RegisterService < ApplicationService
namespace = strip(@namespace)
password = strip(@password)
Rails.logger.info "Users::RegisterService params: ##### #{params} "
#Rails.logger.info "Users::RegisterService params: ##### #{params} "
email, phone =
if register_type == 1

View File

@ -299,6 +299,7 @@ Rails.application.routes.draw do
get :develop
get :role
get :major
get :badges
end
end
resources :project_trends, only: [:index]

View File

@ -0,0 +1,13 @@
class CreateBadges < ActiveRecord::Migration[5.2]
def change
create_table :badges do |t|
t.integer :user_id
t.boolean :watcher, default: false
t.boolean :pullrequest, default: false
t.boolean :many_fans, default: false
t.boolean :amazing_project_owner, default: false
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateRepositoryBadges < ActiveRecord::Migration[5.2]
def change
create_table :repository_badges do |t|
t.integer :project_id
t.integer :popular_project, default: 0
t.integer :recommend_project, default: 0
t.integer :many_stars, default: 0
t.timestamps
end
end
end

View File

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

View File

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