Skip to content

Commit

Permalink
Add packages endpoint to projects controller #87
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Dec 8, 2023
1 parent 322b197 commit 459993c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ def ping
@project.sync_async
render json: { message: 'pong' }
end

def packages
@projects = Project.reviewed.select{|p| p.packages.present? }.sort_by{|p| p.packages.sum{|p| p['downloads'] || 0 } }.reverse
end
end
1 change: 1 addition & 0 deletions app/views/api/v1/projects/packages.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @projects, partial: 'api/v1/projects/project', as: :project
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
resources :projects, constraints: { id: /.*/ }, only: [:index, :show] do
collection do
get :lookup
get :packages
end
member do
get :ping
Expand Down
15 changes: 15 additions & 0 deletions openapi/api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Project'
/projects/packages:
get:
description: get projects with packages
operationId: getProjectPackages
tags:
- projects
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Project'
/issues:
get:
description: get issues
Expand Down

0 comments on commit 459993c

Please sign in to comment.