ADD simple project api
This commit is contained in:
parent
38746464a8
commit
1133517127
|
@ -1,7 +1,8 @@
|
||||||
class ProjectsController < ApplicationController
|
class ProjectsController < ApplicationController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include OperateProjectAbilityAble
|
include OperateProjectAbilityAble
|
||||||
before_action :require_login, except: %i[index branches group_type_list]
|
include ProjectsHelper
|
||||||
|
before_action :require_login, except: %i[index branches group_type_list simple]
|
||||||
before_action :find_project_with_id, only: %i[show branches update destroy fork_users praise_users watch_users]
|
before_action :find_project_with_id, only: %i[show branches update destroy fork_users praise_users watch_users]
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_user]
|
before_action :project_public?, only: %i[fork_users praise_users watch_user]
|
||||||
|
@ -98,6 +99,12 @@ class ProjectsController < ApplicationController
|
||||||
@fork_users = paginate(fork_users)
|
@fork_users = paginate(fork_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def simple
|
||||||
|
project = Project.includes(:owner).select(:id, :name, :identifier, :user_id).find params[:id]
|
||||||
|
|
||||||
|
json_response(project)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def project_params
|
def project_params
|
||||||
params.permit(:user_id, :name, :description, :repository_name,
|
params.permit(:user_id, :name, :description, :repository_name,
|
||||||
|
|
|
@ -27,4 +27,18 @@ module ProjectsHelper
|
||||||
def find_user_by_login_or_mail(identifier)
|
def find_user_by_login_or_mail(identifier)
|
||||||
(User.find_by_login identifier) || (User.find_by_mail identifier)
|
(User.find_by_login identifier) || (User.find_by_mail identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def json_response(project)
|
||||||
|
json = {
|
||||||
|
identifier: project.identifier,
|
||||||
|
name: project.name,
|
||||||
|
id: project.id,
|
||||||
|
author: {
|
||||||
|
login: project.owner.login,
|
||||||
|
name: project.owner.real_name,
|
||||||
|
image_url: url_to_avatar(project.owner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render json: json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,4 +15,22 @@ class Repository < ApplicationRecord
|
||||||
def set_mirror!
|
def set_mirror!
|
||||||
self.build_mirror(status: Mirror.statuses[:waiting]).save
|
self.build_mirror(status: Mirror.statuses[:waiting]).save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mirror_status
|
||||||
|
self&.mirror&.numerical_for_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def mirror_num
|
||||||
|
self&.mirror&.sync_num
|
||||||
|
end
|
||||||
|
|
||||||
|
def first_sync?
|
||||||
|
self&.mirror&.sync_num === 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_mirror!
|
||||||
|
repo_mirror = self.mirror
|
||||||
|
repo_mirror.set_status!(Mirror.statuses[:waiting])
|
||||||
|
repo_mirror.increment!(:sync_num)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,8 +32,8 @@ Rails.application.routes.draw do
|
||||||
delete 'commons/delete', to: 'commons#delete'
|
delete 'commons/delete', to: 'commons#delete'
|
||||||
|
|
||||||
resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do
|
resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do
|
||||||
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
|
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
|
||||||
member do
|
member do
|
||||||
get :get_children_journals
|
get :get_children_journals
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -118,6 +118,7 @@ Rails.application.routes.draw do
|
||||||
get :watch_users
|
get :watch_users
|
||||||
get :praise_users
|
get :praise_users
|
||||||
get :fork_users
|
get :fork_users
|
||||||
|
get :simple
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue