<?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=Jjshah</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=Jjshah"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jjshah"/>
	<updated>2026-09-30T18:00:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Design_for_Automatic_Evaluation_of_Peer_Reviews&amp;diff=165341</id>
		<title>Design for Automatic Evaluation of Peer Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Design_for_Automatic_Evaluation_of_Peer_Reviews&amp;diff=165341"/>
		<updated>2025-04-28T21:28:14Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Created page with &amp;quot;= Evaluate Using LLMs Integration =  == What we want to do ==  The goal of this project is to allow instructors to '''view an evaluation of each reviewer’s overall reviewing performance'''. Rather than looking at individual reviews, instructors will get a '''summary report''' describing how well each reviewer performed overall. The evaluation includes aspects like quality of comments, score consistency, engagement, and other rubric-related metrics. This report will be...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Evaluate Using LLMs Integration =&lt;br /&gt;
&lt;br /&gt;
== What we want to do ==&lt;br /&gt;
&lt;br /&gt;
The goal of this project is to allow instructors to '''view an evaluation of each reviewer’s overall reviewing performance'''.&lt;br /&gt;
Rather than looking at individual reviews, instructors will get a '''summary report''' describing how well each reviewer performed overall.&lt;br /&gt;
The evaluation includes aspects like quality of comments, score consistency, engagement, and other rubric-related metrics.&lt;br /&gt;
This report will be generated using a '''Large Language Model (LLM)''', such as GPT.&lt;br /&gt;
&lt;br /&gt;
Thus, instructors and TAs will be able to '''edit, overwrite, and finalize reviewer evaluation''' based on the LLM-generated suggestions.&lt;br /&gt;
&lt;br /&gt;
== How it is going to be added to Expertiza ==&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Evaluate using LLM&amp;quot; option has been added to the '''dropdown menu''' alongside Review Report, Author Feedback Report, etc.&lt;br /&gt;
&lt;br /&gt;
When the instructor selects &amp;quot;Evaluate using LLM&amp;quot; and clicks View:&lt;br /&gt;
* Review data (responses, reviewer info, reviewee info, scores, comments, etc.) is gathered.&lt;br /&gt;
* The data is sent to an '''external API''' (currently stubbed with fake data).&lt;br /&gt;
* The returned evaluation is populated into an '''editable table view''' similar to the existing Review Report.&lt;br /&gt;
&lt;br /&gt;
=== Classes ===&lt;br /&gt;
* '''LlmEvaluationService''': Located in `app/services/llm_evaluation_service.rb`. Handles outbound API requests and inbound responses.&lt;br /&gt;
* '''ReportsController''': New method `llm_evaluation_report` added to generate the LLM evaluation page.&lt;br /&gt;
&lt;br /&gt;
=== Web Service(s) ===&lt;br /&gt;
* '''External API call''': Currently stubbed with fake data.&lt;br /&gt;
* '''View partial''': `_llm_evaluation_report.html.erb` created to display editable evaluations.&lt;br /&gt;
&lt;br /&gt;
== How much of it is implemented now ==&lt;br /&gt;
&lt;br /&gt;
The following parts are fully working:&lt;br /&gt;
* &amp;quot;Evaluate using LLM&amp;quot; dropdown option in the _searchbox.html.erb partial.&lt;br /&gt;
* Routing to the correct controller action (`llm_evaluation_report`).&lt;br /&gt;
* Service object (`LlmEvaluationService`) created to collect and send review data.&lt;br /&gt;
* Stubbed API returning a hardcoded response.&lt;br /&gt;
* Editable report table rendered via a new partial called _llm_evaluation_report.html.erb.&lt;br /&gt;
* &amp;quot;Overwrite&amp;quot; button added (placeholder functionality). Modify the submit method to overwrite the already existing grades and comments in the reviews_grade table with the LLM generated grades and comments.&lt;br /&gt;
&lt;br /&gt;
Thus, the feature '''end-to-end works with fake data''' for now.&lt;br /&gt;
&lt;br /&gt;
== How to continue development ==&lt;br /&gt;
&lt;br /&gt;
To complete this project:&lt;br /&gt;
* Connect to the '''real LLM API''' instead of fake responses.&lt;br /&gt;
* Work on the schema for reviews_grade table to incorporate the LLM generated scores and feedback in a new column.&lt;br /&gt;
* Implement '''saving''' functionality for the &amp;quot;Overwrite&amp;quot; button which will overwrite the grade_for_reviewer and comment_for_reviewer that already exists with the LLM generated grades and comments.&lt;br /&gt;
* Add robust '''error handling''' (for timeout, API errors, etc.).&lt;br /&gt;
* Extend support for '''multiple rounds''' and '''varying rubrics'''.&lt;br /&gt;
* Add '''RSpec tests''' for the service and controller logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pull request details ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The pull request contains the following:&lt;br /&gt;
&lt;br /&gt;
*'''New dropdown entry: Evaluate using LLM'''  &lt;br /&gt;
A new option titled &amp;quot;Evaluate using LLM&amp;quot; has been added alongside existing report types (such as Review report, Author feedback report) in the reports searchbox partial (`_searchbox.html.erb`). This allows instructors and TAs to select the LLM-based evaluation report from the interface just like any other report type.&lt;br /&gt;
&lt;br /&gt;
*'''New controller action: llm_evaluation_report'''  &lt;br /&gt;
The `llm_evaluation_report` method has been introduced inside the `ReportsController`. This action is responsible for gathering the necessary assignment and participant data, invoking the service object to fetch LLM-evaluated responses, and rendering the new LLM Evaluation Report view for the instructor or TA.&lt;br /&gt;
&lt;br /&gt;
*'''New service object: LlmEvaluationService'''  &lt;br /&gt;
A service class `LlmEvaluationService` has been created under `app/services/llm_evaluation_service.rb`. This service collects review and reviewer information from the database, formats it into the expected API request payload, sends a POST request to an external (currently dummy) LLM evaluation API using `HTTParty`, and parses the received response into a structured format that can be easily rendered in the view.&lt;br /&gt;
&lt;br /&gt;
*'''Dummy API interaction using HTTParty'''  &lt;br /&gt;
For now, the API interaction is stubbed using a static JSON response that simulates an LLM’s feedback. This stubbed interaction ensures the full data flow is functional even without a live backend service. The dummy API response provides evaluation metrics such as reviewer scores, average scores, and LLM-generated comments for the reviews.&lt;br /&gt;
&lt;br /&gt;
*'''New view partial: _llm_evaluation_report.html.erb'''  &lt;br /&gt;
A new view partial `_llm_evaluation_report.html.erb` has been created to display the LLM evaluation report. The styling and table structure closely follow the traditional Review Report design. It presents reviewer names, the number of reviews completed, teams reviewed, scores (both awarded and average), review volume metrics, and editable input fields for grades and comments.&lt;br /&gt;
&lt;br /&gt;
*'''Editable fields populated with API-returned evaluation data'''  &lt;br /&gt;
The fields for assigning grades and writing comments are populated directly from the LLM-evaluated API data. These fields remain editable so that instructors and TAs can modify the suggested grades and comments before deciding to overwrite and save them manually if needed.&lt;br /&gt;
&lt;br /&gt;
*'''&amp;quot;Overwrite&amp;quot; button for future saving'''  &lt;br /&gt;
Each review entry now features an &amp;quot;Overwrite&amp;quot; button that is intended to allow instructors to save changes made to the LLM-suggested evaluations. Currently, this button is connected to a placeholder action, and future development will implement functionality to update and persist these evaluations into the database.&lt;br /&gt;
&lt;br /&gt;
*'''Updated routes and views to integrate the feature cleanly'''  &lt;br /&gt;
The `routes.rb` file was modified to define a route for the new `llm_evaluation_report` controller action. Additionally, `response_report.html.haml` was updated to render the `_llm_evaluation_report.html.erb` partial when the user selects the &amp;quot;Evaluate using LLM&amp;quot; report type, ensuring a seamless integration into the existing reporting infrastructure.&lt;br /&gt;
&lt;br /&gt;
The pull request provides a '''working prototype''' ready to be connected to a real API.&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/Independent_Study_Automatic_Evaluation_of_Peer_Reviews&amp;diff=165294</id>
		<title>CSC/Independent Study Automatic Evaluation of Peer Reviews</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/Independent_Study_Automatic_Evaluation_of_Peer_Reviews&amp;diff=165294"/>
		<updated>2025-04-28T19:18:03Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Created page with &amp;quot;= Evaluate Using LLMs Integration =  == Team Information ==  '''Mentor:''' * Ed Gehringer  '''Team Members:'''  * Jay Shah (jjshah)  * Rushabh Shah (rsshah7)  * Uchswas Paul (upaul)  '''Relevant Links:'''  [https://github.com/expertiza/expertiza Link to Expertiza Repository]  [https://github.com/jayjshah2000/expertiza Link to Forked Repository]  [https://github.com/expertiza/expertiza/pull/2958 Link to Pull Request]  == Expertiza Background ==  Expertiza is an open-sourc...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Evaluate Using LLMs Integration =&lt;br /&gt;
&lt;br /&gt;
== Team Information ==&lt;br /&gt;
&lt;br /&gt;
'''Mentor:'''&lt;br /&gt;
* Ed Gehringer&lt;br /&gt;
&lt;br /&gt;
'''Team Members:''' &lt;br /&gt;
* Jay Shah (jjshah) &lt;br /&gt;
* Rushabh Shah (rsshah7) &lt;br /&gt;
* Uchswas Paul (upaul)&lt;br /&gt;
&lt;br /&gt;
'''Relevant Links:'''&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Link to Expertiza Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jayjshah2000/expertiza Link to Forked Repository]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/2958 Link to Pull Request]&lt;br /&gt;
&lt;br /&gt;
== Expertiza Background ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open-source project built with the Ruby on Rails MVC framework.&lt;br /&gt;
It facilitates peer reviews and collaborative learning activities in educational environments.&lt;br /&gt;
&lt;br /&gt;
== About &amp;quot;Evaluate Using LLMs&amp;quot; Feature ==&lt;br /&gt;
&lt;br /&gt;
* This project adds a new &amp;quot;Evaluate using LLM&amp;quot; feature to Expertiza.&lt;br /&gt;
* It enables instructors and TAs to automate the evaluation of peer reviews using an external LLM (Language Model) API.&lt;br /&gt;
* The evaluated scores and comments are editable, similar to the manual review report.&lt;br /&gt;
&lt;br /&gt;
== Problem Statement == &lt;br /&gt;
&lt;br /&gt;
'''Prior to this work:'''&lt;br /&gt;
&lt;br /&gt;
*Review quality was graded manually by instructors/TAs.&lt;br /&gt;
&lt;br /&gt;
*No automation or AI-assistance existed to assess reviews.&lt;br /&gt;
&lt;br /&gt;
'''The goal:'''&lt;br /&gt;
&lt;br /&gt;
* Send all review data to an external LLM.&lt;br /&gt;
&lt;br /&gt;
* Retrieve scores and comments.&lt;br /&gt;
&lt;br /&gt;
* Populate the review report dynamically.&lt;br /&gt;
&lt;br /&gt;
* Allow instructor/TAs to edit or overwrite the LLM evaluation.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
&lt;br /&gt;
* Add &amp;quot;Evaluate using LLM&amp;quot; option in report dropdown.&lt;br /&gt;
&lt;br /&gt;
* Create service object ('''LlmEvaluationService''') for API communication.&lt;br /&gt;
&lt;br /&gt;
* Build new partial view ('''_llm_evaluation_report.html.erb''').&lt;br /&gt;
&lt;br /&gt;
* Allow editing of scores and comments returned by LLM.&lt;br /&gt;
&lt;br /&gt;
* Integrate LLM report with the existing report framework.&lt;br /&gt;
&lt;br /&gt;
* Use a stubbed (fake) API response for now.&lt;br /&gt;
&lt;br /&gt;
== Plan of Work ==&lt;br /&gt;
&lt;br /&gt;
* Study how Review Report (ReviewResponseMap) is generated.&lt;br /&gt;
* Create service to send review data to API and receive evaluation.&lt;br /&gt;
* Develop view partial for LLM Evaluation Report.&lt;br /&gt;
* Modify report dropdown to include &amp;quot;Evaluate using LLM&amp;quot; option.&lt;br /&gt;
* Update ReportsController to support LLM Evaluation.&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object ===&lt;br /&gt;
&lt;br /&gt;
'''File:''' app/services/llm_evaluation_service.rb&lt;br /&gt;
&lt;br /&gt;
Collects review data, calls dummy API, returns structured evaluation.&lt;br /&gt;
&lt;br /&gt;
=== New View ===&lt;br /&gt;
&lt;br /&gt;
'''File:''' app/views/reports/_llm_evaluation_report.html.erb&lt;br /&gt;
&lt;br /&gt;
Displays LLM-evaluated results.&lt;br /&gt;
&lt;br /&gt;
Editable fields (Score, Comment).&lt;br /&gt;
&lt;br /&gt;
Exportable to CSV.&lt;br /&gt;
&lt;br /&gt;
=== Controller Modification ===&lt;br /&gt;
&lt;br /&gt;
'''File:''' app/controllers/reports_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''Method Added:''' llm_evaluation_report&lt;br /&gt;
&lt;br /&gt;
=== Dropdown Modification ===&lt;br /&gt;
&lt;br /&gt;
'''File:''' app/views/reports/_searchbox.html.erb&lt;br /&gt;
&lt;br /&gt;
Added &amp;quot;Evaluate using LLM&amp;quot; to the report selection.&lt;br /&gt;
&lt;br /&gt;
=== API Stub ===&lt;br /&gt;
&lt;br /&gt;
Fake JSON response mimicking future LLM output.&lt;br /&gt;
&lt;br /&gt;
== Fake API Response ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; [ { &amp;quot;reviewer_name&amp;quot;: &amp;quot;John Doe&amp;quot;, &amp;quot;reviewer_id&amp;quot;: 101, &amp;quot;team_reviewed&amp;quot;: &amp;quot;Team Alpha&amp;quot;, &amp;quot;reviews_done&amp;quot;: 3, &amp;quot;score_awarded&amp;quot;: 90, &amp;quot;avg_score&amp;quot;: 88, &amp;quot;metrics&amp;quot;: &amp;quot;Volume: 45 words&amp;quot;, &amp;quot;grade_for_reviewer&amp;quot;: 95, &amp;quot;comment_for_reviewer&amp;quot;: &amp;quot;Great feedback with actionable suggestions.&amp;quot; } ] &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
* Verified dropdown functionality.&lt;br /&gt;
&lt;br /&gt;
* Verified table rendering and editable fields.&lt;br /&gt;
&lt;br /&gt;
* Confirmed dummy API data is properly injected.&lt;br /&gt;
&lt;br /&gt;
* Ensured no effect on existing reports (review, feedback, calibration, etc.)&lt;br /&gt;
&lt;br /&gt;
== Future Work ==&lt;br /&gt;
&lt;br /&gt;
* Replace dummy API with real LLM API integration.&lt;br /&gt;
&lt;br /&gt;
* Allow asynchronous API calls for large assignments.&lt;br /&gt;
&lt;br /&gt;
* Save updated instructor edits after LLM evaluation.&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152633</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152633"/>
		<updated>2023-12-05T04:36:02Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Description of Project==&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
==Objectives==&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
==Development Strategy, Project Design and Implementation==&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
=== Functionality ===&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png|1400px]]&lt;br /&gt;
[[File:2386_3.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png|1400px]]&lt;br /&gt;
[[File:2386_6.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png|1400px]]&lt;br /&gt;
[[File:2386_9.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/66&lt;br /&gt;
&lt;br /&gt;
Video: https://drive.google.com/file/d/1HkfvPSDFRu7zLEhNlopIkfnjAsrwPykp/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
==Team Members==&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
==Mentor==&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152624</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152624"/>
		<updated>2023-12-05T04:31:40Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Description of Project==&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
==Objectives==&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
==Development Strategy==&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
==Project Design and Implementation==&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
=== Functionality ===&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
==Code Snippets==&lt;br /&gt;
&lt;br /&gt;
===Model===&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Schema===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png|1400px]]&lt;br /&gt;
[[File:2386_3.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png|1400px]]&lt;br /&gt;
[[File:2386_6.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png|1400px]]&lt;br /&gt;
[[File:2386_9.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
==Relevant Links==&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/66&lt;br /&gt;
&lt;br /&gt;
Video: https://drive.google.com/file/d/1HkfvPSDFRu7zLEhNlopIkfnjAsrwPykp/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
==Team Members==&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
==Mentor==&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152422</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152422"/>
		<updated>2023-12-05T01:16:55Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Relevant Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png|1400px]]&lt;br /&gt;
[[File:2386_3.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png|1400px]]&lt;br /&gt;
[[File:2386_6.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png|1400px]]&lt;br /&gt;
[[File:2386_9.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/66&lt;br /&gt;
&lt;br /&gt;
Video: https://drive.google.com/file/d/1HkfvPSDFRu7zLEhNlopIkfnjAsrwPykp/view?usp=sharing&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152225</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152225"/>
		<updated>2023-12-04T10:23:41Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Relevant Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png|1400px]]&lt;br /&gt;
[[File:2386_3.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png|1400px]]&lt;br /&gt;
[[File:2386_6.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png|1400px]]&lt;br /&gt;
[[File:2386_9.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
Pull request: https://github.com/expertiza/reimplementation-back-end/pull/66&lt;br /&gt;
&lt;br /&gt;
Video:&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152224</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152224"/>
		<updated>2023-12-04T10:11:31Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png|1400px]]&lt;br /&gt;
[[File:2386_3.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png|1400px]]&lt;br /&gt;
[[File:2386_6.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png|1400px]]&lt;br /&gt;
[[File:2386_9.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152223</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152223"/>
		<updated>2023-12-04T10:09:45Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1400px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png]]&lt;br /&gt;
[[File:2386_3.png]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png]]&lt;br /&gt;
[[File:2386_6.png]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png]]&lt;br /&gt;
[[File:2386_9.png]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152222</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152222"/>
		<updated>2023-12-04T10:09:09Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png]]&lt;br /&gt;
[[File:2386_3.png]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png]]&lt;br /&gt;
[[File:2386_6.png]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png]]&lt;br /&gt;
[[File:2386_9.png]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152221</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152221"/>
		<updated>2023-12-04T10:08:38Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|700px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png]]&lt;br /&gt;
[[File:2386_3.png]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png]]&lt;br /&gt;
[[File:2386_6.png]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png]]&lt;br /&gt;
[[File:2386_9.png]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152220</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152220"/>
		<updated>2023-12-04T10:08:07Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png|100px]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png]]&lt;br /&gt;
[[File:2386_3.png]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png]]&lt;br /&gt;
[[File:2386_6.png]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png]]&lt;br /&gt;
[[File:2386_9.png]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152219</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152219"/>
		<updated>2023-12-04T10:04:42Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
List teams user:&lt;br /&gt;
[[File:2386_1.png]]&lt;br /&gt;
&lt;br /&gt;
Create teams user:&lt;br /&gt;
[[File:2386_2_2.png]]&lt;br /&gt;
[[File:2386_3.png]]&lt;br /&gt;
&lt;br /&gt;
Added to database on creating:&lt;br /&gt;
[[File:2386_4.png]]&lt;br /&gt;
&lt;br /&gt;
Update:&lt;br /&gt;
[[File:2386_5.png]]&lt;br /&gt;
[[File:2386_6.png]]&lt;br /&gt;
&lt;br /&gt;
Database after updating:&lt;br /&gt;
[[File:2386_7.png]]&lt;br /&gt;
&lt;br /&gt;
Delete:&lt;br /&gt;
[[File:2386_8.png]]&lt;br /&gt;
[[File:2386_9.png]]&lt;br /&gt;
&lt;br /&gt;
Database after deleting:&lt;br /&gt;
[[File:2386_10.png]]&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_3.png&amp;diff=152218</id>
		<title>File:2386 3.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_3.png&amp;diff=152218"/>
		<updated>2023-12-04T09:59:26Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_10.png&amp;diff=152217</id>
		<title>File:2386 10.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_10.png&amp;diff=152217"/>
		<updated>2023-12-04T09:56:50Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_9.png&amp;diff=152216</id>
		<title>File:2386 9.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_9.png&amp;diff=152216"/>
		<updated>2023-12-04T09:56:27Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_8.png&amp;diff=152215</id>
		<title>File:2386 8.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_8.png&amp;diff=152215"/>
		<updated>2023-12-04T09:55:56Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_7.png&amp;diff=152214</id>
		<title>File:2386 7.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_7.png&amp;diff=152214"/>
		<updated>2023-12-04T09:55:33Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_6.png&amp;diff=152213</id>
		<title>File:2386 6.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_6.png&amp;diff=152213"/>
		<updated>2023-12-04T09:55:00Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_5.png&amp;diff=152212</id>
		<title>File:2386 5.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_5.png&amp;diff=152212"/>
		<updated>2023-12-04T09:54:27Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_4.png&amp;diff=152211</id>
		<title>File:2386 4.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_4.png&amp;diff=152211"/>
		<updated>2023-12-04T09:54:03Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2_2.png&amp;diff=152210</id>
		<title>File:2386 2 2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2_2.png&amp;diff=152210"/>
		<updated>2023-12-04T09:53:10Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152209</id>
		<title>File:2386 2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152209"/>
		<updated>2023-12-04T09:51:39Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Jjshah uploaded a new version of File:2386 2.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152208</id>
		<title>File:2386 2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152208"/>
		<updated>2023-12-04T09:50:58Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Jjshah uploaded a new version of File:2386 2.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152207</id>
		<title>File:2386 2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_2.png&amp;diff=152207"/>
		<updated>2023-12-04T09:46:40Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_1.png&amp;diff=152206</id>
		<title>File:2386 1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:2386_1.png&amp;diff=152206"/>
		<updated>2023-12-04T09:46:08Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152205</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152205"/>
		<updated>2023-12-04T09:42:28Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Test cases for TeamsUsersController using SwaggerUI:'''&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152204</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152204"/>
		<updated>2023-12-04T09:36:52Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152203</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152203"/>
		<updated>2023-12-04T09:36:05Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Verifies that the `name` method of a `TeamsUser` instance returns the name of the associated user.  &lt;br /&gt;
|-&lt;br /&gt;
| 2 || `.remove_team` || Tests the `remove_team` method, ensuring that it removes the corresponding entry in the `TeamsUser` table by creating a `TeamsUser` record, calling `remove_team`, and checking if the entry is removed.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || `.first_by_team_id` || Validates that the `first_by_team_id` method returns the first `TeamsUser` instance associated with a specific team by creating a `TeamsUser` record and checking if the method correctly retrieves it. &lt;br /&gt;
|-&lt;br /&gt;
| 4 || `.team_empty?`  || Checks the `team_empty?` method, verifying that it returns `true` if a team has no associated users (empty team), and `false` if there is at least one user associated with the team.                                                    |&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152202</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152202"/>
		<updated>2023-12-04T09:33:04Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Test cases for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Name !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || `#name` || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152201</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152201"/>
		<updated>2023-12-04T09:30:24Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
'''Tests for teams_users model:'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152200</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152200"/>
		<updated>2023-12-04T09:22:20Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152199</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152199"/>
		<updated>2023-12-04T09:21:54Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Code Snippets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods to return the name of the user based on ip_address. Then it includes a method that removes entry in the TeamUsers table for the given user and given team id. Another method returns the first entry in the TeamUsers table for a given team id and the last method determines whether a team is empty or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods that lists all teams_users, gets the teams_users of a particular team, renders a form to create a new teams_user for a specific team, creates a new teams_user, updates an existing teams_user, removes a teams_user and calls methods on the TeamsUser model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Api::V1::TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :find_teams_user, only: [:update, :destroy]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :teams_user_not_found&lt;br /&gt;
  rescue_from ActionController::ParameterMissing, with: :parameter_missing&lt;br /&gt;
&lt;br /&gt;
  # GET /teams_users&lt;br /&gt;
  # List all the teams_users&lt;br /&gt;
  def index&lt;br /&gt;
    teams_users = TeamsUser.all&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1&lt;br /&gt;
  # Get the team_users of a particular team&lt;br /&gt;
  def show&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    teams_users = TeamsUser.where(team_id: params[:id])&lt;br /&gt;
    render json: teams_users, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # GET /teams/1/teams_users/new&lt;br /&gt;
  # Render form to create a new teams_user for a specific team&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    render json: team, status: :ok&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # POST /teams_users&lt;br /&gt;
  # Create a new teams_user&lt;br /&gt;
  def create&lt;br /&gt;
    teams_user = TeamsUser.new(teams_user_params)&lt;br /&gt;
    if teams_user.save&lt;br /&gt;
      render json: teams_user, status: :created&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # PATCH/PUT /teams_users/1&lt;br /&gt;
  # Update an existing teams_user&lt;br /&gt;
  def update&lt;br /&gt;
    if @teams_user.update(teams_user_params)&lt;br /&gt;
      render json: @teams_user, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: @teams_user.errors.full_messages }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # DELETE /teams_users/1&lt;br /&gt;
  # Remove a teams_user&lt;br /&gt;
  def destroy&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
&lt;br /&gt;
    if @teams_user.destroy&lt;br /&gt;
      render json: { message: 'TeamsUser removed successfully' }, status: :no_content&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Failed to remove TeamsUser' }, status: :unprocessable_entity&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def find_teams_user&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_params&lt;br /&gt;
    params.require(:teams_user).permit(:team_id, :user_id, :duty_id, :pair_programming_status, :participant_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def teams_user_not_found&lt;br /&gt;
    render json: { error: &amp;quot;TeamsUser with id #{params[:id]} not found&amp;quot; }, status: :not_found&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def parameter_missing&lt;br /&gt;
    render json: { error: &amp;quot;Parameter missing&amp;quot; }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def redirect_to_teams_list(parent_id, flash_message)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id, flash: { success: flash_message }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, charset: &amp;quot;utf8mb4&amp;quot;, collation: &amp;quot;utf8mb4_0900_ai_ci&amp;quot;, force: :cascade do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.datetime &amp;quot;created_at&amp;quot;, null: false&lt;br /&gt;
    t.datetime &amp;quot;updated_at&amp;quot;, null: false&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following image shows the tables referencing teams_users table is referencing to&lt;br /&gt;
[[File:teams_users_export.png]]&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152198</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152198"/>
		<updated>2023-12-04T09:04:53Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Project Design and Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
We have added the teams_user model and TeamsUserController and have outlined a set of RESTful endpoints along with their corresponding request types for implementation to facilitate CRUD operations on teams_users. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve teams_users of a particular team from the database.&lt;br /&gt;
&lt;br /&gt;
2. Display all teams_users.&lt;br /&gt;
&lt;br /&gt;
3. Add a new teams_user. &lt;br /&gt;
&lt;br /&gt;
4. Update an existing teams_user.&lt;br /&gt;
&lt;br /&gt;
4. Delete a specific teams_user.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152197</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152197"/>
		<updated>2023-12-04T08:55:26Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Development Strategy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the teams_user model and the TeamsUsersController. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152196</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152196"/>
		<updated>2023-12-04T08:50:37Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Objectives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering both the models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the Invitation model and the Invitation Controller. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
Furthermore, we align with the Rails philosophy of &amp;quot;Fat models,&amp;quot; aiming to migrate substantial business logic from the controller to the model. This approach is intended to maintain a clean and organized controller codebase while promoting code reusability throughout the application.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152195</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152195"/>
		<updated>2023-12-04T08:44:31Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The main aim of the project is to create a backend for teams_users_controller. The team needs to write appropriate test cases for the models as well as refactor the code to make sure the correct JSON response is being returned. The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Establish a user-invitation system that empowers invited users to accept, decline, or cancel invitations, triggering corresponding updates to the associated teams_user records. This should seamlessly manage the addition or removal of users from teams.&lt;br /&gt;
&lt;br /&gt;
*Implement an email notification system within the user-invitation framework, sending email notifications to invited users upon the issuance of new invitations.&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering all APIs, models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the Invitation model and the Invitation Controller. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
Furthermore, we align with the Rails philosophy of &amp;quot;Fat models,&amp;quot; aiming to migrate substantial business logic from the controller to the model. This approach is intended to maintain a clean and organized controller codebase while promoting code reusability throughout the application.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152194</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=152194"/>
		<updated>2023-12-04T08:41:09Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Description of Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_users_controller.rb, teams_user.rb model capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Establish a user-invitation system that empowers invited users to accept, decline, or cancel invitations, triggering corresponding updates to the associated teams_user records. This should seamlessly manage the addition or removal of users from teams.&lt;br /&gt;
&lt;br /&gt;
*Implement an email notification system within the user-invitation framework, sending email notifications to invited users upon the issuance of new invitations.&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering all APIs, models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the Invitation model and the Invitation Controller. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
Furthermore, we align with the Rails philosophy of &amp;quot;Fat models,&amp;quot; aiming to migrate substantial business logic from the controller to the model. This approach is intended to maintain a clean and organized controller codebase while promoting code reusability throughout the application.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151983</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151983"/>
		<updated>2023-12-03T02:32:14Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Objectives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_user model, capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, updating and deleting teams users. &lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate CRUD operations&lt;br /&gt;
&lt;br /&gt;
*Establish a user-invitation system that empowers invited users to accept, decline, or cancel invitations, triggering corresponding updates to the associated teams_user records. This should seamlessly manage the addition or removal of users from teams.&lt;br /&gt;
&lt;br /&gt;
*Implement an email notification system within the user-invitation framework, sending email notifications to invited users upon the issuance of new invitations.&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering all APIs, models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the Invitation model and the Invitation Controller. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
Furthermore, we align with the Rails philosophy of &amp;quot;Fat models,&amp;quot; aiming to migrate substantial business logic from the controller to the model. This approach is intended to maintain a clean and organized controller codebase while promoting code reusability throughout the application.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151982</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151982"/>
		<updated>2023-12-03T01:30:07Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: /* Description of Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the teams_user model, capturing information about team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the teams_user_controller, which orchestrates CRUD operations on the teams_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;teams_users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the teams_users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, and deleting invitations, along with approving new invitations. Additionally, provide functionality for listing pending invitations, creating new invitations, and notifying students about newly formed team invitations.&lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the teams_users_controller to facilitate invitation-related operations, including creating, accepting, declining, and canceling invitations. Ensure thorough checks of user and team statuses before initiating or accepting invitations.&lt;br /&gt;
&lt;br /&gt;
*Establish a user-invitation system that empowers invited users to accept, decline, or cancel invitations, triggering corresponding updates to the associated teams_user records. This should seamlessly manage the addition or removal of users from teams.&lt;br /&gt;
&lt;br /&gt;
*Implement an email notification system within the user-invitation framework, sending email notifications to invited users upon the issuance of new invitations.&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the teams_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering all APIs, models, and controllers to ensure the robustness and reliability of the entire system.&lt;br /&gt;
&lt;br /&gt;
===Development Strategy===&lt;br /&gt;
&lt;br /&gt;
Our development strategy adheres to the principles of Test-Driven Development (TDD) for the implementation of both the Invitation model and the Invitation Controller. The process begins with the creation of a failing test case, followed by the addition of code to address the identified issues and ensure the successful passage of the test.&lt;br /&gt;
&lt;br /&gt;
Furthermore, we align with the Rails philosophy of &amp;quot;Fat models,&amp;quot; aiming to migrate substantial business logic from the controller to the model. This approach is intended to maintain a clean and organized controller codebase while promoting code reusability throughout the application.&lt;br /&gt;
&lt;br /&gt;
===Project Design and Implementation===&lt;br /&gt;
&lt;br /&gt;
Considering the existing functionality of the teams_user model and controller, we have outlined a set of RESTful endpoints along with their corresponding request types for implementation. In the controller, we plan to adopt the Strategy Pattern, leveraging its ability to encapsulate controller actions and facilitate easy extensibility and usability. This pattern will enable a structured approach to defining and managing the various operations the controller can perform.&lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
In this project, we aim to add functions for the following:&lt;br /&gt;
&lt;br /&gt;
1. Retrieve and display team members.&lt;br /&gt;
&lt;br /&gt;
2. Add a new team member with checks for user existence and team limits.&lt;br /&gt;
&lt;br /&gt;
3. Delete a specific team member.&lt;br /&gt;
&lt;br /&gt;
4. Delete multiple selected team members based on item IDs.&lt;br /&gt;
&lt;br /&gt;
5. Autocomplete functionality for user names within a team.&lt;br /&gt;
&lt;br /&gt;
6. Updating duties of a team member.&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
The `TeamsUser` model in the Expertiza code represents a user's association with a team within the context of a collaborative assignment or project. It utilizes ActiveRecord associations to establish relationships with the `User` and `Team` models, indicating that a user belongs to a team. The model includes methods for deleting a team user, retrieving team members, removing a user from a team, checking if a team is empty, and adding a member to an invited team based on certain conditions. Additionally, there's a method for determining the team ID associated with a user in a specific assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUser &amp;lt; ApplicationRecord&lt;br /&gt;
  belongs_to :user&lt;br /&gt;
  belongs_to :team&lt;br /&gt;
  has_one :team_user_node, foreign_key: 'node_object_id', dependent: :destroy&lt;br /&gt;
  has_paper_trail&lt;br /&gt;
  # attr_accessible :user_id, :team_id # unnecessary protected attributes&lt;br /&gt;
&lt;br /&gt;
  def name(ip_address = nil)&lt;br /&gt;
    name = user.name(ip_address)&lt;br /&gt;
&lt;br /&gt;
    # E2115 Mentor Management&lt;br /&gt;
    # Indicate that someone is a Mentor in the UI. The view code is&lt;br /&gt;
    # often hard to follow, and this is the best place we could find&lt;br /&gt;
    # for this to go.&lt;br /&gt;
    name += ' (Mentor)' if MentorManagement.user_a_mentor?(user)&lt;br /&gt;
    name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    TeamUserNode.find_by(node_object_id: id).destroy&lt;br /&gt;
    team = self.team&lt;br /&gt;
    destroy&lt;br /&gt;
    team.delete if team.teams_users.empty?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def get_team_members(team_id); end&lt;br /&gt;
&lt;br /&gt;
  # Removes entry in the TeamUsers table for the given user and given team id&lt;br /&gt;
  def self.remove_team(user_id, team_id)&lt;br /&gt;
    team_user = TeamsUser.where('user_id = ? and team_id = ?', user_id, team_id).first&lt;br /&gt;
    team_user&amp;amp;.destroy&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns the first entry in the TeamUsers table for a given team id&lt;br /&gt;
  def self.first_by_team_id(team_id)&lt;br /&gt;
    TeamsUser.where('team_id = ?', team_id).first&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Determines whether a team is empty of not&lt;br /&gt;
  def self.team_empty?(team_id)&lt;br /&gt;
    team_members = TeamsUser.where('team_id = ?', team_id)&lt;br /&gt;
    team_members.blank?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Add member to the team they were invited to and accepted the invite for&lt;br /&gt;
  def self.add_member_to_invited_team(invitee_user_id, invited_user_id, assignment_id)&lt;br /&gt;
    can_add_member = false&lt;br /&gt;
    users_teams = TeamsUser.where(['user_id = ?', invitee_user_id])&lt;br /&gt;
    users_teams.each do |team|&lt;br /&gt;
      new_team = AssignmentTeam.where(['id = ? and parent_id = ?', team.team_id, assignment_id]).first&lt;br /&gt;
      unless new_team.nil?&lt;br /&gt;
        can_add_member = new_team.add_member(User.find(invited_user_id), assignment_id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    can_add_member&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # 2015-5-27 [zhewei]:&lt;br /&gt;
  # We just remove the topic_id field from the participants table.&lt;br /&gt;
  def self.team_id(assignment_id, user_id)&lt;br /&gt;
    # team_id variable represents the team_id for this user in this assignment&lt;br /&gt;
    team_id = nil&lt;br /&gt;
    teams_users = TeamsUser.where(user_id: user_id)&lt;br /&gt;
    teams_users.each do |teams_user|&lt;br /&gt;
      if teams_user.team_id == nil&lt;br /&gt;
        next&lt;br /&gt;
      end&lt;br /&gt;
      team = Team.find(teams_user.team_id)&lt;br /&gt;
      if team.parent_id == assignment_id&lt;br /&gt;
        team_id = teams_user.team_id&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
The `TeamsUsersController` handles various actions related to team management within the application. It includes methods for authorization checks, auto-completion of user names, updating team member duties, listing team members, creating new team members, deleting individual team members, and bulk deletion of selected team members. The controller also interacts with models such as `Team`, `Assignment`, `User`, and `TeamsUser` to manage teams, assignments, and users. Notably, the `create` method involves adding new team members, performing checks on user participation in assignments or courses, and triggering additional actions such as mentor assignments. The code emphasizes error handling and provides flash messages to communicate issues or successful operations to users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class TeamsUsersController &amp;lt; ApplicationController&lt;br /&gt;
  include AuthorizationHelper&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # Allow duty updation for a team if current user is student, else require TA or above Privileges.&lt;br /&gt;
    if %w[update_duties].include? params[:action]&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def auto_complete_for_user_name&lt;br /&gt;
    team = Team.find(session[:team_id])&lt;br /&gt;
    @users = team.get_possible_team_members(params[:user][:name])&lt;br /&gt;
    render inline: &amp;quot;&amp;lt;%= auto_complete_result @users, 'name' %&amp;gt;&amp;quot;, layout: false&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Example of duties: manager, designer, programmer, tester. Finds TeamsUser and save preferred Duty&lt;br /&gt;
  def update_duties&lt;br /&gt;
    team_user = TeamsUser.find(params[:teams_user_id])&lt;br /&gt;
    team_user.update_attribute(:duty_id, params[:teams_user]['duty_id'])&lt;br /&gt;
    redirect_to controller: 'student_teams', action: 'view', student_id: params[:participant_id]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def list&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
    @assignment = Assignment.find(@team.parent_id)&lt;br /&gt;
    @teams_users = TeamsUser.page(params[:page]).per_page(10).where(['team_id = ?', params[:id]])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
    @team = Team.find(params[:id])&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    user = User.find_by(name: params[:user][:name].strip)&lt;br /&gt;
    unless user&lt;br /&gt;
      urlCreate = url_for controller: 'users', action: 'new'&lt;br /&gt;
      flash[:error] = &amp;quot;\&amp;quot;#{params[:user][:name].strip}\&amp;quot; is not defined. Please &amp;lt;a href=\&amp;quot;#{urlCreate}\&amp;quot;&amp;gt;create&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    team = Team.find(params[:id])&lt;br /&gt;
    unless user.nil?&lt;br /&gt;
      if team.is_a?(AssignmentTeam)&lt;br /&gt;
        assignment = Assignment.find(team.parent_id)&lt;br /&gt;
        if assignment.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this assignment&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if AssignmentParticipant.find_by(user_id: user.id, parent_id: assignment.id).nil?&lt;br /&gt;
          urlAssignmentParticipantList = url_for controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current assignment. Please &amp;lt;a href=\&amp;quot;#{urlAssignmentParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          # E2115 Mentor Management&lt;br /&gt;
          # Kick off the Mentor Management workflow&lt;br /&gt;
          # Note: this is _not_ supported for CourseTeams which is why the other&lt;br /&gt;
          # half of this if block does not include the same code&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team @teams_user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
            MentorManagement.assign_mentor(assignment.id, team.id)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else # CourseTeam&lt;br /&gt;
        course = Course.find(team.parent_id)&lt;br /&gt;
        if course.user_on_team?(user)&lt;br /&gt;
          flash[:error] = &amp;quot;This user is already assigned to a team for this course&amp;quot;&lt;br /&gt;
          redirect_back fallback_location: root_path&lt;br /&gt;
          return&lt;br /&gt;
        end&lt;br /&gt;
        if CourseParticipant.find_by(user_id: user.id, parent_id: course.id).nil?&lt;br /&gt;
          urlCourseParticipantList = url_for controller: 'participants', action: 'list', id: course.id, model: 'Course', authorization: 'participant'&lt;br /&gt;
          flash[:error] = &amp;quot;\&amp;quot;#{user.name}\&amp;quot; is not a participant of the current course. Please &amp;lt;a href=\&amp;quot;#{urlCourseParticipantList}\&amp;quot;&amp;gt;add&amp;lt;/a&amp;gt; this user before continuing.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          begin&lt;br /&gt;
            add_member_return = team.add_member(user, team.parent_id)&lt;br /&gt;
          rescue&lt;br /&gt;
            flash[:error] = &amp;quot;The user #{user.name} is already a member of the team #{team.name}&amp;quot;&lt;br /&gt;
            redirect_back fallback_location: root_path&lt;br /&gt;
            return&lt;br /&gt;
          end&lt;br /&gt;
          flash[:error] = 'This team already has the maximum number of members.' if add_member_return == false&lt;br /&gt;
          if add_member_return&lt;br /&gt;
            @teams_user = TeamsUser.last&lt;br /&gt;
            undo_link(&amp;quot;The team user \&amp;quot;#{user.name}\&amp;quot; has been successfully added to \&amp;quot;#{team.name}\&amp;quot;.&amp;quot;)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: team.parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete&lt;br /&gt;
    @teams_user = TeamsUser.find(params[:id])&lt;br /&gt;
    parent_id = Team.find(@teams_user.team_id).parent_id&lt;br /&gt;
    @user = User.find(@teams_user.user_id)&lt;br /&gt;
    @teams_user.destroy&lt;br /&gt;
    undo_link(&amp;quot;The team user \&amp;quot;#{@user.name}\&amp;quot; has been successfully removed. &amp;quot;)&lt;br /&gt;
    redirect_to controller: 'teams', action: 'list', id: parent_id&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def delete_selected&lt;br /&gt;
    params[:item].each do |item_id|&lt;br /&gt;
      team_user = TeamsUser.find(item_id).first&lt;br /&gt;
      team_user.destroy&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    redirect_to action: 'list', id: params[:id]&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Schema====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  create_table &amp;quot;teams_users&amp;quot;, id: :integer, force: :cascade, options: &amp;quot;ENGINE=InnoDB DEFAULT CHARSET=latin1&amp;quot; do |t|&lt;br /&gt;
    t.integer &amp;quot;team_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;user_id&amp;quot;&lt;br /&gt;
    t.integer &amp;quot;duty_id&amp;quot;&lt;br /&gt;
    t.string &amp;quot;pair_programming_status&amp;quot;, limit: 1&lt;br /&gt;
    t.integer &amp;quot;participant_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;duty_id&amp;quot;], name: &amp;quot;index_teams_participants_on_duty_id&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;participant_id&amp;quot;], name: &amp;quot;fk_rails_f4d20198de&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;team_id&amp;quot;], name: &amp;quot;fk_users_teams&amp;quot;&lt;br /&gt;
    t.index [&amp;quot;user_id&amp;quot;], name: &amp;quot;fk_teams_users&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing Plan===&lt;br /&gt;
The TeamsUsers model and controller will be tested using Rspec. FactoryBot will be utilized to create test fixtures and to build the required models. As the methods in the controller are defined as RESTful endpoints. The test take into consideration that the methods return the correct status codes for the output. Based on the current functionality of TeamsUsers model and controller we have defined the following test which are implemented to test the reimplemented code of teams_users model and controller.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:40px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Test No. !! Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || Tests if `#update_duties` updates duties for a participant successfully and redirects to '/student_teams/view?student_id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Tests if `#list` renders the list of users under Assignment team teams#users.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Tests if `#new` sets the Team object to an instance variable.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Tests if `#create` (User Not Defined) throws an error and redirects to 'http://test.host/teams/list?id=1' when a user is not defined.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Tests if `#create` (User Not a Participant) throws an error and redirects to 'http://test.host/teams/list?id=1' when the user added is not a participant of the current assignment.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Tests if `#create` (Assignment Team Full) throws an error 'This team already has the maximum number of members.' and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Tests if `#create` (User Successfully Added) new user gets successfully added to the assignment and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Tests if `#delete` deletes a user and redirects to 'http://test.host/teams/list?id=1'.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Tests if `#delete_selected` deletes selected users and redirects to 'http://test.host/teams_users/list'.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Relevant Links===&lt;br /&gt;
Github Repository: https://github.com/Kashika08/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Jay Shah (github: jayjshah2000)&lt;br /&gt;
&lt;br /&gt;
*Kashika Malick (github: kashika08)&lt;br /&gt;
&lt;br /&gt;
*Riya Gori (github: riyagori1203)&lt;br /&gt;
&lt;br /&gt;
===Mentor===&lt;br /&gt;
Kartiki Bhandakkar&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151456</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151456"/>
		<updated>2023-11-15T18:35:43Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the Team_user model, capturing information about mentors, team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the Team_user_controller, which orchestrates CRUD operations on the Team_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals. Furthermore, the controller provides a list of mentors associated with Team_users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;Team_Users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the Team_Users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;br /&gt;
&lt;br /&gt;
===Objectives===&lt;br /&gt;
&lt;br /&gt;
*Craft RESTful endpoints for creating, displaying, and deleting invitations, along with approving new invitations. Additionally, provide functionality for listing pending invitations, creating new invitations, and notifying students about newly formed team invitations.&lt;br /&gt;
&lt;br /&gt;
*Develop and integrate methods within the Team_usersController to facilitate invitation-related operations, including creating, accepting, declining, and canceling invitations. Ensure thorough checks of user and team statuses before initiating or accepting invitations.&lt;br /&gt;
&lt;br /&gt;
*Establish a user-invitation system that empowers invited users to accept, decline, or cancel invitations, triggering corresponding updates to the associated Team_user records. This should seamlessly manage the addition or removal of users from teams.&lt;br /&gt;
&lt;br /&gt;
*Implement an email notification system within the user-invitation framework, sending email notifications to invited users upon the issuance of new invitations.&lt;br /&gt;
&lt;br /&gt;
*Enforce the use of proper status codes and robust validation mechanisms for all RESTful endpoints.&lt;br /&gt;
&lt;br /&gt;
*Construct models and controllers for the Team_user model, incorporating contemporary approaches to writing Ruby code. This involves leveraging language features and adhering to best practices for object-oriented design.&lt;br /&gt;
&lt;br /&gt;
*Compose comprehensive RSpec tests covering all APIs, models, and controllers to ensure the robustness and reliability of the entire system.&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151454</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151454"/>
		<updated>2023-11-15T18:28:54Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Description of Project===&lt;br /&gt;
&lt;br /&gt;
The focal point of the project is the Team_user model, capturing information about mentors, team members, and affiliations with other models such as Users and Teams. This model undertakes various responsibilities, including the formation of teams with enrolled students and the display of team members. Oversight of team management falls under the purview of the Team_user_controller, which orchestrates CRUD operations on the Team_user model. Its duties span the creation, modification, and deletion of teams, along with the administration of team members through additions or removals. Furthermore, the controller provides a list of mentors associated with Team_users.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;Team_Users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the Team_Users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151452</id>
		<title>CSC/ECE 517 Fall 2023 - E2386. Reimplement teams users backend</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2386._Reimplement_teams_users_backend&amp;diff=151452"/>
		<updated>2023-11-15T18:17:57Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Created page with &amp;quot;===Problem Statement===  The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between te...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
The project involves creating a backend system for seamless CRUD operations on a relational database, specifically focusing on interactions between teams and users. This requires defining &amp;quot;Team_Users&amp;quot; model with suitable attributes and relationships, establishing controllers to manage CRUD actions, and setting up corresponding routes. Emphasis is placed on rigorous testing, covering model validations and associations, as well as controller actions to ensure accurate execution of CRUD operations. A key project aspect involves refining code to produce precise JSON responses. Adhering to RESTful conventions, the re-implementation includes appropriate HTTP response codes. RSpec tests are mandatory for both the Team_Users model and TeamUsersController, covering all endpoints and incorporating HTTP response codes. These controller tests are designed to integrate seamlessly with RSwag for generating API documentation and testing REST APIs through the Swagger UI.&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023&amp;diff=151448</id>
		<title>CSC/ECE 517 Fall 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023&amp;diff=151448"/>
		<updated>2023-11-15T17:44:43Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Fall 2023 - E2350. Allow reviewers to bid on what to review]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2351. Finish mentor management for assignments without topics]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2352. Fix &amp;quot;Back&amp;quot; link on “New Late Policy” page]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2353. Further refactoring and improvement of review mapping helper]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2355. Improving Search Facility In Expertiza]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2356. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2357. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2358. Refactor student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2359. Refactor user_controller.rb, user.rb, and its child classes]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2360. View for Results of Bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2361. Create a page to create and update a Questionnaire in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2362. Create a page to edit an Assignment's due date in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2363. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2364. Create a UI for Course's &amp;amp; Assignment's &amp;quot;Add Participants&amp;quot; page]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2365. Create a user interface for Questionnaire in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2363. Create a UI for Assignment Edit page &amp;quot;Etc&amp;quot; tab in ReactJS(Phase 2)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2366. Reimplement assignment model and assignment controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2367. Reimplement participants_controller.rb, participants.rb and its child classes]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2368. Reimplement of due_date.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2369. Reimplement duties controller.rb and badges controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2370. Reimplement join team requests controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2371. Reimplement quiz_questionnaires_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2373. Reimplementation of teams controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2374. Reimplement the Question hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2375. Reimplement Waitlists]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2376. Reimplement student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2379. Reimplement authorization_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2380. Reimplement frontend for Courses]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2382. Optimizing the LatePoliciesController]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2383. Grading Audit Trail]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2384. Reimplement user_controller.rb, user.rb and its child classes]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2385. Create a Courses User interface in ReactJS]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2386. Reimplement teams_users backend]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - E2377. Reimplement impersonating users (functionality within impersonate_controller.rb)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - NTX-2 Observability and Debuggability]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - NTX-3 Usability and Security]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - NTX-4 Extend NDB Operator capabilities to support Postgres HA]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - G2350. Add GitLab support for using GraphQL to query user metrics 1]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023 - G2352. Add GitLab support for using GraphQL to query repository information]]&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2365._Create_a_user_interface_for_Questionnaire_in_ReactJS&amp;diff=150538</id>
		<title>CSC/ECE 517 Fall 2023 - E2365. Create a user interface for Questionnaire in ReactJS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2023_-_E2365._Create_a_user_interface_for_Questionnaire_in_ReactJS&amp;diff=150538"/>
		<updated>2023-10-30T17:35:38Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a [http://rubyonrails.org/ Ruby on Rails] based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
&lt;br /&gt;
The task involves creating a user interface for a Questionnaire in ReactJS. The main page should display all types of questionnaires, and clicking on each item should expand to show its data. Additionally, an &amp;quot;add/plus&amp;quot; action button should be included for all questionnaire items, with an empty function that activates upon clicking the button. Furthermore, a checkbox labeled &amp;quot;Display my items only&amp;quot; should be present, checked by default. This checkbox will control the display of &amp;quot;public&amp;quot; items.&lt;br /&gt;
&lt;br /&gt;
Tasks that were accomplished:&lt;br /&gt;
&lt;br /&gt;
#&amp;lt;strong&amp;gt;Create a UI Page for Questionnaire Listing:&amp;lt;/strong&amp;gt;&lt;br /&gt;
#*Design a user-friendly page that lists all types of questionnaires.&lt;br /&gt;
#*Implement the necessary React components for displaying the questionnaires.&lt;br /&gt;
#*Implement Add/Plus Action Button:&lt;br /&gt;
#&amp;lt;strong&amp;gt;Add an &amp;quot;add/plus&amp;quot; action button for each questionnaire item.&amp;lt;/strong&amp;gt;&lt;br /&gt;
#*Create an empty function that triggers upon clicking the button.&lt;br /&gt;
#*Include a console log message to verify the functionality of the button click.&lt;br /&gt;
#*Enable Expansion for Questionnaire Items:&lt;br /&gt;
#&amp;lt;strong&amp;gt;Allow users to expand each listed item to reveal its data.&amp;lt;/strong&amp;gt;&lt;br /&gt;
#*Implement a mechanism that displays the relevant data upon clicking.&lt;br /&gt;
#*Incorporate &amp;quot;Display My Items Only&amp;quot; Checkbox:&lt;br /&gt;
#&amp;lt;strong&amp;gt;Include a checkbox with the label &amp;quot;Display my items only.&amp;quot;&amp;lt;/strong&amp;gt;&lt;br /&gt;
#*Ensure that it is checked by default.&lt;br /&gt;
#*Set up the functionality so that it controls the display of &amp;quot;public&amp;quot; items.&lt;br /&gt;
#&amp;lt;strong&amp;gt;Set up Action Buttons for Expanded Entries:&amp;lt;/strong&amp;gt;&lt;br /&gt;
#*Create action buttons for expanded entries.&lt;br /&gt;
#*Implement empty functions for these buttons with console log statements for verification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files added / modified ==&lt;br /&gt;
&lt;br /&gt;
*reimplementation-front-end/src/App.tsx&lt;br /&gt;
*reimplementation-front-end/src/pages/Questionnaire/Questionnaire.css&lt;br /&gt;
*reimplementation-front-end/src/pages/Questionnaire/questionnaire.tsx&lt;br /&gt;
*reimplementation-front-end/src/pages/Questionnaire/dummyData.json&lt;br /&gt;
&lt;br /&gt;
== Results (Screenshots) ==&lt;br /&gt;
*Default Page with Reviews extended:&lt;br /&gt;
[[File:DefaultPagewithReviewsExtended.png|700px]]&lt;br /&gt;
*Sorted in ascending order:&lt;br /&gt;
[[File:AscendingQuestionnaire.png|700px]]&lt;br /&gt;
*Sorted in Descending order:&lt;br /&gt;
[[File:DescendingQuestionnaire.png|700px]]&lt;br /&gt;
*Console log when clicking the buttons:&lt;br /&gt;
[[File:ConsoleLog.png|700px]]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentor===== &lt;br /&gt;
* Kartiki Bhandakkar&lt;br /&gt;
&lt;br /&gt;
=====Members===== &lt;br /&gt;
* Riya Gori &amp;lt;rvgori@ncsu.edu&amp;gt;&lt;br /&gt;
* Kashika Malick &amp;lt;kmalick@ncsu.edu&amp;gt;&lt;br /&gt;
* Jay Shah &amp;lt;jjshah@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-front-end/pull/18 https://github.com/expertiza/reimplementation-front-end/pull/18]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1dXwTNHR26eou6EJZkME8k8FhlpxCf_roMmWzclca8bA/edit?usp=sharing Project Instructions]&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:ConsoleLog.png&amp;diff=150525</id>
		<title>File:ConsoleLog.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:ConsoleLog.png&amp;diff=150525"/>
		<updated>2023-10-30T17:17:00Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DescendingQuestionnaire.png&amp;diff=150524</id>
		<title>File:DescendingQuestionnaire.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DescendingQuestionnaire.png&amp;diff=150524"/>
		<updated>2023-10-30T17:16:44Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:AscendingQuestionnaire.png&amp;diff=150522</id>
		<title>File:AscendingQuestionnaire.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:AscendingQuestionnaire.png&amp;diff=150522"/>
		<updated>2023-10-30T17:16:27Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Descending.png&amp;diff=150521</id>
		<title>File:Descending.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Descending.png&amp;diff=150521"/>
		<updated>2023-10-30T17:15:02Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Jjshah uploaded a new version of File:Descending.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Descending.png&amp;diff=150520</id>
		<title>File:Descending.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Descending.png&amp;diff=150520"/>
		<updated>2023-10-30T17:14:44Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Jjshah uploaded a new version of File:Descending.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Ascending.png&amp;diff=150519</id>
		<title>File:Ascending.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Ascending.png&amp;diff=150519"/>
		<updated>2023-10-30T17:14:06Z</updated>

		<summary type="html">&lt;p&gt;Jjshah: Jjshah uploaded a new version of File:Ascending.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jjshah</name></author>
	</entry>
</feed>