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'
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def present_projects(projects, options = {})
 | 
			
		||||
        def present_projects(options = {})
 | 
			
		||||
          options = options.reverse_merge(
 | 
			
		||||
            with: Entities::Project,
 | 
			
		||||
            current_user: current_user,
 | 
			
		||||
            simple: params[:simple],
 | 
			
		||||
            with_issues_enabled: params[:with_issues_enabled],
 | 
			
		||||
            with_merge_requests_enabled: params[:with_merge_requests_enabled]
 | 
			
		||||
            with: current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails,
 | 
			
		||||
            current_user: current_user
 | 
			
		||||
          )
 | 
			
		||||
 | 
			
		||||
          projects = ProjectsFinder.new(current_user: current_user).execute
 | 
			
		||||
          projects = filter_projects(projects)
 | 
			
		||||
          projects = projects.with_statistics if options[:statistics]
 | 
			
		||||
          projects = projects.with_issues_enabled if options[:with_issues_enabled]
 | 
			
		||||
          projects = projects.with_merge_requests_enabled if options[:with_merge_requests_enabled]
 | 
			
		||||
          options[:with] = Entities::BasicProjectDetails if options[:simple]
 | 
			
		||||
          projects = projects.with_statistics if params[:statistics]
 | 
			
		||||
          projects = projects.with_issues_enabled if params[:with_issues_enabled]
 | 
			
		||||
          projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
 | 
			
		||||
          options[:with] = Entities::BasicProjectDetails if params[:simple]
 | 
			
		||||
 | 
			
		||||
          present paginate(projects), options
 | 
			
		||||
        end
 | 
			
		||||
| 
						 | 
				
			
			@ -94,8 +92,7 @@ module API
 | 
			
		|||
        use :statistics_params
 | 
			
		||||
      end
 | 
			
		||||
      get do
 | 
			
		||||
        entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
 | 
			
		||||
        present_projects ProjectsFinder.new(current_user: current_user).execute, with: entity, statistics: params[:statistics]
 | 
			
		||||
        present_projects
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      desc 'Create new project' do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue