<?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=Bkurra</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=Bkurra"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Bkurra"/>
	<updated>2026-10-08T07:58:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159654</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159654"/>
		<updated>2024-11-18T02:40:18Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
*Refactoring TeamsUsersController to TeamsParticipantsController: The controller will be renamed and restructured to better align with the domain model. All associated views, routes, and models will be updated accordingly.&lt;br /&gt;
&lt;br /&gt;
*Modular Methods and DRY Principles: Each method will be decomposed into smaller, reusable helper methods, ensuring adherence to the Single Responsibility Principle (SRP).&lt;br /&gt;
&lt;br /&gt;
*create Method: Split into smaller helper methods:&lt;br /&gt;
  find_user: Locates a user based on input.&lt;br /&gt;
  create_user: Creates a user based on input&lt;br /&gt;
check_user_already_on_team?: Validates user is already in the team or not&lt;br /&gt;
add_user_to_team: Handles adding a user to the team if all conditions are met.&lt;br /&gt;
Move Logic to Models: E.g., team_exceeds_capacity?, to keep the controller clean.&lt;br /&gt;
&lt;br /&gt;
*Role Management and UI Enhancement: Role management functionality, such as role assignments and updates, will use intuitive UI elements like dropdowns, with role descriptions available for clarity.&lt;br /&gt;
&lt;br /&gt;
*AJAX Integration for Dynamic Updates: Key actions such as adding and removing members will use AJAX to provide a smooth user experience.&lt;br /&gt;
&lt;br /&gt;
*Policy-Based Access Control: Replace action_allowed? with Policy Classes. Fine-grained permissions will be enforced using a library like Pundit to control access to various actions based on user roles.&lt;br /&gt;
&lt;br /&gt;
*Auto-Complete and Filtering: Auto-complete for user search will provide more context (e.g., name, email), and filters will be added for improved member listing.&lt;br /&gt;
&lt;br /&gt;
*Quality of Explanations: Clear and Detailed Explanations: All proposed changes, such as modularizing the create method, are clearly explained with an emphasis on improving readability and reducing complexity.&lt;br /&gt;
&lt;br /&gt;
*Follow Consistent Naming Conventions: Ensure variable and method names are descriptive and consistent across the controller.&lt;br /&gt;
&lt;br /&gt;
*Avoid Overloading Controllers: Ensure complex logic is moved to models, helpers, or service objects to prevent bloated controllers. This makes code easier to maintain and adheres to MVC principles.&lt;br /&gt;
&lt;br /&gt;
*Proper Allocation of Responsibilities: E.g., methods for checking membership should be in Team or TeamsParticipant models, not the controller.&lt;br /&gt;
&lt;br /&gt;
*Repetitive Logic and Nesting: Excessive nesting and duplicated logic can lead to code smell. Refactor common checks (e.g., user existence, membership) into helper methods.&lt;br /&gt;
&lt;br /&gt;
*Verbose Controllers: Long controllers tend to indicate poor separation of concerns. Any domain-specific logic should reside in models or services.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159653</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159653"/>
		<updated>2024-11-18T02:40:05Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
*Refactoring TeamsUsersController to TeamsParticipantsController: The controller will be renamed and restructured to better align with the domain model. All associated views, routes, and models will be updated accordingly.&lt;br /&gt;
&lt;br /&gt;
*Modular Methods and DRY Principles: Each method will be decomposed into smaller, reusable helper methods, ensuring adherence to the Single Responsibility Principle (SRP).&lt;br /&gt;
&lt;br /&gt;
*create Method: Split into smaller helper methods:&lt;br /&gt;
find_user: Locates a user based on input.&lt;br /&gt;
create_user: Creates a user based on input&lt;br /&gt;
check_user_already_on_team?: Validates user is already in the team or not&lt;br /&gt;
add_user_to_team: Handles adding a user to the team if all conditions are met.&lt;br /&gt;
Move Logic to Models: E.g., team_exceeds_capacity?, to keep the controller clean.&lt;br /&gt;
&lt;br /&gt;
*Role Management and UI Enhancement: Role management functionality, such as role assignments and updates, will use intuitive UI elements like dropdowns, with role descriptions available for clarity.&lt;br /&gt;
&lt;br /&gt;
*AJAX Integration for Dynamic Updates: Key actions such as adding and removing members will use AJAX to provide a smooth user experience.&lt;br /&gt;
&lt;br /&gt;
*Policy-Based Access Control: Replace action_allowed? with Policy Classes. Fine-grained permissions will be enforced using a library like Pundit to control access to various actions based on user roles.&lt;br /&gt;
&lt;br /&gt;
*Auto-Complete and Filtering: Auto-complete for user search will provide more context (e.g., name, email), and filters will be added for improved member listing.&lt;br /&gt;
&lt;br /&gt;
*Quality of Explanations: Clear and Detailed Explanations: All proposed changes, such as modularizing the create method, are clearly explained with an emphasis on improving readability and reducing complexity.&lt;br /&gt;
&lt;br /&gt;
*Follow Consistent Naming Conventions: Ensure variable and method names are descriptive and consistent across the controller.&lt;br /&gt;
&lt;br /&gt;
*Avoid Overloading Controllers: Ensure complex logic is moved to models, helpers, or service objects to prevent bloated controllers. This makes code easier to maintain and adheres to MVC principles.&lt;br /&gt;
&lt;br /&gt;
*Proper Allocation of Responsibilities: E.g., methods for checking membership should be in Team or TeamsParticipant models, not the controller.&lt;br /&gt;
&lt;br /&gt;
*Repetitive Logic and Nesting: Excessive nesting and duplicated logic can lead to code smell. Refactor common checks (e.g., user existence, membership) into helper methods.&lt;br /&gt;
&lt;br /&gt;
*Verbose Controllers: Long controllers tend to indicate poor separation of concerns. Any domain-specific logic should reside in models or services.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159652</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159652"/>
		<updated>2024-11-18T02:39:31Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
*Refactoring TeamsUsersController to TeamsParticipantsController: The controller will be renamed and restructured to better align with the domain model. All associated views, routes, and models will be updated accordingly.&lt;br /&gt;
&lt;br /&gt;
*Modular Methods and DRY Principles: Each method will be decomposed into smaller, reusable helper methods, ensuring adherence to the Single Responsibility Principle (SRP).&lt;br /&gt;
create Method: Split into smaller helper methods:&lt;br /&gt;
find_user: Locates a user based on input.&lt;br /&gt;
create_user: Creates a user based on input&lt;br /&gt;
check_user_already_on_team?: Validates user is already in the team or not&lt;br /&gt;
add_user_to_team: Handles adding a user to the team if all conditions are met.&lt;br /&gt;
Move Logic to Models: E.g., team_exceeds_capacity?, to keep the controller clean.&lt;br /&gt;
&lt;br /&gt;
*Role Management and UI Enhancement: Role management functionality, such as role assignments and updates, will use intuitive UI elements like dropdowns, with role descriptions available for clarity.&lt;br /&gt;
&lt;br /&gt;
*AJAX Integration for Dynamic Updates: Key actions such as adding and removing members will use AJAX to provide a smooth user experience.&lt;br /&gt;
&lt;br /&gt;
*Policy-Based Access Control: Replace action_allowed? with Policy Classes. Fine-grained permissions will be enforced using a library like Pundit to control access to various actions based on user roles.&lt;br /&gt;
&lt;br /&gt;
*Auto-Complete and Filtering: Auto-complete for user search will provide more context (e.g., name, email), and filters will be added for improved member listing.&lt;br /&gt;
&lt;br /&gt;
*Quality of Explanations: Clear and Detailed Explanations: All proposed changes, such as modularizing the create method, are clearly explained with an emphasis on improving readability and reducing complexity.&lt;br /&gt;
&lt;br /&gt;
*Follow Consistent Naming Conventions: Ensure variable and method names are descriptive and consistent across the controller.&lt;br /&gt;
&lt;br /&gt;
*Avoid Overloading Controllers: Ensure complex logic is moved to models, helpers, or service objects to prevent bloated controllers. This makes code easier to maintain and adheres to MVC principles.&lt;br /&gt;
&lt;br /&gt;
*Proper Allocation of Responsibilities: E.g., methods for checking membership should be in Team or TeamsParticipant models, not the controller.&lt;br /&gt;
&lt;br /&gt;
*Repetitive Logic and Nesting: Excessive nesting and duplicated logic can lead to code smell. Refactor common checks (e.g., user existence, membership) into helper methods.&lt;br /&gt;
&lt;br /&gt;
*Verbose Controllers: Long controllers tend to indicate poor separation of concerns. Any domain-specific logic should reside in models or services.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159651</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159651"/>
		<updated>2024-11-18T02:39:03Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
