<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jriehle</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jriehle"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jriehle"/>
	<updated>2026-08-08T08:25:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156933</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156933"/>
		<updated>2024-04-26T18:50:29Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Validate Parameters===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Separated Answer Creation and Update Logic===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Creation:&lt;br /&gt;
[[File:Postman after create for answer.png|900px]]&lt;br /&gt;
[[File:DB after create.png|900px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:Postman after update for answer.png|900px]]&lt;br /&gt;
[[File:DB after update.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156932</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156932"/>
		<updated>2024-04-26T18:43:29Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Validate Parameters===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Separated Answer Creation and Update Logic===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Creation:&lt;br /&gt;
[[File:Postman after create for answer.png|900px]]&lt;br /&gt;
[[File:DB after create.png|900px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:Postman after update for answer.png|900px]]&lt;br /&gt;
[[File:DB after update.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156931</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156931"/>
		<updated>2024-04-26T17:09:03Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Validate Parameters===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Separated Answer Creation and Update Logic===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Creation:&lt;br /&gt;
[[File:Postman after create for answer.png|900px]]&lt;br /&gt;
[[File:DB after create.png|900px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:Postman after update for answer.png|900px]]&lt;br /&gt;
[[File:DB after update.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156798</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156798"/>
		<updated>2024-04-24T03:50:22Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Response model test===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Validate Parameters : &lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Response model test===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Responses Controller test===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://youtu.be/EWxvSC9hPtU&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156695</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156695"/>
		<updated>2024-04-24T03:18:54Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156683</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156683"/>
		<updated>2024-04-24T03:14:47Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156681</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156681"/>
		<updated>2024-04-24T03:14:33Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156680</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156680"/>
		<updated>2024-04-24T03:14:26Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
 create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156667</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156667"/>
		<updated>2024-04-24T03:09:00Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Solutions/Details of Changes Made */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156619</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156619"/>
		<updated>2024-04-24T02:39:59Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/moZrjXE-dM8&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156390</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=156390"/>
		<updated>2024-04-24T00:59:19Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/EPoD3ai33qk&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155971</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155971"/>
		<updated>2024-04-23T05:15:15Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Show_calibration_results_for_student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155970</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155970"/>
		<updated>2024-04-23T05:14:39Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Show_calibration_results_for_student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student reimplimented.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155968</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155968"/>
		<updated>2024-04-23T05:14:14Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Show_calibration_results_for_student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student reimplemented.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155967</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155967"/>
		<updated>2024-04-23T05:13:54Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Show_calibration_results_for_student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student reimplementation.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results_for_student_reimplimented.PNG&amp;diff=155958</id>
		<title>File:Show calibration results for student reimplimented.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results_for_student_reimplimented.PNG&amp;diff=155958"/>
		<updated>2024-04-23T04:50:21Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_access_in_view_2.PNG&amp;diff=155957</id>
		<title>File:DB access in view 2.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_access_in_view_2.PNG&amp;diff=155957"/>
		<updated>2024-04-23T04:48:53Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_access_in_view.PNG&amp;diff=155956</id>
		<title>File:DB access in view.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_access_in_view.PNG&amp;diff=155956"/>
		<updated>2024-04-23T04:48:36Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results_for_student.PNG&amp;diff=155955</id>
		<title>File:Show calibration results for student.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results_for_student.PNG&amp;diff=155955"/>
		<updated>2024-04-23T04:48:25Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155946</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155946"/>
		<updated>2024-04-23T04:27:48Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
==== Create ====&lt;br /&gt;
==== Show ====&lt;br /&gt;
==== Update ====&lt;br /&gt;
==== Delete ====&lt;br /&gt;
==== Questionnaire_from_response_map and Questionnaire_from_response ====&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
==== Init_answers ====&lt;br /&gt;
==== Save ====&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly.  &lt;br /&gt;
&lt;br /&gt;
Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.  &lt;br /&gt;
&lt;br /&gt;
Unit tests will be written for the following model functions:&lt;br /&gt;
 *set_content&lt;br /&gt;
 *validate_params&lt;br /&gt;
 *serialize_response&lt;br /&gt;
&lt;br /&gt;
Unit tests will also be written for the controller functions:&lt;br /&gt;
 *Create&lt;br /&gt;
 *Show&lt;br /&gt;
 *Update&lt;br /&gt;
 *Delete&lt;br /&gt;
 *Questionnaire_from_response_map&lt;br /&gt;
 *Questionnaire_from_response&lt;br /&gt;
 *Create_answers&lt;br /&gt;
 *Show_calibration_results_for_student&lt;br /&gt;
 *Init_answers&lt;br /&gt;
 *Save&lt;br /&gt;
&lt;br /&gt;
The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155371</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155371"/>
		<updated>2024-04-09T00:56:40Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* 8. Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Implementation==&lt;br /&gt;
===4.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 4.1.1 set_content&lt;br /&gt;
* 4.1.2 validate_params&lt;br /&gt;
* 4.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 4.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 4.2.1 Create&lt;br /&gt;
* 4.2.2 Show&lt;br /&gt;
* 4.2.3 Update&lt;br /&gt;
* 4.2.4 Delete&lt;br /&gt;
* 4.2.5 Questionnaire_from_response_map &lt;br /&gt;
* 4.2.6 Questionnaire_from_response &lt;br /&gt;
* 4.2.7 Create_answers&lt;br /&gt;
* 4.2.8 Show_calibration_results_for_student&lt;br /&gt;
* 4.2.9 Init_answers&lt;br /&gt;
* 4.2.10 Save&lt;br /&gt;
&lt;br /&gt;
==5. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==6. Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly.  &lt;br /&gt;
&lt;br /&gt;
1. Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.  &lt;br /&gt;
&lt;br /&gt;
 Unit tests will be written for the following model functions:&lt;br /&gt;
 * set_content&lt;br /&gt;
 * validate_params&lt;br /&gt;
 * serialize_response&lt;br /&gt;
&lt;br /&gt;
 Unit tests will also be written for the controller functions:&lt;br /&gt;
 * Create&lt;br /&gt;
 * Show&lt;br /&gt;
 * Update&lt;br /&gt;
 * Delete&lt;br /&gt;
 * Questionnaire_from_response_map&lt;br /&gt;
 * Questionnaire_from_response&lt;br /&gt;
 * Create_answers&lt;br /&gt;
 * Show_calibration_results_for_student&lt;br /&gt;
 * Init_answers&lt;br /&gt;
 * Save&lt;br /&gt;
&lt;br /&gt;
2. The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Team==&lt;br /&gt;
=====7.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====7.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==8. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155362</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155362"/>
		<updated>2024-04-09T00:50:44Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Implementation==&lt;br /&gt;
===4.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 4.1.1 set_content&lt;br /&gt;
* 4.1.2 validate_params&lt;br /&gt;
* 4.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 4.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 4.2.1 Create&lt;br /&gt;
* 4.2.2 Show&lt;br /&gt;
* 4.2.3 Update&lt;br /&gt;
* 4.2.4 Delete&lt;br /&gt;
* 4.2.5 Questionnaire_from_response_map &lt;br /&gt;
* 4.2.6 Questionnaire_from_response &lt;br /&gt;
* 4.2.7 Create_answers&lt;br /&gt;
* 4.2.8 Show_calibration_results_for_student&lt;br /&gt;
* 4.2.9 Init_answers&lt;br /&gt;
* 4.2.10 Save&lt;br /&gt;
&lt;br /&gt;
==5. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==6. Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly.  &lt;br /&gt;
&lt;br /&gt;
1. Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.  &lt;br /&gt;
&lt;br /&gt;
 Unit tests will be written for the following model functions:&lt;br /&gt;
 * set_content&lt;br /&gt;
 * validate_params&lt;br /&gt;
 * serialize_response&lt;br /&gt;
&lt;br /&gt;
 Unit tests will also be written for the controller functions:&lt;br /&gt;
 * Create&lt;br /&gt;
 * Show&lt;br /&gt;
 * Update&lt;br /&gt;
 * Delete&lt;br /&gt;
 * Questionnaire_from_response_map&lt;br /&gt;
 * Questionnaire_from_response&lt;br /&gt;
 * Create_answers&lt;br /&gt;
 * Show_calibration_results_for_student&lt;br /&gt;
 * Init_answers&lt;br /&gt;
 * Save&lt;br /&gt;
&lt;br /&gt;
2. The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Team==&lt;br /&gt;
=====7.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====7.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==8. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request:&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=155361</id>
		<title>CSC/ECE 517 Spring 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024&amp;diff=155361"/>
		<updated>2024-04-09T00:49:55Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Spring 2024 - E2401 Implementing and testing import &amp;amp; export controllers]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2405 Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2407 Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2428 Replicate Roles and Institution UIs ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2429 Reimplement student_task list]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2430 Reimplement student_task view]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2410. View for Results of Bidding ]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2414 Grading Audit Trail]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - NTNX-1 : Extend NDB Operator to Support Postgres HA]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - ‬NTNX-2‬‭ : Snapshot Functionality for provisioned databases]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2411 : Fix &amp;quot;Back&amp;quot; link on “New Late Policy” page]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2416.  Reimplement the Question hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2420. Reimplement student_quizzes_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2424. Reimplement the Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2426. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb (Phase 2)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2425. Create a Courses user interface in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2431. Reimplement  grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2404 Refactor student teams functionality]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2406 Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2403 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2421. Reimplement impersonating users (within impersonate controller.rb)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2413. Testing - Answer Tagging]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2412. Testing for hamer.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2427. UI for questionnaire.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2419. Reimplement duties controller.rb and badges controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2432. UI for Participants.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - G2402 Implement REST client, REST API, and Graphql API endpoint for repositories]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - G2400 DevOp for GitHub Miner app]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2439 Testing for view_translation_substitutor.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2443 Reimplement grades_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2434 Reimplement Frontend for the Grades view]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2435 Implement Frontend for the My Profile]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2446 Implement Front End for Student Task List]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2444 Implement Frontend for the Review]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2440 Testing for questionnaire_helper, review_bids_helper]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2433 Implement UI for the Student Teams]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)]]&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155356</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155356"/>
		<updated>2024-04-09T00:46:51Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Implementation==&lt;br /&gt;
