CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 27: Line 27:
=== Model set_content method ===
=== Model set_content method ===
We eliminated the new_response variable as the model setup can be autonomously determined by the get method. This change improves error handling for scenarios where required parameters are not received. Additionally, we removed function calls related to the view page and introduced a new function, get_items, which identifies the relevant questions for the Response model.
We eliminated the new_response variable as the model setup can be autonomously determined by the get method. This change improves error handling for scenarios where required parameters are not received. Additionally, we removed function calls related to the view page and introduced a new function, get_items, which identifies the relevant questions for the Response model.
[[File:Set content.jpg|1300px]]
[[File:Set content.jpg|1300px]]
=== Model validate_params method ===
=== Model validate_params method ===
The validate_params method verifies whether the request data contains the necessary information to create or update the Response model. It assesses if the received data can lead to the creation of a new model or update an existing one, based on the response_id, round, and num_review values provided in the request. Upon evaluation, it responds with a corresponding HTTP status code and message.
The validate_params method verifies whether the request data contains the necessary information to create or update the Response model. It assesses if the received data can lead to the creation of a new model or update an existing one, based on the response_id, round, and num_review values provided in the request. Upon evaluation, it responds with a corresponding HTTP status code and message.
[[File:Validate params.jpg|1300px]]
[[File:Validate params.jpg|1300px]]
=== Model serialize_response method ===
=== Model serialize_response method ===
The new method "serialize_response" eliminates the need to manage the order of items and offers a structured representation of the model for easier management.
The new method "serialize_response" eliminates the need to manage the order of items and offers a structured representation of the model for easier management.
[[File:Serialize response.jpg|500px]]
[[File:Serialize response.jpg|500px]]
=== Controller CRUD Actions ===
=== Controller CRUD Actions ===
The ResponseController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods.To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application. A key area of improvement has been minimizing the reliance on chaining method calls that span across various Active Record models. This practice, while common, posed significant risks to the ResponseController's stability, particularly if a function invoked from another model were to be updated.
The ResponseController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods.To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application. A key area of improvement has been minimizing the reliance on chaining method calls that span across various Active Record models. This practice, while common, posed significant risks to the ResponseController's stability, particularly if a function invoked from another model were to be updated.
Our focus has now shifted to refining the core CRUD actions of the Response API, along with developing essential helper functions that facilitate these operations. This approach aims to ensure a more robust, maintainable, and efficient system. EX: Create and Update Actions
Our focus has now shifted to refining the core CRUD actions of the Response API, along with developing essential helper functions that facilitate these operations. This approach aims to ensure a more robust, maintainable, and efficient system. EX: Create and Update Actions.
 
[[File:Responses controller.jpg|1200px]]
[[File:Responses controller.jpg|1200px]]



Revision as of 15:32, 24 March 2024

This wiki page is for information regarding the changes made for the E2415. Reimplementation of responses controller.rb OSS assignment for Spring 2024, CSC/ECE 517.

Introduction

The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. A recent initiative under CSC/ECE 517 Spring 2024 - E2415, mentored by Ameya Vaichalkar, focused on the reimagination of the responses_controller.rb. This documentation encapsulates the efforts and methodologies employed in the reimplementation process, aligning with Rails' conventions and enhancing the application's functionality and maintainability.

Problem Description

The current ResponseController is notably lengthy and encompasses more than the essential CRUD operations. Notably, the edit method includes functionality for sorting reviews, a task that could be more appropriately handled within the Response model. The controller employs several methods, such as assign_action_parameters and set_content, to set parameters. While these methods help avoid code duplication, a more streamlined approach could further ensure that client methods readily access the required objects. The questionnaire_from_response_map method identifies the evaluation tool type—rubric, quiz, or survey—and adapts the review rubric based on the topic, indicating potential for simplification despite its complexity.

Reimplementation Objectives

The project's core objectives were manifold, aiming not only to adhere to contemporary Rails naming conventions but also to streamline and refactor the existing ResponseController for better clarity, functionality, and adherence to best practices. Key focus areas included:

1. Show_response: allow rendering json format for a response including an associated response_map and answers.

2. Create_response: create a new response model with associated answers.

3. Update_response: update an existing response model with associated answers.

4. Delete_response: delete an existing response model with associated answers.

5. Create answer blanks and Sort answers: We introduced a new sorting method “serialize_response” that formats response model structure to resolve the sort answers with question type.

6. Reimplement questionnaire_from_response and questionnaire_from_response_map: We introduced a new method “get_questionnaire” function that takes a response model as a parameter so that it identifies the questionnaire based on questionnaire type, signed up team, current round, version number, and due date. However there is a difficult to test it due to the chained functions throughout the related models, and no sufficient models provided.

Method Reimplemented

The ResponsesController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods. To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application.

Model set_content method

We eliminated the new_response variable as the model setup can be autonomously determined by the get method. This change improves error handling for scenarios where required parameters are not received. Additionally, we removed function calls related to the view page and introduced a new function, get_items, which identifies the relevant questions for the Response model.

Model validate_params method

The validate_params method verifies whether the request data contains the necessary information to create or update the Response model. It assesses if the received data can lead to the creation of a new model or update an existing one, based on the response_id, round, and num_review values provided in the request. Upon evaluation, it responds with a corresponding HTTP status code and message.

Model serialize_response method

The new method "serialize_response" eliminates the need to manage the order of items and offers a structured representation of the model for easier management.

Controller CRUD Actions

The ResponseController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods.To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application. A key area of improvement has been minimizing the reliance on chaining method calls that span across various Active Record models. This practice, while common, posed significant risks to the ResponseController's stability, particularly if a function invoked from another model were to be updated. Our focus has now shifted to refining the core CRUD actions of the Response API, along with developing essential helper functions that facilitate these operations. This approach aims to ensure a more robust, maintainable, and efficient system. EX: Create and Update Actions.

Email Notification Refinement

Email-related methods were consolidated into the ResponseHelper, with new constructs like EmailObject and Mailer introduced for better organization.

Questionnaire Determination Simplification

Design and Additional Implementation Details

  • Controller Renaming: The controller was renamed to responses_controller.rb, aligning with Rails conventions.
  • Response Helper: During the reimplementation, the team employed various design patterns and refactoring strategies to achieve a cleaner, more maintainable codebase. We developed a response helper file serving as service logic to facilitate essential functions for processing the "set_content" and "validate_params" methods in the Response model, as well as supporting CRUD actions in the Responses controller.

File(s) Modified

  • responses_controller.rb (new)
  • response_helper.rb (new)
  • response.rb
  • 20240305170836_add_column_type_response_maps.rb
  • 20240312235330_add_columns_to_participant.rb

Test Plan and Coverage

The project adopted Test-Driven Development (TDD) principles, ensuring that each new feature and refactoring effort was accompanied by comprehensive test cases. This approach not only facilitated the detection of potential issues early in the development cycle but also contributed to a robust and reliable codebase. Test coverage metrics were carefully monitored, with significant improvements observed in both the breadth and depth of the testing suite.

Response model test

Response controller test

Relevant Links

  • GitHub Repository: Expertiza GitHub
  • Pull Requests: Detailed pull request for the reimplementation can be viewed here.

Team

Mentor

  • Ameya Vaichalkar (ameyav)

Contributors

  • Deana Franks
  • Maday Moya
  • Jacob Leavitt