Skip to content

Commit

Permalink
Add dwc_occurrence_id param to dwc_gallery_json endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Oct 2, 2024
1 parent 6c69373 commit 754731e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv

### Added

- `dwc_occurrence_id[]` param to dwc_gallery endpoint
- Image matrix link to radial linker and radial matrix

### Fixed

- `api/v1/images/975145cf4d25d7ed35893170abc2e852` style calls finding images by id, not fingerprint

## [0.44.2] - 2024-09-27

### Added
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/otus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,14 @@ def api_dwc_inventory
type: 'text',
filename: "dwc_#{helpers.label_for_otu(@otu).gsub(/\W/,'_')}_#{DateTime.now}.csv"
end

format.json do
if params[:page].blank? && params[:per].blank?
render json: DwcOccurrence.scoped_by_otu(@otu).to_json
else # only apply if provided, do not fall back to default scope
render json: DwcOccurrence.scoped_by_otu(@otu).page(params[:page]).per(params[:per]).to_json
r = DwcOccurrence.scoped_by_otu(@otu).page(params[:page]).per(params[:per])
assign_pagination(r)
render json: r.to_json
end
end
end
Expand All @@ -346,7 +349,8 @@ def api_dwc_inventory
# GET /api/v1/otus/:id/inventory/dwc_gallery.json?per=1&page=2
def api_dwc_gallery
# see otus_helper
@data = helpers.dwc_gallery_data(@otu)

@data = helpers.dwc_gallery_data(@otu, dwc_occurrence_id: params[:dwc_occurrence_id])
render '/otus/api/v1/inventory/dwc_gallery'
end

Expand Down
14 changes: 10 additions & 4 deletions app/helpers/otus_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,21 @@ def ranked_otu_table(otus)

# @return Hash
# { dwc_occurrence_id: [ image1, image2 ... ], ... }
def dwc_gallery_data(otu, pagination_headers: true)
def dwc_gallery_data(otu, dwc_occurrence_id: [], pagination_headers: true)
a = DwcOccurrence.scoped_by_otu(otu)
.select(:id, :dwc_occurrence_object_id, :dwc_occurrence_object_type)
.page(params[:page])
.per(params[:per])

dwc_ids = [dwc_occurrence_id].flatten.compact.uniq

if dwc_ids.any?
a = a.where(id: dwc_ids)
end

a = a.page(params[:page]).per(params[:per])

# Somehwhat of a janky pattern, probably needs to be
# moved into Controller.
assign_pagination(a) if pagination_headers
assign_pagination(a) if pagination_headers

b = Image.with(dwc_scope: a)
.joins("JOIN depictions d on d.image_id = images.id" )
Expand Down
2 changes: 0 additions & 2 deletions config/routes/api_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@
get '/observation_matrices', to: '/observation_matrices#api_index'
get '/observation_matrices/:id', to: '/observation_matrices#api_show'


get '/images', to: '/images#api_index'
get '/images/:id/file', to: '/images#api_file', as: :image_file
get '/images/:id', to: '/images#api_show'
get '/images/:id/scale_to_box(/:x/:y/:width/:height/:box_width/:box_height)', to: '/images#api_scale_to_box'

Expand Down

0 comments on commit 754731e

Please sign in to comment.