CSC/ECE 517 Spring 2022 - E2218: Refactor response controller: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:
== Modified Files and Refactorization ==
== Modified Files and Refactorization ==
A. '''response_controller.rb''' <br>
A. '''response_controller.rb''' <br>
1.  '''authorize_show_calibration_results'''
 
      This method is used to authorize if the user(reviewer) is allowed to view the calibration results for the corresponding ''calibration_response_map_id'' and ''review_response_map_id''  
  '''authorize_show_calibration_results'''
      passed as parameters in the URL.
  This method is used to authorize if the user(reviewer) is allowed to view the calibration results for the corresponding  
      Ex: https://expertiza.ncsu.edu/response/show_calibration_results_for_student?calibration_response_map_id=165688&review_response_map_id=165790
  ''calibration_response_map_id'' and ''review_response_map_id''  
      When someone tries to change the map_id's, the request should be authorized to check if the user can access the calibration result or not. <br>
  passed as parameters in the URL.
  Ex: https://expertiza.ncsu.edu/response/show_calibration_results_for_student?calibration_response_map_id=165688&review_response_map_id=165790
  When someone tries to change the map_id's, the request should be authorized to check if the user can access the calibration result or not. <br>
  [[File:Authorize_show_calibration_results.png|1180px|]]
 
  '''set_response'''
  @response and @map instance variables are initialized the same way across multiple methods.
  In order to avoid duplication, we created a before_action action which will be called first before calling the corresponding methods.
  [[File:Set_response_method.png|1170px|]]


      [[File:Authorize_show_calibration_results.png|1200px|]]


B. '''response_helper.rb''' <br>
B. '''response_helper.rb''' <br>
1 . Following methods are moved from the ''response_controller.rb'' class to ''response_helper.rb'' class since these methods are called from the controller action methods.
 
  Following methods are moved from the ''response_controller.rb'' class to ''response_helper.rb'' class since these methods are called from the  
  controller action methods.
     i) '''current_user_is_reviewer'''  
     i) '''current_user_is_reviewer'''  
     ii) '''sort_questions'''
     ii) '''sort_questions'''
Line 33: Line 42:
     iv) '''set_content''' <br>
     iv) '''set_content''' <br>
      
      
     [[File:Response_helper_1.png|1200px|]]
     [[File:Response_helper_1.png|1170px|]]


     [[File:Response_helper_2.png|1200px|]]
     [[File:Response_helper_2.png|1170px|]]


C. '''assignment_questionnaire.rb''' <br>
C. '''assignment_questionnaire.rb''' <br>
1. ''get_questions_by_assignment_id''
  '''get_questions_by_assignment_id'''
      Parameters : assignment_id  
  Parameters : assignment_id  
      When a user clicks on 'calibration results' from UI, questions in the assignment that has been reviewed are displayed.
  When a user clicks on 'calibration results' from UI, questions in the assignment that has been reviewed are displayed.
      A new method is added in the ''AssignmentQuestionnaire'' model class that returns the appropriate questions by querying the ''AssignmentQuestionnaire'' using the ''assignment_id''.
  A new method is added in the ''AssignmentQuestionnaire'' model class that returns the appropriate questions by querying the  
      This method is added to separate the business logic of retrieving the questions from the controller class.
  ''AssignmentQuestionnaire'' using the ''assignment_id''.
  This method is added to separate the business logic of retrieving the questions from the controller class.
      
      
    [[File: Get_questions_by_assignment_id.png|1200px|]]
  [[File: Get_questions_by_assignment_id.png|1170px|]]


D. '''awarded_badge.rb'''  <br>
D. '''awarded_badge.rb'''  <br>
1. ''award_badge''
  '''award_badge'''
    Parameters :  participant_id, badge_name
  Parameters :  participant_id, badge_name
    This method adds the ''badge_name'' to a specific ''participant_id'' in the AwardedBadges table.  
  This method adds the ''badge_name'' to a specific ''participant_id'' in the AwardedBadges table.  
    A separate method is created in the ''AwardedBadges'' model class to avoid the controller class from knowing the business logic of adding a badge name to a participant.
  A separate method is created in the ''AwardedBadges'' model class to avoid the controller class from knowing the business logic of adding a badge  
  name to a participant.
 
  [[File:RespControllerAwardBadge.png|1170px|]]


    [[File:RespControllerAwardBadge.png|1200px|]]
  [[File:AwardBadgeMethod.png|1170px|]]
 
    [[File:AwardBadgeMethod.png|1200px|]]
      
      
E. '''cake.rb'''  <br>
E. '''cake.rb'''  <br>
1. ''store_total_cake_score''
  '''store_total_cake_score'''
   This method clearly exposes the logic of retrieving the score for a cake question in the ''response_controller.rb'' class which is an incorrect design.   
   This method clearly exposes the logic of retrieving the score for a cake question in the ''response_controller.rb'' class which is an incorrect  
  design.   
   So, a model class method ''get_total_score_for_questions'' is added and the same logic of iterating over the Cake questions is moved there.
   So, a model class method ''get_total_score_for_questions'' is added and the same logic of iterating over the Cake questions is moved there.
   Return results for this method remains same here.
   Return results for this method remains same here.
 
   [[File:Cake.png|1170px|]]
   [[File:Cake.png|1200px|]]


