ncbo / ontologies_api

Hypermedia API for NCBO's ontology-related projects
http://data.bioontology.org
Other
25 stars 10 forks source link

Refactor: The first brick of an harmonized way to get request params #109

Closed syphax-bouazzouni closed 4 months ago

syphax-bouazzouni commented 1 year ago

Goal

see https://github.com/ontoportal-lirmm/ontologies_api/issues/2

Write a DSL to make all the API endpoints implement pagination, sort and filter

How to use

See the following example

    # Display a page for all classes
    get do
      includes_param_check
      ont, submission = get_ontology_and_submission
      cls_count = submission.class_count(LOGGER)
      error 403, "Unable to display classes due to missing metrics for #{submission.id.to_s}. Please contact the administrator." if cls_count < 0

      attributes, page, size, filter_by, sort_by, bring_unmapped_needed  =  settings_params(LinkedData::Models::Class)
      check_last_modified_segment(LinkedData::Models::Class, [ont.acronym])

      page_data = LinkedData::Models::Class.in(submission)

      page_data = page_data.order_by(sort_by)    if sort_by

      page_data = page_data.include(attributes)

      page_data = page_data.page(page,size).page_count_set(cls_count)  if page

      page_data = page_data.all

      bring_unmapped_to page_data , sub if bring_unmapped_needed

      reply page_data    
    end

And it can't even be evolved to this

    # Display a page for all classes
    get do
      includes_param_check
      ont, submission = get_ontology_and_submission

         cls_count = submission.class_count(LOGGER)
      error 403, "Unable to display classes due to missing metrics for #{submission.id.to_s}. Please contact the administrator." if cls_count < 0
      reply page_data(LinkedData::Models::Class, collection: submission)    
    end

  # Display a page for all users
    get do
      reply page_data(LinkedData::Models::User)    
    end

TODO

codecov-commenter commented 1 year ago

Codecov Report

Merging #109 (4df8aae) into master (6b71451) will decrease coverage by 0.29%. The diff coverage is 43.33%.

@@            Coverage Diff             @@
##           master     #109      +/-   ##
==========================================
- Coverage   71.83%   71.53%   -0.30%     
==========================================
  Files          52       53       +1     
  Lines        2844     2874      +30     
==========================================
+ Hits         2043     2056      +13     
- Misses        801      818      +17     
Flag Coverage Δ
unittests 71.53% <43.33%> (-0.30%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
helpers/request_params_helper.rb 43.33% <43.33%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

syphax-bouazzouni commented 4 months ago

Close as I did not progress on this, and is not in our priorities for the coming months (the issue remain open here https://github.com/ontoportal-lirmm/ontologies_api/issues/2)