===4.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 4.1.1 set_content&lt;br /&gt;
* 4.1.2 validate_params&lt;br /&gt;
* 4.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 4.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 4.2.1 Create&lt;br /&gt;
* 4.2.2 Show&lt;br /&gt;
* 4.2.3 Update&lt;br /&gt;
* 4.2.4 Delete&lt;br /&gt;
* 4.2.5 Questionnaire_from_response_map &lt;br /&gt;
* 4.2.6 Questionnaire_from_response &lt;br /&gt;
* 4.2.7 Create_answers&lt;br /&gt;
* 4.2.8 Show_calibration_results_for_student&lt;br /&gt;
* 4.2.9 Init_answers&lt;br /&gt;
* 4.2.10 Save&lt;br /&gt;
&lt;br /&gt;
==5. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==6. Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly.  &lt;br /&gt;
&lt;br /&gt;
1. Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.  &lt;br /&gt;
&lt;br /&gt;
 Unit tests will be written for the following model functions:&lt;br /&gt;
 * set_content&lt;br /&gt;
 * validate_params&lt;br /&gt;
 * serialize_response&lt;br /&gt;
&lt;br /&gt;
 Unit tests will also be written for the controller functions:&lt;br /&gt;
 * Create&lt;br /&gt;
 * Show&lt;br /&gt;
 * Update&lt;br /&gt;
 * Delete&lt;br /&gt;
 * Questionnaire_from_response_map&lt;br /&gt;
 * Questionnaire_from_response&lt;br /&gt;
 * Create_answers&lt;br /&gt;
 * Show_calibration_results_for_student&lt;br /&gt;
 * Init_answers&lt;br /&gt;
 * Save&lt;br /&gt;