*Refactoring TeamsUsersController to TeamsParticipantsController: The controller will be renamed and restructured to better align with the domain model. All associated views, routes, and models will be updated accordingly.&lt;br /&gt;
&lt;br /&gt;
*Modular Methods and DRY Principles: Each method will be decomposed into smaller, reusable helper methods, ensuring adherence to the Single Responsibility Principle (SRP).&lt;br /&gt;
create Method: Split into smaller helper methods:&lt;br /&gt;
find_user: Locates a user based on input.&lt;br /&gt;
create_user: Creates a user based on input&lt;br /&gt;
check_user_already_on_team?: Validates user is already in the team or not&lt;br /&gt;
add_user_to_team: Handles adding a user to the team if all conditions are met.&lt;br /&gt;
Move Logic to Models: E.g., team_exceeds_capacity?, to keep the controller clean.&lt;br /&gt;
&lt;br /&gt;
*Role Management and UI Enhancement: Role management functionality, such as role assignments and updates, will use intuitive UI elements like dropdowns, with role descriptions available for clarity.&lt;br /&gt;
&lt;br /&gt;
*AJAX Integration for Dynamic Updates: Key actions such as adding and removing members will use AJAX to provide a smooth user experience.&lt;br /&gt;
&lt;br /&gt;
*Policy-Based Access Control: Replace action_allowed? with Policy Classes. Fine-grained permissions will be enforced using a library like Pundit to control access to various actions based on user roles.&lt;br /&gt;
&lt;br /&gt;
*Auto-Complete and Filtering: Auto-complete for user search will provide more context (e.g., name, email), and filters will be added for improved member listing.&lt;br /&gt;
&lt;br /&gt;
*Quality of Explanations: Clear and Detailed Explanations: All proposed changes, such as modularizing the create method, are clearly explained with an emphasis on improving readability and reducing complexity.&lt;br /&gt;
&lt;br /&gt;
*Follow Consistent Naming Conventions: Ensure variable and method names are descriptive and consistent across the controller.&lt;br /&gt;
&lt;br /&gt;
*Avoid Overloading Controllers: Ensure complex logic is moved to models, helpers, or service objects to prevent bloated controllers. This makes code easier to maintain and adheres to MVC principles.&lt;br /&gt;
Proper Allocation of Responsibilities: E.g., methods for checking membership should be in Team or TeamsParticipant models, not the controller.&lt;br /&gt;
&lt;br /&gt;
*Repetitive Logic and Nesting: Excessive nesting and duplicated logic can lead to code smell. Refactor common checks (e.g., user existence, membership) into helper methods.&lt;br /&gt;
&lt;br /&gt;
*Verbose Controllers: Long controllers tend to indicate poor separation of concerns. Any domain-specific logic should reside in models or services.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159650</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159650"/>
		<updated>2024-11-18T02:37:09Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
Refactoring TeamsUsersController to TeamsParticipantsController: The controller will be renamed and restructured to better align with the domain model. All associated views, routes, and models will be updated accordingly.&lt;br /&gt;
&lt;br /&gt;
Modular Methods and DRY Principles: Each method will be decomposed into smaller, reusable helper methods, ensuring adherence to the Single Responsibility Principle (SRP).&lt;br /&gt;
create Method: Split into smaller helper methods:&lt;br /&gt;
find_user: Locates a user based on input.&lt;br /&gt;
create_user: Creates a user based on input&lt;br /&gt;
check_user_already_on_team?: Validates user is already in the team or not&lt;br /&gt;
add_user_to_team: Handles adding a user to the team if all conditions are met.&lt;br /&gt;
Move Logic to Models: E.g., team_exceeds_capacity?, to keep the controller clean.&lt;br /&gt;
&lt;br /&gt;
Role Management and UI Enhancement: Role management functionality, such as role assignments and updates, will use intuitive UI elements like dropdowns, with role descriptions available for clarity.&lt;br /&gt;
&lt;br /&gt;
AJAX Integration for Dynamic Updates: Key actions such as adding and removing members will use AJAX to provide a smooth user experience.&lt;br /&gt;
&lt;br /&gt;
Policy-Based Access Control: Replace action_allowed? with Policy Classes. Fine-grained permissions will be enforced using a library like Pundit to control access to various actions based on user roles.&lt;br /&gt;
&lt;br /&gt;
Auto-Complete and Filtering: Auto-complete for user search will provide more context (e.g., name, email), and filters will be added for improved member listing.&lt;br /&gt;
&lt;br /&gt;
Quality of Explanations: Clear and Detailed Explanations: All proposed changes, such as modularizing the create method, are clearly explained with an emphasis on improving readability and reducing complexity.&lt;br /&gt;
&lt;br /&gt;
Follow Consistent Naming Conventions: Ensure variable and method names are descriptive and consistent across the controller.&lt;br /&gt;
&lt;br /&gt;
Avoid Overloading Controllers: Ensure complex logic is moved to models, helpers, or service objects to prevent bloated controllers. This makes code easier to maintain and adheres to MVC principles.&lt;br /&gt;
Proper Allocation of Responsibilities: E.g., methods for checking membership should be in Team or TeamsParticipant models, not the controller.&lt;br /&gt;
&lt;br /&gt;
Repetitive Logic and Nesting: Excessive nesting and duplicated logic can lead to code smell. Refactor common checks (e.g., user existence, membership) into helper methods.&lt;br /&gt;
&lt;br /&gt;
Verbose Controllers: Long controllers tend to indicate poor separation of concerns. Any domain-specific logic should reside in models or services.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159649</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159649"/>
		<updated>2024-11-18T02:36:00Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159648</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159648"/>
		<updated>2024-11-18T02:35:42Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159647</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159647"/>
		<updated>2024-11-18T02:35:34Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159646</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159646"/>
		<updated>2024-11-18T02:35:14Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159645</id>
		<title>CSC/ECE 517 Fall 2024 - E2479. Reimplement teams users controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2479._Reimplement_teams_users_controller.rb&amp;diff=159645"/>
		<updated>2024-11-18T02:34:55Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Implementation Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Expertiza ==&lt;br /&gt;
Expertiza is an open-source learning management system built with Ruby on Rails as its core. Its features include creating tests and assignments, managing assignment teams and courses, and having a solid framework to facilitate peer reviews and group comments. The main objective of this project is to reimplement teams_users_controller.rb. The goal is to reimplement teams_users_controller.rb from the Expertiza repository to the reimplementation-back-end repository to follow SOLID and DRY principles. &lt;br /&gt;
 &lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
The following were the problems with the previous implementation :&lt;br /&gt;
* &amp;lt;b&amp;gt;Lack of Modularity and SRP Violations:&amp;lt;/b&amp;gt; The create method is excessively long and handles multiple concerns such as finding users, checking assignments/courses, adding members, and handling various flash messages. This violates the Single Responsibility Principle (SRP) and makes the method difficult to maintain. Similar complexity is observed in other methods like auto_complete_for_user_name and delete.&lt;br /&gt;
* &amp;lt;b&amp;gt;Redundant and Repetitive Code:&amp;lt;/b&amp;gt; There is significant duplication in handling AssignmentTeam and CourseTeam logic in the create method. This could be abstracted into separate model methods or helper functions. The repeated checks for user membership and participant status introduce unnecessary redundancy.&lt;br /&gt;
* &amp;lt;b&amp;gt;Error Handling and Flash Message Management:&amp;lt;/b&amp;gt; Flash messages are scattered throughout the code, with some being overly complex and not user-friendly. &lt;br /&gt;
* &amp;lt;b&amp;gt;Inconsistent and Non-Descriptive Naming:&amp;lt;/b&amp;gt; Variable and method names, such as urlCreate, add_member_return, and urlCourseParticipantList, do not follow consistent naming conventions and are not very descriptive.&lt;br /&gt;
* &amp;lt;b&amp;gt;Tightly Coupled Logic:&amp;lt;/b&amp;gt; Business logic, such as validating membership and handling team participant status, resides within the controller instead of being abstracted into model methods. This makes the controller overly complex and difficult to test. Logic specific to AssignmentTeam and CourseTeam is handled in the controller, whereas it should ideally be part of respective models or services.&lt;br /&gt;
* &amp;lt;b&amp;gt;Poor Use of Access Control Mechanism:&amp;lt;/b&amp;gt; The action_allowed? method is hardcoded to check for privileges using strings and is difficult to extend. &lt;br /&gt;
* &amp;lt;b&amp;gt;Insufficient User Feedback and Validation:&amp;lt;/b&amp;gt; The implementation lacks comprehensive validation and feedback mechanisms, such as form-level client-side validation, detailed error messages, and modern UX elements like modal pop-ups or toast notifications.&lt;br /&gt;
* &amp;lt;b&amp;gt;Limited Error Handling in Batch Operations:&amp;lt;/b&amp;gt; The delete_selected method performs deletions in a loop without adequate error handling or feedback for each item.&lt;br /&gt;
* &amp;lt;b&amp;gt;Unclear Role Management:&amp;lt;/b&amp;gt; The update_duties method updates a duty using direct attribute assignment without validation or checks, potentially leading to data inconsistency.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
* Break down the create method into smaller, helper methods to ensure each performs a specific, single task. Abstract shared logic into these helper methods to eliminate redundant code, improving modularity and maintainability.&lt;br /&gt;
* Move business logic out of the controller and into the model. The controller should primarily handle interactions between the views and models, while models encapsulate business logic such as team membership validation or user assignment checks.&lt;br /&gt;
* Replace action_allowed? with policy classes (e.g., using Pundit) to provide a clear, granular, and consistent approach to managing access control based on roles and permissions.&lt;br /&gt;
* Leverage polymorphism by coding common functionalities (e.g., user-team membership rules) in the AssignmentTeam and MentoredTeam models. &lt;br /&gt;
* Use AJAX to make core actions such as adding, updating, or removing members more dynamic and responsive without page reloads. &lt;br /&gt;
* Adhere to consistent and meaningful variable naming conventions throughout the controller. And document every method with clear, descriptive comments explaining its purpose, input parameters, and expected outcomes.&lt;br /&gt;
* Implement auto-complete, error messages, and toast notifications to provide better user feedback and guidance.&lt;br /&gt;
* Add filtering and UI improvements to manage member listings to enhance usability.&lt;br /&gt;
* Develop detailed unit and integration tests to ensure robust coverage of controller actions, focusing on both normal and edge cases.  &lt;br /&gt;
* Design intuitive, interactive UI components such as dropdowns or drag-and-drop elements, for role assignments, and ensure they follow a modular, easily maintainable, and extendable modular structure.&lt;br /&gt;
1. 1. Unit Tests&lt;br /&gt;
a. Test the create Method&lt;br /&gt;
Scenario 1: Successfully adding a user to a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User exists, user is not already on a team, and team capacity is not exceeded.&lt;br /&gt;
Expected Outcome: User is added to the team, a success message is displayed, and the user is redirected.&lt;br /&gt;
Scenario 2: Adding a non-existent user.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User does not exist in the system.&lt;br /&gt;
Expected Outcome: Appropriate error message is displayed with a link to create the user.&lt;br /&gt;
Scenario 3: Adding a user who is already a member of another team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is already assigned to a different team within the same assignment/course.&lt;br /&gt;
Expected Outcome: User is not added, and an error message is displayed.&lt;br /&gt;
Scenario 4: Adding a user as a mentor.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is designated as a mentor and the team does not have a mentor yet.&lt;br /&gt;
Expected Outcome: User is added as a mentor, and appropriate success message is displayed.&lt;br /&gt;
Scenario 5: Team is at maximum capacity.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Team has reached its maximum allowed members.&lt;br /&gt;
Expected Outcome: User is not added, and an error message indicating maximum capacity is displayed.&lt;br /&gt;
b. Test the delete Method&lt;br /&gt;
Scenario 1: Successfully removing a user from a team.&lt;br /&gt;
&lt;br /&gt;
Preconditions: User is a member of the team.&lt;br /&gt;
Expected Outcome: User is removed from the team, and a success message is displayed.&lt;br /&gt;
Scenario 2: Removing a non-existent TeamsUser record.&lt;br /&gt;
&lt;br /&gt;
Preconditions: TeamsUser record does not exist.&lt;br /&gt;
Expected Outcome: Error is handled gracefully, and a suitable error message is displayed.&lt;br /&gt;
c. Test the delete_selected Method&lt;br /&gt;
Scenario 1: Successfully removing multiple selected users from a team.&lt;br /&gt;
Preconditions: Multiple valid TeamsUser records exist for the team.&lt;br /&gt;
Expected Outcome: All selected users are removed, and a success message is displayed.&lt;br /&gt;
d. Test the list Method&lt;br /&gt;
Scenario 2: Listing members with filters.&lt;br /&gt;
&lt;br /&gt;
Preconditions: Filters are applied (e.g., by role).&lt;br /&gt;
Expected Outcome: Only filtered members are displayed.&lt;br /&gt;
e. Test the update_duties Method&lt;br /&gt;
Scenario 1: Updating a user’s role within a team.&lt;br /&gt;
Preconditions: Valid TeamsUser record exists.&lt;br /&gt;
Expected Outcome: User’s role is updated, and a success message is displayed.&lt;br /&gt;
2. Integration Tests&lt;br /&gt;
a. Test User Creation and Assignment Workflow&lt;br /&gt;
Scenario 1: Create a new user and add them to a team.&lt;br /&gt;
Expected Outcome: User is created, validated, and added to the team successfully.&lt;br /&gt;
b. Test Removing and Re-adding Users&lt;br /&gt;
Scenario 1: Remove a user from a team and re-add them.&lt;br /&gt;
Expected Outcome: User is successfully removed and can be re-added if team conditions are met.&lt;br /&gt;
c. Test Access Control Policies&lt;br /&gt;
Scenario 1: User with insufficient privileges tries to create, update, or delete team members.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Access is denied with an appropriate message.&lt;br /&gt;
Scenario 2: Admin users perform team member management actions.&lt;br /&gt;
&lt;br /&gt;
Expected Outcome: Actions are allowed with expected results.&lt;br /&gt;
3. User Interface (UI) Tests&lt;br /&gt;
a. Test Auto-Complete Feature&lt;br /&gt;
Scenario 1: Search for a user by name using the auto-complete feature.&lt;br /&gt;
Expected Outcome: Matching users are displayed in real-time as suggestions.&lt;br /&gt;
b. Test Role Assignment UI&lt;br /&gt;
Scenario 1: Assign a role using a dropdown or drag-and-drop.&lt;br /&gt;
Expected Outcome: Role is correctly assigned, and UI updates accordingly.&lt;br /&gt;
&lt;br /&gt;
4. Security Tests&lt;br /&gt;
a. Test Access Control and Authorization&lt;br /&gt;
Scenario 1: Ensure unauthorized users cannot access or modify team member information.&lt;br /&gt;
Expected Outcome: Proper access control is enforced, and unauthorized actions are blocked.&lt;br /&gt;
&lt;br /&gt;
Test Plan Execution Steps&lt;br /&gt;
Setup Test Environment&lt;br /&gt;
Ensure all dependencies and environment configurations are in place.&lt;br /&gt;
Seed test data as necessary.&lt;br /&gt;
Run Unit Tests: Execute all unit tests and ensure all pass with expected behavior.&lt;br /&gt;
Run Integration Tests: Test workflows end-to-end to validate interactions between components.&lt;br /&gt;
UI and AJAX Testing: Test UI elements and AJAX responses to ensure smooth user interactions.&lt;br /&gt;
&lt;br /&gt;
Testing Tools and Frameworks&lt;br /&gt;
RSpec: For unit and integration tests.&lt;br /&gt;
Capybara: For UI testing.&lt;br /&gt;
FactoryBot: For creating test data.&lt;br /&gt;
&lt;br /&gt;
== Flow Chart for the teams_users_controller Page ==&lt;br /&gt;
[[File:Teams_participants_controller.png]]&lt;br /&gt;
=UML Diagram=&lt;br /&gt;
[[File: teamsParticipants_uml.png]]&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Our test plan will generally involve testing using RSpec and UI tests to ensure the functionality remains the same without affecting the existing functionality. This involves adding RSpec test commands for teams_user_controller and teams_user model to verify that each component functions as expected within the refactored structure. Additionally, we will run UI tests to ensure that the teams_participants page display accurately and integrates seamlessly within the Expertiza interface.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
* Manideepika Reddy Myaka&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=158110</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=158110"/>
		<updated>2024-10-30T01:48:36Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
==Expertiza==&lt;br /&gt;
The Expertiza project, an open-source initiative based on Ruby on Rails, pursues ongoing enhancement to incorporate contemporary software engineering methodologies. The Responses Controller is designed to aid reviewers in supplying organized data that conforms to an assignment's rubrics, assuring the availability of pertinent questions for each round within the appropriate deadline. It allows a reviewer to assess and grade the rubric questions relevant to the assignment's subjects. Moreover, it guarantees the provision of relevant questions for each assignment round, enabling reviewers to generate and adjust scores and remarks for each rubric question linked to the assignment. Upon the submission of scored questions and comments by reviewers, the Responses Controller sends an email message to the instructor and the members of the reviewed team.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a historical system with conventions that predate Rails standards, is too intricate, incorporating functionalities that extend beyond simple CRUD operations and requiring compliance with contemporary Rails nomenclature and design concepts. Critical concerns encompass the direct execution of functions such as sorting reviews and verifying reviewer roles within the controller, indicating a transition towards polymorphism and a more systematic method of code organization. Moreover, the controller's management of email notifications and feedback systems is erratic, highlighting the need for a specialized assistant to optimize communication procedures. The reimplementation initiative must concentrate on streamlining the controller, conforming to Rails principles, and enhancing code readability and maintainability through the judicious allocation of responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal ==&lt;br /&gt;
The redesign of `responses_controller.rb` is driven by several primary aims aimed at enhancing code quality, system performance, and developer engagement. The objectives encompass:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Guaranteeing the code is comprehensible, modifiable, and extensible. The reimplementation should facilitate future updates and the incorporation of new features.&lt;br /&gt;
&lt;br /&gt;
* Compliance with Rails Best Practices: Adhering to Rails conventions on nomenclature, architecture, and coding methodologies to guarantee code uniformity and dependability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - eliminating unnecessary code and logic to enhance efficiency and reduce errors in the codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Reorganizing the controller and related models to ensure that each class and method has a singular purpose, hence facilitating enhanced testing and management.&lt;br /&gt;
&lt;br /&gt;
* Enhanced Testing and Coverage: Augmenting test suites to encompass a broader range of scenarios and edge situations, hence bolstering confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Recognizing and enhancing sluggish or ineffective segments in the code to guarantee the application operates seamlessly.&lt;br /&gt;
&lt;br /&gt;
* Eliminate Obsolete Methods: Conduct an audit of the codebase to identify and delete any unneeded (&amp;quot;dead&amp;quot;) methods inside the present controller to streamline the code.&lt;br /&gt;
&lt;br /&gt;
* Diminished Controller Complexity: We have already streamlined the `ResponseController` to concentrate mostly on CRUD activities and have extracted non-essential functionality to suitable models or helpers; now we intend to implement the remaining operations.&lt;br /&gt;
&lt;br /&gt;
By achieving these design objectives, the project seeks to create a `responses_controller.rb` that is resilient, efficient, and user-friendly for both the current development team and future system maintainers.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern == &lt;br /&gt;
&lt;br /&gt;
Throughout the code rewriting effort, we meticulously adhered to certain design patterns to improve the overall architecture.&lt;br /&gt;
During the redesign of the Response model and its corresponding controller and helper methods within the application, several fundamental design patterns and concepts were adhered to in order to enhance code quality, maintainability, and scalability. The following are the principal patterns and principles that were taken into account:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This technique was utilized to decompose intricate methods into smaller, more targeted functions that manage a specific aspect of the process.&lt;br /&gt;
&lt;br /&gt;
In the Response Model, Validate_params was subdivided into several smaller methods, each responsible for a distinct aspect of the validation process. This enables each method to oversee a specific facet of the validation, hence enhancing the maintainability and modifiability of the code.&lt;br /&gt;
The establishment and administration of relationships and fundamental properties were distinctly articulated, ensuring that the Response class remains unencumbered by logic unrelated to its specific attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
In the ResponsesController, the methods such as create, update, and show are designed solely to manage HTTP requests while delegating business logic to the model or helper methods. This maintains the controller actions in a clean and focused manner for routing and fundamental request management.&lt;br /&gt;
&lt;br /&gt;
In the ResponseHelper, methods like create_answers and update_answers exemplify the principle that each method is designated for either the creation or the updating of answers, but not both. This adheres to SRP by partitioning duties into more manageable, distinct operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method design is implicitly evident when object generation procedures are encapsulated within the model or auxiliary methods, such as instantiating a new ResponseMap or generating new Answer objects. This guarantees that object instantiation is modular and distinct from the primary application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The strategy design enables the independent variation of algorithms by establishing a family of encapsulated algorithms, such as validation criteria for activities like creation or updating, and allowing them to be interchangeable for the clients that utilize them. Separating the validation criteria for response creation and updating facilitates the flexible interchange and enhancement of validation logic without necessitating direct alterations to the controller or model.&lt;br /&gt;
Observer Pattern&lt;br /&gt;
Typically employed in situations where modifications to a certain object must automatically inform other dependant objects. Within the framework of this program, this may pertain to alerting instructors or peers following the submission or modification of responses, managed via the auxiliary ways for dispatching emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be employed to delineate the framework of an operation within a method, postponing certain phases to subclasses or other methods. The validation process in validate_params employs a generic framework while delegating specific details to methods such as validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactoring seeks to establish a more resilient, manageable, and scalable system through the integration of various design patterns and concepts. This method not only resolves existing complexities but also establishes a basis for more straightforward future improvements and alterations.&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 in the response model were either refactored or newly added, including: &lt;br /&gt;
==== set_content ====&lt;br /&gt;
 Reengineered to collect and organize the necessary data for response objects, enhancing the interaction with related models.&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original approach including 46 lines. &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==This method underwent substantial refactoring to enhance parameter validation. It was divided into several smaller, targeted procedures, each assigned to address a certain facet of the validation process. Each new method performs a singular function, hence enhancing comprehension and maintainability.==&lt;br /&gt;
*Assigns the map_id for the response according to the specified parameters, ensuring the accurate map ID is utilized for both creation and modification of responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Confirms and verifies the existence of the response_map according to map_id. It is essential to verify that any answer being generated or modified is associated with a proper response map.This method seeks to locate a ResponseMap using map_id. If it cannot locate one, it logs an error and ceases further validation, indicating a problem early in the procedure.&lt;br /&gt;
[[File:Set and validate response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params): Allocates supplementary attributes to the response object derived from the parameters. This consolidates attribute configuration, minimizing redundancy and errors.Extracts values such as round, version_num, additional_comment, and visibility from the arguments and assigns them to the answer object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, activity): Orchestrates the validation process contingent upon whether the action pertains to creating or updating a response, systematically structuring the logic to avert condition proliferation in the primary validation procedure.Invokes various validation methods according to 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: Verifies that a new response does not replicate an existing response inside the same response map, round, and version number.Conducts a search for a pre-existing response that corresponds to the current map_id, round, and version_num. If such a response exists, it generates a validation error and inhibits the generation of a duplicate answer.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
validate_update_conditions(params): Verifies the validity of updates to a response, specifically confirming that the response has not been previously sent and that its map_id remains constant.Verifies the submission status and assesses any attempts to modify the map_id. Should either criteria be breached, an error is documented.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
validate_submission_status(params): Modifies the submission status of the response during the update procedure, guaranteeing that the attribute is accurately configured according to the supplied parameters.Extracts and establishes the is_submitted state from the parameters, which is essential for regulating the editability of the answer.&lt;br /&gt;
[[File:Validate submission status.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Optimized for the effective serialization of answer data in API contacts, hence boosting the clarity and usefulness of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
The ResponseController, initially comprehensive with several features exceeding simple CRUD operations, has been optimized for our API application. In this scenario, it is unnecessary to manage data variables for view pages, hence streamlining the handling of request data exclusively through request methods.To improve the architecture and efficiency of our program, we have removed unnecessary methods and integrated functionality across the model, controller, and helper files. The restructure was crucial for optimizing the response endpoints specifically designed for an API application.&lt;br /&gt;
&lt;br /&gt;
Prior to the incorporation of fundamental CRUD operations such as Create, Read, Update, Edit, and Delete.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: The legacy methods Questionnaire_from_response_map and Questionnaire_from_response were eliminated with the reworking of set_content, which now internally manages their functionalities.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ==== =&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Display calibration outcomes for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The previous solution also utilized database queries within the display.  The reimplemented Expertiza will not permit this, necessitating that the relevant data be included 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|900 pixels]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method obtains and presents calibration and review replies according to specified map IDs. It retrieves responses utilizing these IDs, acquires corresponding questions and answers, and presents the data as a structured JSON object. In the absence of a response, an error is generated to signify the lack of a response. The method manages all exceptions by providing a standardized error message, hence assuring comprehensive error handling during the operation.&lt;br /&gt;
Functions as an API endpoint to retrieve comprehensive response data for a student's calibration and review activities, supplying all pertinent information regarding the questions posed and the answers given in both scenarios.&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) initially managed both the generation and modification of answer records within a singular function. &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To enhance code maintainability and comply with the Single Responsibility Principle, this method has been separated into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
Create_answers ==== ====&lt;br /&gt;
This method is exclusively concerned with generating new answer records. It traverses the submitted responses, verifying that each answer is not already present in the database. If the response is absent, it generates a new record for that answer. This guarantees the uniqueness of each response and inhibits redundancy.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
====Update_answers ==== &lt;br /&gt;
This technique updates existing response records. It queries the database for existing replies using the response and question identifiers. Upon discovering an answer, it revises the current record with the newly supplied information. This method guarantees the precise recording of all response updates and maintains the database's currency.&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;
*Richard Li&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Loyda Yusufova	&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157956</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157956"/>
		<updated>2024-10-30T00:39:09Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* 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 initiative based on Ruby on Rails, pursues ongoing enhancement to incorporate contemporary software engineering methodologies. The Responses Controller is designed to aid reviewers in supplying organized data that conforms to an assignment's rubrics, assuring the availability of pertinent questions for each round within the appropriate deadline. It allows a reviewer to assess and grade the rubric questions relevant to the assignment's subjects. Moreover, it guarantees the provision of relevant questions for each assignment round, enabling reviewers to generate and adjust scores and remarks for each rubric question linked to the assignment. Upon the submission of scored questions and comments by reviewers, the Responses Controller sends an email message to the instructor and the members of the reviewed team.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a historical system with conventions that predate Rails standards, is too intricate, incorporating functionalities that extend beyond simple CRUD operations and requiring compliance with contemporary Rails nomenclature and design concepts. Critical concerns encompass the direct execution of functions such as sorting reviews and verifying reviewer roles within the controller, indicating a transition towards polymorphism and a more systematic method of code organization. Moreover, the controller's management of email notifications and feedback systems is erratic, highlighting the need for a specialized assistant to optimize communication procedures. The reimplementation initiative must concentrate on streamlining the controller, conforming to Rails principles, and enhancing code readability and maintainability through the judicious allocation of responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal ==&lt;br /&gt;
The redesign of `responses_controller.rb` is driven by several primary aims aimed at enhancing code quality, system performance, and developer engagement. The objectives encompass:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Guaranteeing the code is comprehensible, modifiable, and extensible. The reimplementation should facilitate future updates and the incorporation of new features.&lt;br /&gt;
&lt;br /&gt;
* Compliance with Rails Best Practices: Adhering to Rails conventions on nomenclature, architecture, and coding methodologies to guarantee code uniformity and dependability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - eliminating unnecessary code and logic to enhance efficiency and reduce errors in the codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Reorganizing the controller and related models to ensure that each class and method has a singular purpose, hence facilitating enhanced testing and management.&lt;br /&gt;
&lt;br /&gt;
* Enhanced Testing and Coverage: Augmenting test suites to encompass a broader range of scenarios and edge situations, hence bolstering confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Recognizing and enhancing sluggish or ineffective segments in the code to guarantee the application operates seamlessly.&lt;br /&gt;
&lt;br /&gt;
* Eliminate Obsolete Methods: Conduct an audit of the codebase to identify and delete any unneeded (&amp;quot;dead&amp;quot;) methods inside the present controller to streamline the code.&lt;br /&gt;
&lt;br /&gt;
* Diminished Controller Complexity: We have already streamlined the `ResponseController` to concentrate mostly on CRUD activities and have extracted non-essential functionality to suitable models or helpers; now we intend to implement the remaining operations.&lt;br /&gt;
&lt;br /&gt;
By achieving these design objectives, the project seeks to create a `responses_controller.rb` that is resilient, efficient, and user-friendly for both the current development team and future system maintainers.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern == &lt;br /&gt;
&lt;br /&gt;
Throughout the code rewriting effort, we meticulously adhered to certain design patterns to improve the overall architecture.&lt;br /&gt;
During the redesign of the Response model and its corresponding controller and helper methods within the application, several fundamental design patterns and concepts were adhered to in order to enhance code quality, maintainability, and scalability. The following are the principal patterns and principles that were taken into account:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This technique was utilized to decompose intricate methods into smaller, more targeted functions that manage a specific aspect of the process.&lt;br /&gt;
&lt;br /&gt;
In the Response Model, Validate_params was subdivided into several smaller methods, each responsible for a distinct aspect of the validation process. This enables each method to oversee a specific facet of the validation, hence enhancing the maintainability and modifiability of the code.&lt;br /&gt;
The establishment and administration of relationships and fundamental properties were distinctly articulated, ensuring that the Response class remains unencumbered by logic unrelated to its specific attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
In the ResponsesController, the methods such as create, update, and show are designed solely to manage HTTP requests while delegating business logic to the model or helper methods. This maintains the controller actions in a clean and focused manner for routing and fundamental request management.&lt;br /&gt;
&lt;br /&gt;
In the ResponseHelper, methods like create_answers and update_answers exemplify the principle that each method is designated for either the creation or the updating of answers, but not both. This adheres to SRP by partitioning duties into more manageable, distinct operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method design is implicitly evident when object generation procedures are encapsulated within the model or auxiliary methods, such as instantiating a new ResponseMap or generating new Answer objects. This guarantees that object instantiation is modular and distinct from the primary application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The strategy design enables the independent variation of algorithms by establishing a family of encapsulated algorithms, such as validation criteria for activities like creation or updating, and allowing them to be interchangeable for the clients that utilize them. Separating the validation criteria for response creation and updating facilitates the flexible interchange and enhancement of validation logic without necessitating direct alterations to the controller or model.&lt;br /&gt;
Observer Pattern&lt;br /&gt;
Typically employed in situations where modifications to a certain object must automatically inform other dependant objects. Within the framework of this program, this may pertain to alerting instructors or peers following the submission or modification of responses, managed via the auxiliary ways for dispatching emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be employed to delineate the framework of an operation within a method, postponing certain phases to subclasses or other methods. The validation process in validate_params employs a generic framework while delegating specific details to methods such as validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactoring seeks to establish a more resilient, manageable, and scalable system through the integration of various design patterns and concepts. This method not only resolves existing complexities but also establishes a basis for more straightforward future improvements and alterations.&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 in the response model were either refactored or newly added, including: &lt;br /&gt;
==== set_content ====&lt;br /&gt;
 Reengineered to collect and organize the necessary data for response objects, enhancing the interaction with related models.&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original approach including 46 lines. &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==This method underwent substantial refactoring to enhance parameter validation. It was divided into several smaller, targeted procedures, each assigned to address a certain facet of the validation process. Each new method performs a singular function, hence enhancing comprehension and maintainability.==&lt;br /&gt;
*Assigns the map_id for the response according to the specified parameters, ensuring the accurate map ID is utilized for both creation and modification of responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Confirms and verifies the existence of the response_map according to map_id. It is essential to verify that any answer being generated or modified is associated with a proper response map.This method seeks to locate a ResponseMap using map_id. If it cannot locate one, it logs an error and ceases further validation, indicating a problem early in the procedure.&lt;br /&gt;
[[File:Set and validate response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params): Allocates supplementary attributes to the response object derived from the parameters. This consolidates attribute configuration, minimizing redundancy and errors.Extracts values such as round, version_num, additional_comment, and visibility from the arguments and assigns them to the answer object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, activity): Orchestrates the validation process contingent upon whether the action pertains to creating or updating a response, systematically structuring the logic to avert condition proliferation in the primary validation procedure.Invokes various validation methods according to 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: Verifies that a new response does not replicate an existing response inside the same response map, round, and version number.Conducts a search for a pre-existing response that corresponds to the current map_id, round, and version_num. If such a response exists, it generates a validation error and inhibits the generation of a duplicate answer.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
validate_update_conditions(params): Verifies the validity of updates to a response, specifically confirming that the response has not been previously sent and that its map_id remains constant.Verifies the submission status and assesses any attempts to modify the map_id. Should either criteria be breached, an error is documented.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
validate_submission_status(params): Modifies the submission status of the response during the update procedure, guaranteeing that the attribute is accurately configured according to the supplied parameters.Extracts and establishes the is_submitted state from the parameters, which is essential for regulating the editability of the answer.&lt;br /&gt;
[[File:Validate submission status.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Optimized for the effective serialization of answer data in API contacts, hence boosting the clarity and usefulness of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
The ResponseController, initially comprehensive with several features exceeding simple CRUD operations, has been optimized for our API application. In this scenario, it is unnecessary to manage data variables for view pages, hence streamlining the handling of request data exclusively through request methods.To improve the architecture and efficiency of our program, we have removed unnecessary methods and integrated functionality across the model, controller, and helper files. The restructure was crucial for optimizing the response endpoints specifically designed for an API application.&lt;br /&gt;
&lt;br /&gt;
Prior to the incorporation of fundamental CRUD operations such as Create, Read, Update, Edit, and Delete.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: The legacy methods Questionnaire_from_response_map and Questionnaire_from_response were eliminated with the reworking of set_content, which now internally manages their functionalities.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ==== =&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Display calibration outcomes for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The previous solution also utilized database queries within the display.  The reimplemented Expertiza will not permit this, necessitating that the relevant data be included 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|900 pixels]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method obtains and presents calibration and review replies according to specified map IDs. It retrieves responses utilizing these IDs, acquires corresponding questions and answers, and presents the data as a structured JSON object. In the absence of a response, an error is generated to signify the lack of a response. The method manages all exceptions by providing a standardized error message, hence assuring comprehensive error handling during the operation.&lt;br /&gt;
Functions as an API endpoint to retrieve comprehensive response data for a student's calibration and review activities, supplying all pertinent information regarding the questions posed and the answers given in both scenarios.&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) initially managed both the generation and modification of answer records within a singular function. &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To enhance code maintainability and comply with the Single Responsibility Principle, this method has been separated into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
Create_answers ==== ====&lt;br /&gt;
This method is exclusively concerned with generating new answer records. It traverses the submitted responses, verifying that each answer is not already present in the database. If the response is absent, it generates a new record for that answer. This guarantees the uniqueness of each response and inhibits redundancy.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
====Update_answers ==== &lt;br /&gt;
This technique updates existing response records. It queries the database for existing replies using the response and question identifiers. Upon discovering an answer, it revises the current record with the newly supplied information. This method guarantees the precise recording of all response updates and maintains the database's currency.&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;
*Richard Li&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Loyda Yusufova	&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157784</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157784"/>
		<updated>2024-10-29T22:33:53Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Team */&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 initiative based on Ruby on Rails, pursues ongoing enhancement to incorporate contemporary software engineering methodologies. The Responses Controller is designed to aid reviewers in supplying organized data that conforms to an assignment's rubrics, assuring the availability of pertinent questions for each round within the appropriate deadline. It allows a reviewer to assess and grade the rubric questions relevant to the assignment's subjects. Moreover, it guarantees the provision of relevant questions for each assignment round, enabling reviewers to generate and adjust scores and remarks for each rubric question linked to the assignment. Upon the submission of scored questions and comments by reviewers, the Responses Controller sends an email message to the instructor and the members of the reviewed team.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a historical system with conventions that predate Rails standards, is too intricate, incorporating functionalities that extend beyond simple CRUD operations and requiring compliance with contemporary Rails nomenclature and design concepts. Critical concerns encompass the direct execution of functions such as sorting reviews and verifying reviewer roles within the controller, indicating a transition towards polymorphism and a more systematic method of code organization. Moreover, the controller's management of email notifications and feedback systems is erratic, highlighting the need for a specialized assistant to optimize communication procedures. The reimplementation initiative must concentrate on streamlining the controller, conforming to Rails principles, and enhancing code readability and maintainability through the judicious allocation of responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal ==&lt;br /&gt;
The redesign of `responses_controller.rb` is driven by several primary aims aimed at enhancing code quality, system performance, and developer engagement. The objectives encompass:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Guaranteeing the code is comprehensible, modifiable, and extensible. The reimplementation should facilitate future updates and the incorporation of new features.&lt;br /&gt;
&lt;br /&gt;
* Compliance with Rails Best Practices: Adhering to Rails conventions on nomenclature, architecture, and coding methodologies to guarantee code uniformity and dependability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - eliminating unnecessary code and logic to enhance efficiency and reduce errors in the codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Reorganizing the controller and related models to ensure that each class and method has a singular purpose, hence facilitating enhanced testing and management.&lt;br /&gt;
&lt;br /&gt;
* Enhanced Testing and Coverage: Augmenting test suites to encompass a broader range of scenarios and edge situations, hence bolstering confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Recognizing and enhancing sluggish or ineffective segments in the code to guarantee the application operates seamlessly.&lt;br /&gt;
&lt;br /&gt;
* Eliminate Obsolete Methods: Conduct an audit of the codebase to identify and delete any unneeded (&amp;quot;dead&amp;quot;) methods inside the present controller to streamline the code.&lt;br /&gt;
&lt;br /&gt;
* Diminished Controller Complexity: We have already streamlined the `ResponseController` to concentrate mostly on CRUD activities and have extracted non-essential functionality to suitable models or helpers; now we intend to implement the remaining operations.&lt;br /&gt;
&lt;br /&gt;
By achieving these design objectives, the project seeks to create a `responses_controller.rb` that is resilient, efficient, and user-friendly for both the current development team and future system maintainers.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern == &lt;br /&gt;
&lt;br /&gt;
Throughout the code rewriting effort, we meticulously adhered to certain design patterns to improve the overall architecture.&lt;br /&gt;
During the redesign of the Response model and its corresponding controller and helper methods within the application, several fundamental design patterns and concepts were adhered to in order to enhance code quality, maintainability, and scalability. The following are the principal patterns and principles that were taken into account:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This technique was utilized to decompose intricate methods into smaller, more targeted functions that manage a specific aspect of the process.&lt;br /&gt;
&lt;br /&gt;
In the Response Model, Validate_params was subdivided into several smaller methods, each responsible for a distinct aspect of the validation process. This enables each method to oversee a specific facet of the validation, hence enhancing the maintainability and modifiability of the code.&lt;br /&gt;
The establishment and administration of relationships and fundamental properties were distinctly articulated, ensuring that the Response class remains unencumbered by logic unrelated to its specific attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
In the ResponsesController, the methods such as create, update, and show are designed solely to manage HTTP requests while delegating business logic to the model or helper methods. This maintains the controller actions in a clean and focused manner for routing and fundamental request management.&lt;br /&gt;
&lt;br /&gt;
In the ResponseHelper, methods like create_answers and update_answers exemplify the principle that each method is designated for either the creation or the updating of answers, but not both. This adheres to SRP by partitioning duties into more manageable, distinct operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method design is implicitly evident when object generation procedures are encapsulated within the model or auxiliary methods, such as instantiating a new ResponseMap or generating new Answer objects. This guarantees that object instantiation is modular and distinct from the primary application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The strategy design enables the independent variation of algorithms by establishing a family of encapsulated algorithms, such as validation criteria for activities like creation or updating, and allowing them to be interchangeable for the clients that utilize them. Separating the validation criteria for response creation and updating facilitates the flexible interchange and enhancement of validation logic without necessitating direct alterations to the controller or model.&lt;br /&gt;
Observer Pattern&lt;br /&gt;
Typically employed in situations where modifications to a certain object must automatically inform other dependant objects. Within the framework of this program, this may pertain to alerting instructors or peers following the submission or modification of responses, managed via the auxiliary ways for dispatching emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be employed to delineate the framework of an operation within a method, postponing certain phases to subclasses or other methods. The validation process in validate_params employs a generic framework while delegating specific details to methods such as validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactoring seeks to establish a more resilient, manageable, and scalable system through the integration of various design patterns and concepts. This method not only resolves existing complexities but also establishes a basis for more straightforward future improvements and alterations.&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;
*Richard Li&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Loyda Yusufova	&lt;br /&gt;
* Bhuvan Chandra Kurra&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157758</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157758"/>
		<updated>2024-10-29T22:17:54Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Design Pattern */&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 initiative based on Ruby on Rails, pursues ongoing enhancement to incorporate contemporary software engineering methodologies. The Responses Controller is designed to aid reviewers in supplying organized data that conforms to an assignment's rubrics, assuring the availability of pertinent questions for each round within the appropriate deadline. It allows a reviewer to assess and grade the rubric questions relevant to the assignment's subjects. Moreover, it guarantees the provision of relevant questions for each assignment round, enabling reviewers to generate and adjust scores and remarks for each rubric question linked to the assignment. Upon the submission of scored questions and comments by reviewers, the Responses Controller sends an email message to the instructor and the members of the reviewed team.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a historical system with conventions that predate Rails standards, is too intricate, incorporating functionalities that extend beyond simple CRUD operations and requiring compliance with contemporary Rails nomenclature and design concepts. Critical concerns encompass the direct execution of functions such as sorting reviews and verifying reviewer roles within the controller, indicating a transition towards polymorphism and a more systematic method of code organization. Moreover, the controller's management of email notifications and feedback systems is erratic, highlighting the need for a specialized assistant to optimize communication procedures. The reimplementation initiative must concentrate on streamlining the controller, conforming to Rails principles, and enhancing code readability and maintainability through the judicious allocation of responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal ==&lt;br /&gt;
The redesign of `responses_controller.rb` is driven by several primary aims aimed at enhancing code quality, system performance, and developer engagement. The objectives encompass:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Guaranteeing the code is comprehensible, modifiable, and extensible. The reimplementation should facilitate future updates and the incorporation of new features.&lt;br /&gt;
&lt;br /&gt;
* Compliance with Rails Best Practices: Adhering to Rails conventions on nomenclature, architecture, and coding methodologies to guarantee code uniformity and dependability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - eliminating unnecessary code and logic to enhance efficiency and reduce errors in the codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Reorganizing the controller and related models to ensure that each class and method has a singular purpose, hence facilitating enhanced testing and management.&lt;br /&gt;
&lt;br /&gt;
* Enhanced Testing and Coverage: Augmenting test suites to encompass a broader range of scenarios and edge situations, hence bolstering confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Recognizing and enhancing sluggish or ineffective segments in the code to guarantee the application operates seamlessly.&lt;br /&gt;
&lt;br /&gt;
* Eliminate Obsolete Methods: Conduct an audit of the codebase to identify and delete any unneeded (&amp;quot;dead&amp;quot;) methods inside the present controller to streamline the code.&lt;br /&gt;
&lt;br /&gt;
* Diminished Controller Complexity: We have already streamlined the `ResponseController` to concentrate mostly on CRUD activities and have extracted non-essential functionality to suitable models or helpers; now we intend to implement the remaining operations.&lt;br /&gt;
&lt;br /&gt;
By achieving these design objectives, the project seeks to create a `responses_controller.rb` that is resilient, efficient, and user-friendly for both the current development team and future system maintainers.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern == &lt;br /&gt;
&lt;br /&gt;
Throughout the code rewriting effort, we meticulously adhered to certain design patterns to improve the overall architecture.&lt;br /&gt;
During the redesign of the Response model and its corresponding controller and helper methods within the application, several fundamental design patterns and concepts were adhered to in order to enhance code quality, maintainability, and scalability. The following are the principal patterns and principles that were taken into account:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This technique was utilized to decompose intricate methods into smaller, more targeted functions that manage a specific aspect of the process.&lt;br /&gt;
&lt;br /&gt;
In the Response Model, Validate_params was subdivided into several smaller methods, each responsible for a distinct aspect of the validation process. This enables each method to oversee a specific facet of the validation, hence enhancing the maintainability and modifiability of the code.&lt;br /&gt;
The establishment and administration of relationships and fundamental properties were distinctly articulated, ensuring that the Response class remains unencumbered by logic unrelated to its specific attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
In the ResponsesController, the methods such as create, update, and show are designed solely to manage HTTP requests while delegating business logic to the model or helper methods. This maintains the controller actions in a clean and focused manner for routing and fundamental request management.&lt;br /&gt;
&lt;br /&gt;
In the ResponseHelper, methods like create_answers and update_answers exemplify the principle that each method is designated for either the creation or the updating of answers, but not both. This adheres to SRP by partitioning duties into more manageable, distinct operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method design is implicitly evident when object generation procedures are encapsulated within the model or auxiliary methods, such as instantiating a new ResponseMap or generating new Answer objects. This guarantees that object instantiation is modular and distinct from the primary application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
The strategy design enables the independent variation of algorithms by establishing a family of encapsulated algorithms, such as validation criteria for activities like creation or updating, and allowing them to be interchangeable for the clients that utilize them. Separating the validation criteria for response creation and updating facilitates the flexible interchange and enhancement of validation logic without necessitating direct alterations to the controller or model.&lt;br /&gt;
Observer Pattern&lt;br /&gt;
Typically employed in situations where modifications to a certain object must automatically inform other dependant objects. Within the framework of this program, this may pertain to alerting instructors or peers following the submission or modification of responses, managed via the auxiliary ways for dispatching emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be employed to delineate the framework of an operation within a method, postponing certain phases to subclasses or other methods. The validation process in validate_params employs a generic framework while delegating specific details to methods such as validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactoring seeks to establish a more resilient, manageable, and scalable system through the integration of various design patterns and concepts. This method not only resolves existing complexities but also establishes a basis for more straightforward future improvements and alterations.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
The ResponseController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods.To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Validate Parameters===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Separated Answer Creation and Update Logic===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Creation:&lt;br /&gt;
[[File:Postman after create for answer.png|900px]]&lt;br /&gt;
[[File:DB after create.png|900px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:Postman after update for answer.png|900px]]&lt;br /&gt;
[[File:DB after update.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157741</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157741"/>
		<updated>2024-10-29T22:13:19Z</updated>

		<summary type="html">&lt;p&gt;Bkurra: /* Design Goal */&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 initiative based on Ruby on Rails, pursues ongoing enhancement to incorporate contemporary software engineering methodologies. The Responses Controller is designed to aid reviewers in supplying organized data that conforms to an assignment's rubrics, assuring the availability of pertinent questions for each round within the appropriate deadline. It allows a reviewer to assess and grade the rubric questions relevant to the assignment's subjects. Moreover, it guarantees the provision of relevant questions for each assignment round, enabling reviewers to generate and adjust scores and remarks for each rubric question linked to the assignment. Upon the submission of scored questions and comments by reviewers, the Responses Controller sends an email message to the instructor and the members of the reviewed team.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The ResponseController in Expertiza, a historical system with conventions that predate Rails standards, is too intricate, incorporating functionalities that extend beyond simple CRUD operations and requiring compliance with contemporary Rails nomenclature and design concepts. Critical concerns encompass the direct execution of functions such as sorting reviews and verifying reviewer roles within the controller, indicating a transition towards polymorphism and a more systematic method of code organization. Moreover, the controller's management of email notifications and feedback systems is erratic, highlighting the need for a specialized assistant to optimize communication procedures. The reimplementation initiative must concentrate on streamlining the controller, conforming to Rails principles, and enhancing code readability and maintainability through the judicious allocation of responsibilities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal ==&lt;br /&gt;
The redesign of `responses_controller.rb` is driven by several primary aims aimed at enhancing code quality, system performance, and developer engagement. The objectives encompass:&lt;br /&gt;
&lt;br /&gt;
* Maintainability and Scalability: Guaranteeing the code is comprehensible, modifiable, and extensible. The reimplementation should facilitate future updates and the incorporation of new features.&lt;br /&gt;
&lt;br /&gt;
* Compliance with Rails Best Practices: Adhering to Rails conventions on nomenclature, architecture, and coding methodologies to guarantee code uniformity and dependability.&lt;br /&gt;
&lt;br /&gt;
* DRY Principle: &amp;quot;Don't Repeat Yourself&amp;quot; - eliminating unnecessary code and logic to enhance efficiency and reduce errors in the codebase.&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle: Reorganizing the controller and related models to ensure that each class and method has a singular purpose, hence facilitating enhanced testing and management.&lt;br /&gt;
&lt;br /&gt;
* Enhanced Testing and Coverage: Augmenting test suites to encompass a broader range of scenarios and edge situations, hence bolstering confidence in the application's stability and performance.&lt;br /&gt;
&lt;br /&gt;
* Performance Optimization: Recognizing and enhancing sluggish or ineffective segments in the code to guarantee the application operates seamlessly.&lt;br /&gt;
&lt;br /&gt;
* Eliminate Obsolete Methods: Conduct an audit of the codebase to identify and delete any unneeded (&amp;quot;dead&amp;quot;) methods inside the present controller to streamline the code.&lt;br /&gt;
&lt;br /&gt;
* Diminished Controller Complexity: We have already streamlined the `ResponseController` to concentrate mostly on CRUD activities and have extracted non-essential functionality to suitable models or helpers; now we intend to implement the remaining operations.&lt;br /&gt;
&lt;br /&gt;
By achieving these design objectives, the project seeks to create a `responses_controller.rb` that is resilient, efficient, and user-friendly for both the current development team and future system maintainers.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern ==&lt;br /&gt;
&lt;br /&gt;
During the code refactoring process, we conscientiously followed various design patterns to enhance the overall structure.&lt;br /&gt;
When refactoring the Response model and associated controller and helper methods in the application, several key design patterns and principles were followed to ensure improved code quality, maintainability, and scalability. Here are the primary patterns and principles that were considered:&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
This principle was applied to break down complex methods into smaller, more focused functions that handle a specific part of the process&lt;br /&gt;
&lt;br /&gt;
*In the Response Model:&lt;br /&gt;
Validate_params was broken down into multiple smaller methods, each handling a specific part of the validation process. This allows each method to manage one aspect of the validation, making the code easier to maintain and modify.&lt;br /&gt;
Creation and management of relationships and basic attributes were clearly defined, ensuring that the Response class isn't overloaded with logic that doesn't pertain to its direct attributes or relationships.&lt;br /&gt;
&lt;br /&gt;
*In the ResponsesController:&lt;br /&gt;
The controller methods like create, update, show, etc., were defined to handle only HTTP requests and delegate business logic to the model or helper methods. This keeps the controller actions clean and focused on routing and basic request handling.&lt;br /&gt;
&lt;br /&gt;
*In the ResponseHelper:&lt;br /&gt;
Methods such as create_answers and update_answers are good examples where each method is tasked with either creating or updating answers but not both. This follows SRP by dividing the responsibilities into more manageable, discrete operations.&lt;br /&gt;
&lt;br /&gt;
===Factory Method===&lt;br /&gt;
The Factory Method pattern can be seen implicitly where object creation processes are encapsulated within the model or helper methods, such as creating a new ResponseMap or generating new Answer objects. This ensures that object creation is modular and separated from the main application logic.&lt;br /&gt;
===Strategy Pattern===&lt;br /&gt;
By defining a family of algorithms (in this case, validation rules for different actions like create or update), encapsulating each one, and making them interchangeable, the strategy pattern lets the algorithm vary independently from the clients that use it. For instance, separating the validation conditions for creating and updating responses allows for flexible swapping and extension of validation logic without modifying the controller or model directly.&lt;br /&gt;
===Observer Pattern===&lt;br /&gt;
Used typically in scenarios where changes to a particular object need to notify other dependent objects automatically. In the context of this application, this could relate to notifying instructors or peers upon the submission or update of responses, handled through the helper methods for sending emails.&lt;br /&gt;
===Template Method===&lt;br /&gt;
This pattern can be used in defining the skeleton of an operation in a method, deferring some steps to subclasses or other methods. It's seen in how validate_params uses a general structure for validation but defers the specifics to methods like validate_create_conditions and validate_update_conditions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By integrating these design patterns and principles, the refactoring aims to achieve a more robust, maintainable, and scalable system. This approach not only addresses current complexities but also lays a foundation for easier future enhancements and modifications.&lt;br /&gt;
&lt;br /&gt;
== Class Diagram ==&lt;br /&gt;
[[File:controller_Class_diagram.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==  Use cases ==&lt;br /&gt;
[[File:Use_cases_controller.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solutions/Details of Changes Made==&lt;br /&gt;
=== Response Model ===&lt;br /&gt;
Methods within the response model were refactored or introduced, including:&lt;br /&gt;
==== set_content ====&lt;br /&gt;
Redesigned to gather and prepare the required data for response objects, optimizing the interaction with associated models&lt;br /&gt;
==== validate_params ====&lt;br /&gt;
This is the original method that was 46 lines long: &lt;br /&gt;
&lt;br /&gt;
[[File:Validate parameters before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===This method was significantly refactored to improve parameter validation. It was split into multiple smaller, focused methods, each dedicated to handling a specific aspect of the validation process. Each new method does one thing only, which makes them easier to understand and maintain.===&lt;br /&gt;
* assign_map_id_from_params: Sets the map_id for the response based on the provided parameters, ensuring the correct map ID is used for both creating and updating responses.&lt;br /&gt;
[[File:Assign map id.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_and_validate_response_map: Establishes and validates the presence of the response_map based on map_id. It's crucial to ensure that any response being created or updated is linked to a valid response map.This method attempts to find a ResponseMap based on map_id. If it fails to find one, it records an error and halts further validation, signaling an issue early in the process.&lt;br /&gt;
[[File:Set and validte response.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*set_response_attributes(params):Assigns additional attributes to the response object from the parameters. This centralizes attribute setting, reducing redundancy and errors.Directly extracts values like round, version_num, additional_comment, and visibility from the parameters and assigns them to the response object.&lt;br /&gt;
[[File:Set response attributes.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*action_specific_validation(params, action): Directs the validation flow based on whether the action is to create or update a response, organizing the logic clearly and preventing condition sprawl in the main validation method.Calls specific validation methods based on the action type: validate_create_conditions for creation and validate_update_conditions for updates.&lt;br /&gt;
[[File:Action specific validation.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_create_conditions: Ensures that a new response doesn't duplicate an existing one under the same response map, round, and version number.Searches for an existing response that matches the current map_id, round, and version_num. If such a response exists, it adds a validation error and prevents the creation of a duplicate response.&lt;br /&gt;
[[File:Validate create condition.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_update_conditions(params): Ensures that updates to a response are valid, specifically checking that a response isn't already submitted and that its map_id remains unchanged.Checks the submission status and whether there's an attempt to change the map_id. If either condition is violated, it records an error.&lt;br /&gt;
[[File:Validate update conditions.png|900px]]&lt;br /&gt;
&lt;br /&gt;
*validate_submission_status(params): Updates the submission status of the response during the update process, ensuring the attribute is correctly set based on the provided parameters.Extracts and sets the is_submitted status from the parameters, which is crucial for controlling the editability of the response.&lt;br /&gt;
[[File:Validate submission status .png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== serialize_response ====&lt;br /&gt;
Improved to efficiently serialize response data for API interactions, enhancing the clarity and usability of data exchanges.&lt;br /&gt;
&lt;br /&gt;
=== Response Controller ===&lt;br /&gt;
The ResponseController, originally extensive with numerous functions beyond basic CRUD operations, has been streamlined for our API application. In this context, there's no need to manage data variables for view pages, simplifying the handling of request data solely through request methods.To enhance the architecture and efficiency of our application, we've eliminated redundant methods and consolidated functionalities across the model, controller, and helper files. This restructuring was essential for refining the response endpoints specifically tailored for an API application.&lt;br /&gt;
&lt;br /&gt;
Before we added Basic CRUD like New, Create, Update, edit, destroy.&lt;br /&gt;
&lt;br /&gt;
Removed Methods: Legacy methods like Questionnaire_from_response_map and Questionnaire_from_response were removed following the refactoring of set_content, which now handles its functionalities internally without the need for these methods.&lt;br /&gt;
&lt;br /&gt;
==== Show_calibration_results_for_student ====&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[File:Show calibration results for student.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The old implementation also made use of database queries in the view.  This will not be possible in the reimplemented Expertiza, and the required data will need to be made available in the JSON response sent by the controller.  &lt;br /&gt;
[[File:DB access in view.PNG|900px]]&lt;br /&gt;
[[File:DB access in view 2.PNG|900px]]&lt;br /&gt;
&lt;br /&gt;
The new show_calibration_results_for_student method retrieves and displays calibration and review responses based on provided map IDs. It fetches responses using these IDs, retrieves associated questions and answers, and returns the data as a formatted JSON object. If a response is not found, it returns an error indicating the missing response. The method handles any exceptions by returning a standard error message, ensuring robust error handling throughout the process.&lt;br /&gt;
Serves as an API endpoint to fetch detailed response data for a student's calibration and review tasks, providing all necessary details about the questions asked and the answers provided in both contexts&lt;br /&gt;
&lt;br /&gt;
[[File:Show_calibration_results.png|900px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Response Helper ===&lt;br /&gt;
&lt;br /&gt;
The method create_update_answers(response, answers) was originally handling both the creation and updating of answer records within a single method: &lt;br /&gt;
&lt;br /&gt;
[[File:Create_update_answers_before.png|900px]]&lt;br /&gt;
&lt;br /&gt;
To improve code maintainability and adhere to the Single Responsibility Principle, this method has been divided into two distinct methods:&lt;br /&gt;
&lt;br /&gt;
==== Create_answers ====&lt;br /&gt;
This method focuses solely on creating new answer records. It iterates over the answers provided, checking if each answer does not already exist in the database. If the answer does not exist, it creates a new record for that answer. This ensures that each answer is unique and prevents duplication.&lt;br /&gt;
[[File:Create_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==== Update_answers ====&lt;br /&gt;
This method is responsible for updating existing answer records. It searches for existing answers in the database based on the response and question identifiers. If an answer is found, it updates the existing record with the new information provided. This method ensures that all modifications to answers are captured accurately and that the database is kept up-to-date.&lt;br /&gt;
&lt;br /&gt;
[[File:Update_answers_after.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Files Modified/Added==&lt;br /&gt;
List of primary files modified or created includes:&lt;br /&gt;
* responses_controller.rb&lt;br /&gt;
* response_helper.rb&lt;br /&gt;
* response.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test==&lt;br /&gt;
&lt;br /&gt;
===Validate Parameters===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
&lt;br /&gt;
[[File:Postman_after_update.png|900px]]&lt;br /&gt;
[[File:DB validate parameters update test.png|900px]]&lt;br /&gt;
&lt;br /&gt;
===Separated Answer Creation and Update Logic===&lt;br /&gt;
====Postman Tests====&lt;br /&gt;
Creation:&lt;br /&gt;
[[File:Postman after create for answer.png|900px]]&lt;br /&gt;
[[File:DB after create.png|900px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:Postman after update for answer.png|900px]]&lt;br /&gt;
[[File:DB after update.png|900px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
===== Mentor===== &lt;br /&gt;
*Ameya Vaichalkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Jeff Riehle&lt;br /&gt;
* Maday Moya&lt;br /&gt;
* Shardul Ladekar&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
Postman Video Links:&lt;br /&gt;
*create: https://youtu.be/hXQl-JkfuUc&lt;br /&gt;
*update: https://youtu.be/BeifLsCRQlk&lt;br /&gt;
*show_calibration_results_for_student: https://www.youtube.com/watch?v=ltJarFGb25k&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/92&lt;br /&gt;
&lt;br /&gt;
Model Tests Video: https://youtu.be/7x8x4l3AksE&lt;br /&gt;
&lt;br /&gt;
Controller Tests Video: https://youtu.be/0PV-ycXfyZU&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>Bkurra</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157633</id>
		<title>User:Bkurra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Bkurra&amp;diff=157633"/>
		<updated>2024-10-29T20:56:11Z</updated>

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

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

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