ADD simple project api

This commit is contained in:
Jasder 2020-06-29 16:05:22 +08:00
parent 38746464a8
commit 1133517127
4 changed files with 43 additions and 3 deletions

View File

@ -1,7 +1,8 @@
class ProjectsController < ApplicationController
include ApplicationHelper
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 :authorizate_user_can_edit_project!, only: %i[update]
before_action :project_public?, only: %i[fork_users praise_users watch_user]
@ -98,6 +99,12 @@ class ProjectsController < ApplicationController
@fork_users = paginate(fork_users)
end
def simple
project = Project.includes(:owner).select(:id, :name, :identifier, :user_id).find params[:id]
json_response(project)
end
private
def project_params
params.permit(:user_id, :name, :description, :repository_name,

View File

@ -27,4 +27,18 @@ module ProjectsHelper
def find_user_by_login_or_mail(identifier)
(User.find_by_login identifier) || (User.find_by_mail identifier)
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

View File

@ -15,4 +15,22 @@ class Repository < ApplicationRecord
def set_mirror!
self.build_mirror(status: Mirror.statuses[:waiting]).save
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

View File

@ -32,8 +32,8 @@ Rails.application.routes.draw do
delete 'commons/delete', to: 'commons#delete'
resources :issues, except: [:index, :new,:create, :update, :edit, :destroy] do
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
member do
resources :journals, only: [:index, :create, :destroy, :edit, :update] do
member do
get :get_children_journals
end
end
@ -118,6 +118,7 @@ Rails.application.routes.draw do
get :watch_users
get :praise_users
get :fork_users
get :simple
end
end