&lt;br /&gt;
2. The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Test Coverage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Team==&lt;br /&gt;
=====7.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====7.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==8. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request:&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155180</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=155180"/>
		<updated>2024-04-08T22:28:39Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* 7. Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
The redesign of the `responses_controller.rb` is guided by several key objectives to improve the code quality, system behavior, and developer interaction. The goals include:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Ensuring the code is easy to understand, modify, and extend. The reimplementation should simplify future updates and feature additions.&lt;br /&gt;
&lt;br /&gt;
* Adherence to Rails Best Practices: Following Rails conventions for naming, structure, and coding practices to ensure code consistency and reliability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - removing redundant code and logic to create a more efficient and error-resistant codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Restructuring the controller and associated models so that each class and method has one purpose and one purpose only, leading to easier testing and management.&lt;br /&gt;
&lt;br /&gt;
* Improved Testing and Coverage: Enhancing test suites to cover more scenarios and edge cases, increasing confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Identifying and optimizing slow or inefficient areas in the code to ensure the application runs smoothly.&lt;br /&gt;
&lt;br /&gt;
* Clean Up Dead Methods: Audit the codebase for any unused (&amp;quot;dead&amp;quot;) methods within the current controller and remove them to declutter the code.&lt;br /&gt;
&lt;br /&gt;
* Reduced Controller Complexity: We already have streamline the `ResponseController` to focus primarily on CRUD operations and extract non-essential logic to appropriate models or helpers, now we aim to implement the rest operations.&lt;br /&gt;
&lt;br /&gt;
By meeting these design goals, the project aims to produce a `responses_controller.rb` that is robust, efficient, and a pleasure to work with, both for the current development team and for those who will maintain the system in the future.&lt;br /&gt;
&lt;br /&gt;
==4.Class UML Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Implementation==&lt;br /&gt;
===5.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 5.1.1 set_content&lt;br /&gt;
* 5.1.2 validate_params&lt;br /&gt;
* 5.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 5.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 5.2.1 Create&lt;br /&gt;
* 5.2.2 Show&lt;br /&gt;
* 5.2.3 Update&lt;br /&gt;
* 5.2.4 Delete&lt;br /&gt;
* 5.2.5 Questionnaire_from_response_map &lt;br /&gt;
* 5.2.6 Questionnaire_from_response &lt;br /&gt;
* 5.2.7 Create_answers&lt;br /&gt;
* 5.2.8 Show_calibration_results_for_student&lt;br /&gt;
* 5.2.9 Init_answers&lt;br /&gt;
* 5.2.10 Save&lt;br /&gt;
&lt;br /&gt;
==6. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Test Plan==&lt;br /&gt;
&lt;br /&gt;
The Model and Controller functions will be tested throughoughly.  &lt;br /&gt;
&lt;br /&gt;
1. Rspec unit tests will be used to test each function of the refactored and reimplemented functions to verify the expected responses are received for given inputs.  &lt;br /&gt;
&lt;br /&gt;
  Unit tests will be written for the following model functions:&lt;br /&gt;
  set_content&lt;br /&gt;
  validate_params&lt;br /&gt;
  serialize_response&lt;br /&gt;
