add: project explore api
This commit is contained in:
parent
e5eb0d3d47
commit
a43f6714de
|
@ -5,6 +5,10 @@ class ProjectCategoriesController < ApplicationController
|
|||
@project_categories = q.result(distinct: true)
|
||||
end
|
||||
|
||||
def pinned_index
|
||||
@project_categories = ProjectCategory.where.not(pinned_index: 0).order(pinned_index: :desc)
|
||||
end
|
||||
|
||||
def group_list
|
||||
@project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
|
||||
# projects = Project.no_anomory_projects.visible
|
||||
|
|
|
@ -6,7 +6,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
|
||||
before_action :require_profile_completed, only: [:create, :migrate]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
|
||||
|
@ -30,8 +30,8 @@ class ProjectsController < ApplicationController
|
|||
def index
|
||||
scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params)
|
||||
|
||||
# @projects = kaminari_paginate(scope)
|
||||
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units))
|
||||
# @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
|
||||
category_id = params[:category_id]
|
||||
@total_count =
|
||||
|
@ -199,6 +199,10 @@ class ProjectsController < ApplicationController
|
|||
@projects = Project.recommend.includes(:repository, :project_category, :owner).order(visits: :desc)
|
||||
end
|
||||
|
||||
def banner_recommend
|
||||
@projects = Project.recommend.where.not(recommend_index: 0).includes(:project_category, :owner, :project_language).order(recommend_index: :desc)
|
||||
end
|
||||
|
||||
def about
|
||||
@project_detail = @project.project_detail
|
||||
@attachments = Array(@project_detail&.attachments) if request.get?
|
||||
|
|
|
@ -55,8 +55,9 @@
|
|||
# platform :integer default("0")
|
||||
# default_branch :string(255) default("master")
|
||||
# website :string(255)
|
||||
# order_index :integer default("0")
|
||||
# lesson_url :string(255)
|
||||
# is_pinned :boolean default("0")
|
||||
# recommend_index :integer default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
@ -79,6 +80,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
class Project < ApplicationRecord
|
||||
include Matchable
|
||||
include Publicable
|
||||
|
@ -134,6 +136,7 @@ class Project < ApplicationRecord
|
|||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
|
||||
scope :pinned, -> {where(is_pinned: true)}
|
||||
|
||||
delegate :content, to: :project_detail, allow_nil: true
|
||||
delegate :name, to: :license, prefix: true, allow_nil: true
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
# projects_count :integer default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# ancestry :string(255)
|
||||
# pinned_index :integer default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_project_categories_on_ancestry (ancestry)
|
||||
#
|
||||
|
||||
class ProjectCategory < ApplicationRecord
|
||||
|
|
|
@ -11,7 +11,8 @@ class Projects::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def call
|
||||
q = Project.visible.by_name_or_identifier(params[:search])
|
||||
q = params[:pinned].present? ? Project.pinned : Project
|
||||
q = q.visible.by_name_or_identifier(params[:search])
|
||||
|
||||
scope = q
|
||||
.with_project_type(params[:project_type])
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
json.project_categories @project_categories, :id, :name
|
|
@ -0,0 +1,35 @@
|
|||
json.partial! "commons/success"
|
||||
json.projects do
|
||||
json.array! @projects do |project|
|
||||
owner = project.owner
|
||||
json.id project.id
|
||||
json.identifier project.identifier
|
||||
json.name project.name
|
||||
json.visits project.visits
|
||||
json.author do
|
||||
json.name owner.try(:show_real_name)
|
||||
json.type owner.type
|
||||
json.login owner.login
|
||||
json.image_url url_to_avatar(owner)
|
||||
end
|
||||
|
||||
json.category do
|
||||
if project.project_category.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_category.id
|
||||
json.name project.project_category.name
|
||||
end
|
||||
end
|
||||
|
||||
json.language do
|
||||
if project.project_language.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_language.id
|
||||
json.name project.project_language.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
json.total_count @total_count
|
||||
json.total_count @projects.total_count
|
||||
json.projects @projects do |project|
|
||||
# json.partial! "/projects/project_detail", project: project
|
||||
json.id project.id
|
||||
|
|
|
@ -159,6 +159,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :project_categories, only: [:index, :show] do
|
||||
get :group_list, on: :collection
|
||||
get :pinned_index, on: :collection
|
||||
end
|
||||
resources :project_languages, only: [:index, :show]
|
||||
resources :ignores, only: [:index, :show]
|
||||
|
@ -184,6 +185,7 @@ Rails.application.routes.draw do
|
|||
post :migrate
|
||||
get :group_type_list
|
||||
get :recommend
|
||||
get :banner_recommend
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class AddSomeColumnsToProjectDetailFeature < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :project_categories, :pinned_index, :integer, default: 0
|
||||
add_column :projects, :is_pinned, :boolean, default: false
|
||||
add_column :projects, :recommend_index, :integer, default: 0
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue