<?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=Mmoyape</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=Mmoyape"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Mmoyape"/>
	<updated>2026-05-06T09:03:19Z</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=156814</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=156814"/>
		<updated>2024-04-24T03:58:24Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Test */&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://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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_create_for_answer.png&amp;diff=156812</id>
		<title>File:Postman after create for answer.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_create_for_answer.png&amp;diff=156812"/>
		<updated>2024-04-24T03:56:59Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_update_for_answer.png&amp;diff=156810</id>
		<title>File:Postman after update for answer.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_update_for_answer.png&amp;diff=156810"/>
		<updated>2024-04-24T03:56:36Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_after_update.png&amp;diff=156808</id>
		<title>File:DB after update.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_after_update.png&amp;diff=156808"/>
		<updated>2024-04-24T03:55:46Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_after_create.png&amp;diff=156806</id>
		<title>File:DB after create.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_after_create.png&amp;diff=156806"/>
		<updated>2024-04-24T03:55:36Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</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=156792</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=156792"/>
		<updated>2024-04-24T03:48:22Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Test */&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;
&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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_update.png&amp;diff=156789</id>
		<title>File:Postman after update.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Postman_after_update.png&amp;diff=156789"/>
		<updated>2024-04-24T03:47:50Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_validate_parameters_update_test.png&amp;diff=156770</id>
		<title>File:DB validate parameters update test.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DB_validate_parameters_update_test.png&amp;diff=156770"/>
		<updated>2024-04-24T03:42:00Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</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=156762</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=156762"/>
		<updated>2024-04-24T03:37:40Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Test */&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;
&lt;br /&gt;
===Response model test===&lt;br /&gt;
====Postman Tests====&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;
&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>Mmoyape</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=156758</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=156758"/>
		<updated>2024-04-24T03:36:14Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Response model test */&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;
&lt;br /&gt;
===Responses Controller test===&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>Mmoyape</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=156753</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=156753"/>
		<updated>2024-04-24T03:32:37Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Test */&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;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Responses Controller test===&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>Mmoyape</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=156639</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=156639"/>
		<updated>2024-04-24T02:50:13Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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;
==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;
==== 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==&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>Mmoyape</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=156637</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=156637"/>
		<updated>2024-04-24T02:49:36Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &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;
==== 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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_Class_diagram.png&amp;diff=156633</id>
		<title>File:Controller Class diagram.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_Class_diagram.png&amp;diff=156633"/>
		<updated>2024-04-24T02:46:30Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Use_cases_controller.png&amp;diff=156629</id>
		<title>File:Use cases controller.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Use_cases_controller.png&amp;diff=156629"/>
		<updated>2024-04-24T02:45:46Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</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=155966</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=155966"/>
		<updated>2024-04-23T05:12:03Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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:Authorize_show_calibration_before.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>Mmoyape</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=155965</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=155965"/>
		<updated>2024-04-23T05:10:15Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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:Authorize_show_calibration_before.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;
&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>Mmoyape</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=155964</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=155964"/>
		<updated>2024-04-23T05:09:44Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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;
== 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:Authorize_show_calibration_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
The 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;
&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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Authorize_show_calibration_before.png&amp;diff=155963</id>
		<title>File:Authorize show calibration before.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Authorize_show_calibration_before.png&amp;diff=155963"/>
		<updated>2024-04-23T05:09:33Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results.png&amp;diff=155962</id>
		<title>File:Show calibration results.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Show_calibration_results.png&amp;diff=155962"/>
		<updated>2024-04-23T05:08:55Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</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=155961</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=155961"/>
		<updated>2024-04-23T05:07:00Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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;
The 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;
&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>Mmoyape</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=155959</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=155959"/>
		<updated>2024-04-23T04:53:15Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Response Controller */&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;
&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>Mmoyape</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=155954</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=155954"/>
		<updated>2024-04-23T04:47:58Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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;
==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;
Beside Basic Crud MEthods &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;
&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>Mmoyape</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=155953</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=155953"/>
		<updated>2024-04-23T04:43:50Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Response Helper */&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;
Beside Basic Crud MEthods &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;
&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;
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>Mmoyape</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=155952</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=155952"/>
		<updated>2024-04-23T04:43:39Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Response Helper */&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;
Beside Basic Crud MEthods &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;
&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;
[[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;
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>Mmoyape</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=155951</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=155951"/>
		<updated>2024-04-23T04:42:52Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Update_answers */&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;
Beside Basic Crud MEthods &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;
&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. To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&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;
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>Mmoyape</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=155950</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=155950"/>
		<updated>2024-04-23T04:42:28Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &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;
Beside Basic Crud MEthods &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;
&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. To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&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;
[[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;
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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Update_answers_after.png&amp;diff=155949</id>
		<title>File:Update answers after.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Update_answers_after.png&amp;diff=155949"/>
		<updated>2024-04-23T04:42:10Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Create_answers_after.png&amp;diff=155948</id>
		<title>File:Create answers after.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Create_answers_after.png&amp;diff=155948"/>
		<updated>2024-04-23T04:41:53Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Create_update_answers_before.png&amp;diff=155947</id>
		<title>File:Create update answers before.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Create_update_answers_before.png&amp;diff=155947"/>
		<updated>2024-04-23T04:40:37Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</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=155945</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=155945"/>
		<updated>2024-04-23T04:15:39Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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: */&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;
* Jacob Leavitt&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>Mmoyape</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=155943</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=155943"/>
		<updated>2024-04-23T04:14:25Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &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:===&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;
* Jacob Leavitt&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>Mmoyape</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=155942</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=155942"/>
		<updated>2024-04-23T04:13:42Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 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;
==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. 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;
== 5. 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:===&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155941</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=155941"/>
		<updated>2024-04-23T04:13:02Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* Template Method */&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. 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;
== 5. 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:===&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155940</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=155940"/>
		<updated>2024-04-23T04:04:40Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 5. 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;
==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. 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;
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;
&lt;br /&gt;
== 5. 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:===&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155939</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=155939"/>
		<updated>2024-04-23T04:04:06Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* validate_params */&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. 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;
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;
&lt;br /&gt;
== 5. 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:&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155938</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=155938"/>
		<updated>2024-04-23T04:03:54Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 5. 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;
==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. 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;
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;
&lt;br /&gt;
== 5. 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;
[[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:&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155937</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=155937"/>
		<updated>2024-04-23T04:01:57Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 5. 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;
==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. 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;
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;
&lt;br /&gt;
== 5. 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 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:&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155936</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=155936"/>
		<updated>2024-04-23T04:01:02Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 5. 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;
==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. 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;
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;
&lt;br /&gt;
== 5. 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 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:&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155935</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=155935"/>
		<updated>2024-04-23T04:00:18Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* 5. 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;
==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. 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;
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;
&lt;br /&gt;
== 5. 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 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:&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|1200px]]&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|1200px]]&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|1200px]]&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|1200px]]&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|1200px]]&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|1200px]]&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|1200px]]&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;
==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;
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;
==7. 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;
* 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>Mmoyape</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=155934</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=155934"/>
		<updated>2024-04-23T03:58:55Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: /* validate_params */&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. 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;
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;
&lt;br /&gt;
== 5. 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 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:&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|1000px]]&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|1000px]]&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|1000px]]&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|1000px]]&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|1000px]]&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|1000px]]&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|1000px]]&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;
==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;
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;
==7. 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;
* 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>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_and_validte_response.png&amp;diff=155931</id>
		<title>File:Set and validte response.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_and_validte_response.png&amp;diff=155931"/>
		<updated>2024-04-23T03:46:25Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_update_conditions.png&amp;diff=155930</id>
		<title>File:Validate update conditions.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_update_conditions.png&amp;diff=155930"/>
		<updated>2024-04-23T03:43:34Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_submission_status_.png&amp;diff=155929</id>
		<title>File:Validate submission status .png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_submission_status_.png&amp;diff=155929"/>
		<updated>2024-04-23T03:43:27Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_parameters_before.png&amp;diff=155928</id>
		<title>File:Validate parameters before.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_parameters_before.png&amp;diff=155928"/>
		<updated>2024-04-23T03:43:17Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_parameters_after.png&amp;diff=155927</id>
		<title>File:Validate parameters after.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_parameters_after.png&amp;diff=155927"/>
		<updated>2024-04-23T03:43:01Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_create_condition.png&amp;diff=155926</id>
		<title>File:Validate create condition.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Validate_create_condition.png&amp;diff=155926"/>
		<updated>2024-04-23T03:42:51Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_response_attributes.png&amp;diff=155925</id>
		<title>File:Set response attributes.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Set_response_attributes.png&amp;diff=155925"/>
		<updated>2024-04-23T03:42:41Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_map_id.png&amp;diff=155924</id>
		<title>File:Assign map id.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_map_id.png&amp;diff=155924"/>
		<updated>2024-04-23T03:42:19Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Action_specific_validation.png&amp;diff=155923</id>
		<title>File:Action specific validation.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Action_specific_validation.png&amp;diff=155923"/>
		<updated>2024-04-23T03:41:55Z</updated>

		<summary type="html">&lt;p&gt;Mmoyape: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mmoyape</name></author>
	</entry>
</feed>