&lt;br /&gt;
  Unit tests will also be written for the controller functions:&lt;br /&gt;
  Create&lt;br /&gt;
  Show&lt;br /&gt;
  Update&lt;br /&gt;
  Delete&lt;br /&gt;
  Questionnaire_from_response_map&lt;br /&gt;
  Questionnaire_from_response&lt;br /&gt;
  Create_answers&lt;br /&gt;
  Show_calibration_results_for_student&lt;br /&gt;
  Init_answers&lt;br /&gt;
  Save&lt;br /&gt;
&lt;br /&gt;
2. The Swagger UI will be utilized to make the controller functions accessible VIA API calls.  This will allow for testing of the input and outputs of the API calls to the methods, and will function as integration tests.&lt;br /&gt;
&lt;br /&gt;
==Test Coverage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==8. Team==&lt;br /&gt;
=====8.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====8.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==9. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request:&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=154963</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=154963"/>
		<updated>2024-04-08T02:42:12Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* 1.Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
The Expertiza project, an open-source endeavor rooted in Ruby on Rails, embarks on continuous improvement to adapt and integrate modern software engineering practices. The Responses Controller is engineered to assist reviewers in submitting structured data that is specifically aligned with an assignment's rubrics, ensuring the provision of relevant questions for each round within the correct due date period. It enables a reviewer to evaluate and score the rubric questions pertinent to the assignment's topics. Furthermore, it ensures the delivery of appropriate questions for each assignment round, allowing reviewers to create and modify scores and comments for each of the rubric questions associated with the assignment. After reviewers submit their scored questions and comments, the Responses Controller dispatches an email notification to the instructor and the reviewed team's members.&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
&lt;br /&gt;
==4.Class UML Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Implementation==&lt;br /&gt;
===5.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 5.1.1 set_content&lt;br /&gt;
* 5.1.2 validate_params&lt;br /&gt;
* 5.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 5.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 5.2.1 Create&lt;br /&gt;
* 5.2.2 Show&lt;br /&gt;
* 5.2.3 Update&lt;br /&gt;
* 5.2.4 Delete&lt;br /&gt;
&lt;br /&gt;
==6. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Test Plan==&lt;br /&gt;
&lt;br /&gt;
===Testing model methods===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Coverage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==8. Team==&lt;br /&gt;
=====8.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====8.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==9. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request:&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=154962</id>
		<title>CSC/ECE 517 Spring 2024 - E2415. Reimplement responses controller.rb (Design Document)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2415._Reimplement_responses_controller.rb_(Design_Document)&amp;diff=154962"/>
		<updated>2024-04-08T02:41:22Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* 2.Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Spring 2024 - E2415: Reimplementation of responses_controller.rb (Design Document)&lt;br /&gt;
