Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

syphax-bouazzouni
Copy link

@syphax-bouazzouni syphax-bouazzouni commented Dec 18, 2022

Goal

see ontoportal-lirmm#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
Copy link

codecov-commenter commented Dec 18, 2022

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%) ⬇️

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 syphax-bouazzouni changed the title Refactor: The first brick of a harmonized way to get request params Refactor: The first brick of an harmonized way to get request params Jan 17, 2023
@syphax-bouazzouni
Copy link
Author

Close as I did not progress on this, and is not in our priorities for the coming months (the issue remain open here ontoportal-lirmm#2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants