| @@ -2,7 +2,7 @@ class UsersController < ApplicationController | |||||
| before_action :load_user, only: [:show, :homepage_info, :sync_token] | before_action :load_user, only: [:show, :homepage_info, :sync_token] | ||||
| before_action :check_user_exist, only: [:show, :homepage_info] | before_action :check_user_exist, only: [:show, :homepage_info] | ||||
| before_action :require_login, only: %i[me list] | |||||
| before_action :require_login, only: %i[me list projects] | |||||
| skip_before_action :check_sign, only: [:attachment_show] | skip_before_action :check_sign, only: [:attachment_show] | ||||
| def list | def list | ||||
| @@ -112,6 +112,13 @@ class UsersController < ApplicationController | |||||
| render_ok | render_ok | ||||
| end | end | ||||
| def projects | |||||
| scope = Projects::ListMyQuery.call(params.merge(joins: params[:joins], user_id: current_user.try(:id))) | |||||
| @total_count = scope.size | |||||
| @projects = paginate(scope) | |||||
| end | |||||
| private | private | ||||
| def load_user | def load_user | ||||
| @user = User.find_by_login(params[:id]) || User.find_by(id: params[:id]) | @user = User.find_by_login(params[:id]) || User.find_by(id: params[:id]) | ||||
| @@ -0,0 +1,32 @@ | |||||
| class Projects::ListMyQuery < ApplicationQuery | |||||
| attr_reader :params | |||||
| # sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc | |||||
| def initialize(params) | |||||
| @params = params | |||||
| end | |||||
| def call | |||||
| if params[:user_id].to_i == 2 || params[:user_id].to_i == 0 | |||||
| return nil | |||||
| else | |||||
| if params[:joins].present? | |||||
| projects = Project.where.not(user_id: params[:user_id]).joins(:members).where("members.user_id = ?", params[:user_id]) | |||||
| else | |||||
| projects = Project.where(user_id: params[:user_id]) | |||||
| end | |||||
| scope = projects.includes(:project_category, :project_language, :repository, owner: :user_extension).like(params[:search]) | |||||
| .with_project_type(params[:project_type]) | |||||
| .with_project_category(params[:category_id]) | |||||
| .with_project_language(params[:language_id]) | |||||
| sort = params[:sort_by] || "updated_on" | |||||
| sort_direction = params[:sort_direction] || "desc" | |||||
| scope.order("projects.#{sort} #{sort_direction}") | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,27 @@ | |||||
| json.total_count @total_count | |||||
| json.projects do | |||||
| json.array! @projects do |project| | |||||
| json.partial! '/projects/project', project: project | |||||
| json.author do | |||||
| json.name project.owner.login | |||||
| json.login project.owner.login | |||||
| json.image_url url_to_avatar(project.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 | |||||
| @@ -436,6 +436,7 @@ Rails.application.routes.draw do | |||||
| post :unlock | post :unlock | ||||
| post :active | post :active | ||||
| post :reset_login_times | post :reset_login_times | ||||
| get :projects | |||||
| end | end | ||||
| end | end | ||||
| resource :import_disciplines, only: [:create] | resource :import_disciplines, only: [:create] | ||||