&lt;br /&gt;
==1.Expertiza==&lt;br /&gt;
&lt;br /&gt;
==2.Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a legacy system with conventions predating Rails standards, is overly complex, encompassing functionalities beyond basic CRUD operations and needing adherence to modern Rails naming and design principles. Key issues include the direct implementation of functionalities like sorting reviews and checking reviewer roles within the controller, suggesting a shift towards polymorphism and a more structured approach to code organization. Furthermore, the controller's handling of email notifications and feedback mechanisms is inconsistent, indicating the necessity for a dedicated helper to streamline communication processes. The reimplementation effort must focus on simplifying the controller, adhering to Rails conventions, and improving code readability and maintainability by appropriately distributing responsibilities.&lt;br /&gt;
&lt;br /&gt;
==3.Design Goal==&lt;br /&gt;
&lt;br /&gt;
==4.Class UML Diagram==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Implementation==&lt;br /&gt;
===5.1 Model ===&lt;br /&gt;
Methods within the model were refactored or introduced, including:&lt;br /&gt;
* 5.1.1 set_content&lt;br /&gt;
* 5.1.2 validate_params&lt;br /&gt;
* 5.1.3 serialize_response&lt;br /&gt;
&lt;br /&gt;
=== 5.2 Controller ===&lt;br /&gt;
Controller methods for CRUD operations were enhanced, comprising:&lt;br /&gt;
* 5.2.1 Create&lt;br /&gt;
* 5.2.2 Show&lt;br /&gt;
* 5.2.3 Update&lt;br /&gt;
* 5.2.4 Delete&lt;br /&gt;
&lt;br /&gt;
==6. Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==7. Test Plan==&lt;br /&gt;
&lt;br /&gt;
===Testing model methods===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Coverage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==8. Team==&lt;br /&gt;
=====8.1 Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====8.2 Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Jacob Leavitt&lt;br /&gt;
&lt;br /&gt;
==9. Links==&lt;br /&gt;
Swagger Video Link:&lt;br /&gt;
&lt;br /&gt;
Pull request:&lt;br /&gt;
&lt;br /&gt;
Model Tests Video:&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video:&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2427._UI_for_questionnaire.rb&amp;diff=154333</id>
		<title>CSC/ECE 517 Spring 2024 - E2427. UI for questionnaire.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_-_E2427._UI_for_questionnaire.rb&amp;diff=154333"/>
		<updated>2024-03-25T01:38:10Z</updated>

		<summary type="html">&lt;p&gt;Jriehle: /* Contributors to this project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview of Expertiza ==&lt;br /&gt;
Expertiza, constructed using Ruby on Rails, is an open-source learning management system that offers a diverse array of features. These include the ability to generate assignments, tests, assignment teams, and courses. Notably, it excels in providing a comprehensive peer review system, fostering thorough feedback within teams and among group members. The central focus of the project revolves around enhancing the frontend components related to the Questionnaire. A specific challenge being tackled involves restructuring the current non-Typescript questionnaire UI to incorporate Typescript. Consequently, the team's task is to craft the User Interface for these components using React.js and Typescript.&lt;br /&gt;
&lt;br /&gt;
== Description of the Project ==&lt;br /&gt;
&lt;br /&gt;
* Objective: Refactor the non-Typescript frontend questionnaire UI of Expertiza to use Typescript and develop the User Interface using React.js and Typescript.&lt;br /&gt;
&lt;br /&gt;
* Key Tasks:&lt;br /&gt;
** Log in as a Super Admin.&lt;br /&gt;
** Replicate the 'Administration' and 'Institution' UIs using ReactJS, ensuring they retain full functionality within the new TypeScript and ReactJS framework.&lt;br /&gt;
&lt;br /&gt;
* Development Process:&lt;br /&gt;
** Understand the Existing System: Analyze the current Ruby on Rails implementation of Questionnaire UIs, including data models, controllers, and views.&lt;br /&gt;
** Setup Development Environment: Establish a TypeScript and ReactJS environment for developing the new UIs.&lt;br /&gt;
** Design Components: Create React components corresponding to UI parts, focusing on state and props management.&lt;br /&gt;
** Implement Components: Develop these components in TypeScript, mirroring the existing UIs' functionality.&lt;br /&gt;
** Integrate Components: Incorporate the new components into the main application, ensuring compatibility and functionality with the backend.&lt;br /&gt;
** Review and Refactor: Enhance code quality through reviews and refactoring, emphasizing readability and efficiency.&lt;br /&gt;
&lt;br /&gt;
* Additional Features and Improvements:&lt;br /&gt;
** Enhance UI with tooltips, improved table positioning, and pagination.&lt;br /&gt;
** Introduce a new search functionality to search for questionnaires based on the query.&lt;br /&gt;
** Introduce the sorting functionality to sort questionnaires based on the query.&lt;br /&gt;
** Enhance code quality by adding comments, removing obsolete code, and implementing form validations.&lt;br /&gt;
&lt;br /&gt;
* Outcome: The project aims to transition the Expertiza UI component for 'Questionnaire' from Ruby on Rails to a more modern, efficient TypeScript and ReactJS-based implementation, incorporating user role restrictions and various UI improvements for a better user experience.&lt;br /&gt;
&lt;br /&gt;
== Technologies Used ==&lt;br /&gt;
&lt;br /&gt;
* '''React.js''': A JavaScript library for building user interfaces, particularly single-page applications. React will be used to develop dynamic and responsive UI components.&lt;br /&gt;
&lt;br /&gt;
* '''TypeScript''': An open-source language that builds on JavaScript by adding static type definitions. TypeScript allows for writing clearer and more robust code, facilitating easier debugging and maintenance.&lt;br /&gt;
&lt;br /&gt;
* '''Ruby on Rails''': Although the focus is on refactoring the front end, understanding the existing Ruby on Rails backend is crucial. Rails is a server-side web application framework written in Ruby, following the model-view-controller (MVC) framework.&lt;br /&gt;
&lt;br /&gt;
== Changes Made ==&lt;br /&gt;
&lt;br /&gt;
1. '''Refactored the Questionnaire UI''': The transition of the questionnaire UI frontend from its original non-TypeScript state to now fully incorporating TypeScript has been completed successfully, enhancing the code's reliability and ease of maintenance.&lt;br /&gt;
&lt;br /&gt;
2. '''Developed with React.js and Typescript''': The 'Questionnarie' user interface have been rebuilt using React.js and Typescript, ensuring dynamic and responsive behavior. The React components created are modular, reusable, and effectively manage state.&lt;br /&gt;
&lt;br /&gt;
3. '''Analyzed Existing Backend''': An in-depth analysis and comprehension of the current Ruby on Rails backend were attained to ensure the seamless integration and functionality with the new TypeScript and React.js frontend.&lt;br /&gt;
&lt;br /&gt;
4. '''UI Enhancements Implemented''': &lt;br /&gt;
a. The UI has been updated to match the rest of the Expertiza APP. &lt;br /&gt;
b. Buttons to edit and delete table entries are included inline.  &lt;br /&gt;
c. A button to add new entries is added above and on the right of the table. &lt;br /&gt;
d. Pagination is included for the table to accommodate multiple questionnaires.&lt;br /&gt;
e. Added the search functionality on top of the table to search for a particular Questionnarie.&lt;br /&gt;
f. Clicking the button to add a new questionnaire opens a pop up box to fill in the name of the new Questionnarie.&lt;br /&gt;
g. Added the functionality to sort the surveys alphabetically (Name wise) in ascending or descending order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. '''Enhancements in Code Quality and Maintenance''':&lt;br /&gt;
Thorough documentation and detailed comments have been incorporated into the new codebase to enhance readability and facilitate ongoing maintenance.&lt;br /&gt;
Obsolete or redundant code segments have been systematically removed, optimizing the application's efficiency.&lt;br /&gt;
Validators and robust error-handling mechanisms have been integrated to fortify the UI's resilience.&lt;br /&gt;
&lt;br /&gt;
7. '''Comprehensive Testing and Seamless Integration''': &lt;br /&gt;
The new UI components underwent rigorous testing, both in isolation and within the application's operational framework, ensuring precise functionality across diverse scenarios and datasets.&lt;br /&gt;
Seamless integration of the new components into the existing application infrastructure was meticulously executed to uphold compatibility and operational coherence.&lt;br /&gt;
&lt;br /&gt;
8. '''Review and Deployment Accomplished''':&lt;br /&gt;
Collaborative code reviews were conducted with the development team to identify and implement potential enhancements or essential adjustments.&lt;br /&gt;
The deployment of the updated application was meticulously prepared and executed, guaranteeing a seamless transition devoid of disruptions to the existing user base.&lt;br /&gt;
&lt;br /&gt;
== UI Enhancements and Features in Screenshots ==&lt;br /&gt;
&lt;br /&gt;
The UI has been updated to match the rest of the Expertiza APP. &lt;br /&gt;
[[File:UI.jpeg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;UI looks similar to Expertiza with Pagination at bottom&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Button to 'Edit' and 'Delete' were added inline. Also Added 'Tooltips' to 'Edit' and 'Delete' as well as 'Create New Questionnarie' Buttons.&lt;br /&gt;
&lt;br /&gt;
  [[File:Edit-questionnarie.jpeg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  [[File:Delete-questionnarie.jpeg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Delete Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  [[File:Questionnarie.jpeg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;New Questionnarie Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adding a new questionnaire, editing an existing questionnaire ,or deleting a questionnaire results in a pop-up box to perform respective individual functionality&lt;br /&gt;
[[File:new-survey.jpeg |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;New questionnaire Pop-up Box&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:edit-survey.jpeg |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit questionnaire Pop-up Box&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:delete-survey.jpeg |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Delete questionnaire Pop-up Box&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Added the search functionality on top of the table to search for a particular questionnaire.&lt;br /&gt;
[[File:Search-bar.jpeg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Search Bar search for matching questionnaire&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sorting the Questionnaires Alphabetically (Ascending as well as Descending)&lt;br /&gt;
[[File:sort.jpeg |300px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Sorting questionnaire functionality&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
Testing was initially excluded from the project's scope, as the focus was on frontend development. Nevertheless, ensuring the functionality and user experience of a website's interface is crucial. Therefore, manual testing procedures will be used to validate the correct operation of the UI components. These procedures include:&lt;br /&gt;
&lt;br /&gt;
# Verifying all the added button links to ensure they function correctly.&lt;br /&gt;
# Testing whether the Search Bar accurately searches the matching questionnaire.&lt;br /&gt;
# Testing whether sorting functionality displays the result in correct ascending and descending order.&lt;br /&gt;
&lt;br /&gt;
== Contributors to this project ==&lt;br /&gt;
* '''Mitesh Agarwal''' (unityid: magarwa3, github: mitesh24100)&lt;br /&gt;
* '''Jeff Riehle''' (unityid: jriehle, github: jriehle)&lt;br /&gt;
* '''Shubham Loya''' (unityid: ssloya, github: crmgogo)&lt;br /&gt;
* '''Github repo''' https://github.com/jriehle/reimplementation-front-end&lt;br /&gt;
* '''Link to PR''' https://github.com/expertiza/reimplementation-front-end/pull/41&lt;/div&gt;</summary>
		<author><name>Jriehle</name></author>
	</entry>
</feed>