F. '''response.rb'''  <br>
F. '''response.rb'''  <br>
1. ''calibration_results_info''
  '''calibration_results_info'''
    This method in ''response.rb'' model is completely removed because this method only adds more complexity to the model class.
  This method in ''response.rb'' model is completely removed because this method only adds more complexity to the model class.
    We refactored the method ''show_calibration_results_for_student'' in the ''response_controller.rb'' class.  
  We refactored the method ''show_calibration_results_for_student'' in the ''response_controller.rb'' class.  
    Previously, ''calibration_results_info'' was just doing nothing but getting responses using ''calibration_response_map_id'' and ''review_response_map_id'', and querying ''AssignmentQuestionnaire''.
  Previously, ''calibration_results_info'' was just doing nothing but getting responses using ''calibration_response_map_id'' and  
    Both of these operations can be done by using ''find'' method of model class and adding model class ''get_questions_by_assignment_id'' method.
  ''review_response_map_id'', and querying ''AssignmentQuestionnaire''.
  Both of these operations can be done by using ''find'' method of model class and adding model class ''get_questions_by_assignment_id'' method.


2. ''create_or_get_response''
  '''create_or_get_response'''
    Method name ''populate_new_response'' is changed to ''create_or_get_response'' to convey the functionality of the method.
  Method name ''populate_new_response'' is changed to ''create_or_get_response'' to convey the functionality of the method.
      
      
    [[File:Create_or_get_response.png|1200px|]]
  [[File:Create_or_get_response.png|1170px|]]
 
3. ''set_response''
    @response and @map instance variables are initialized the same way across multiple methods.
    In order to avoid duplication, we created a before_action action which will be called first before calling the corresponding methods.
 
    [[File:Set_response_method.png|1200px|]]


G. '''Code Climate issues''' <br>
G. '''Code Climate issues''' <br>
1. ''Update'' <br>
  '''Update'''
    <p> Made changes to split a line into multiple lines because it is too long. </p>
  Made changes to split a line into multiple lines because it is too long.
 
  [[File:Update_line_long.png|1170px|]]
    [[File:Update_line_long.png|1200px|]]
 
2. ''Create'' <br>
  '''Create'''
    <p> Made changes to split a line into multiple lines because it is too long. </p>
  Made changes to split a line into multiple lines because it is too long.
 
  [[File:Create_line_long.png|1170px|]]
    [[File:Create_line_long.png|1200px|]]
 


== Testing ==
== Testing ==

Revision as of 02:59, 22 March 2022

This page details project documentation for the CSC/ECE 517 Spring 2022, E2218 refactor response_controller.rb project.


Background

A response is the object that is created when someone fills out a review rubric, such as when one writes a review, gives feedback to a reviewer, or fills out a survey. Responses to the individual rubric items are kept in Answer objects; each Answer object has a response_id to say what Response it is part of. Since response_controller needs to work with many kinds of responses, its code is pretty general. It is not the worst controller in the system, but it would be much clearer if its method names were more descriptive of what they do.

Mentor

Ed Gehringer, efg@ncsu.edu

Team Members

  • Sai Naga Vamshi Chidara (schidar@ncsu.edu)
  • Akhil Kumar Mengani (amengan@ncsu.edu)
  • Samson Reddy Mulkur (smulkur@ncsu.edu)

Modified Files and Refactorization

A. response_controller.rb

  authorize_show_calibration_results
  This method is used to authorize if the user(reviewer) is allowed to view the calibration results for the corresponding 
  calibration_response_map_id and review_response_map_id 
  passed as parameters in the URL.
  Ex: https://expertiza.ncsu.edu/response/show_calibration_results_for_student?calibration_response_map_id=165688&review_response_map_id=165790
  When someone tries to change the map_id's, the request should be authorized to check if the user can access the calibration result or not. 
  set_response
  @response and @map instance variables are initialized the same way across multiple methods.
  In order to avoid duplication, we created a before_action action which will be called first before calling the corresponding methods.
  


B. response_helper.rb

  Following methods are moved from the response_controller.rb class to response_helper.rb class since these methods are called from the 
  controller action methods.
   i) current_user_is_reviewer 
   ii) sort_questions
   iii) store_total_cake_score
   iv) set_content 
   

C. assignment_questionnaire.rb

  get_questions_by_assignment_id
  Parameters : assignment_id 
  When a user clicks on 'calibration results' from UI, questions in the assignment that has been reviewed are displayed.
  A new method is added in the AssignmentQuestionnaire model class that returns the appropriate questions by querying the 
  AssignmentQuestionnaire using the assignment_id.
  This method is added to separate the business logic of retrieving the questions from the controller class.
    
  

D. awarded_badge.rb

  award_badge
  Parameters :  participant_id, badge_name
  This method adds the badge_name to a specific participant_id in the AwardedBadges table. 
  A separate method is created in the AwardedBadges model class to avoid the controller class from knowing the business logic of adding a badge 
  name to a participant.
  
  
  
   

E. cake.rb

  store_total_cake_score
  This method clearly exposes the logic of retrieving the score for a cake question in the response_controller.rb class which is an incorrect 
  design.  
  So, a model class method get_total_score_for_questions is added and the same logic of iterating over the Cake questions is moved there.
  Return results for this method remains same here.
  

F. response.rb

  calibration_results_info
  This method in response.rb model is completely removed because this method only adds more complexity to the model class.
  We refactored the method show_calibration_results_for_student in the response_controller.rb class. 
  Previously, calibration_results_info was just doing nothing but getting responses using calibration_response_map_id and 
  review_response_map_id, and querying AssignmentQuestionnaire.
  Both of these operations can be done by using find method of model class and adding model class get_questions_by_assignment_id method.
  create_or_get_response
  Method name populate_new_response is changed to create_or_get_response to convey the functionality of the method.
    
  

G. Code Climate issues

  Update
  Made changes to split a line into multiple lines because it is too long.
  
  
  Create
  Made changes to split a line into multiple lines because it is too long.
  

Testing

Running Tests

  rspec spec/models/responses_spec.rb
  rspec spec/controllers/questionnaires_controller_spec.rb

GitHub links and Pull Request

Link to Expertiza repository: here

Link to the forked repository: here

Link to Pull Request: here