Move ProjectsFinder to `present_projects` for simplification
To avoid passing parameters double, move all filtering to the `present_projects` helper.
This commit is contained in:
		
							parent
							
								
									98043aeedf
								
							
						
					
					
						commit
						44fdf0a1e3
					
				| 
						 | 
					@ -67,20 +67,18 @@ module API
 | 
				
			||||||
          optional :import_url, type: String, desc: 'URL from which the project is imported'
 | 
					          optional :import_url, type: String, desc: 'URL from which the project is imported'
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def present_projects(projects, options = {})
 | 
					        def present_projects(options = {})
 | 
				
			||||||
          options = options.reverse_merge(
 | 
					          options = options.reverse_merge(
 | 
				
			||||||
            with: Entities::Project,
 | 
					            with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
 | 
				
			||||||
            current_user: current_user,
 | 
					            current_user: current_user
 | 
				
			||||||
            simple: params[:simple],
 | 
					 | 
				
			||||||
            with_issues_enabled: params[:with_issues_enabled],
 | 
					 | 
				
			||||||
            with_merge_requests_enabled: params[:with_merge_requests_enabled]
 | 
					 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          projects = ProjectsFinder.new(current_user: current_user).execute
 | 
				
			||||||
          projects = filter_projects(projects)
 | 
					          projects = filter_projects(projects)
 | 
				
			||||||
          projects = projects.with_statistics if options[:statistics]
 | 
					          projects = projects.with_statistics if params[:statistics]
 | 
				
			||||||
          projects = projects.with_issues_enabled if options[:with_issues_enabled]
 | 
					          projects = projects.with_issues_enabled if params[:with_issues_enabled]
 | 
				
			||||||
          projects = projects.with_merge_requests_enabled if options[:with_merge_requests_enabled]
 | 
					          projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
 | 
				
			||||||
          options[:with] = Entities::BasicProjectDetails if options[:simple]
 | 
					          options[:with] = Entities::BasicProjectDetails if params[:simple]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          present paginate(projects), options
 | 
					          present paginate(projects), options
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
| 
						 | 
					@ -94,8 +92,7 @@ module API
 | 
				
			||||||
        use :statistics_params
 | 
					        use :statistics_params
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      get do
 | 
					      get do
 | 
				
			||||||
        entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
 | 
					        present_projects
 | 
				
			||||||
        present_projects ProjectsFinder.new(current_user: current_user).execute, with: entity, statistics: params[:statistics]
 | 
					 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      desc 'Create new project' do
 | 
					      desc 'Create new project' do
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue