<?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=Skanumu2</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=Skanumu2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Skanumu2"/>
	<updated>2026-05-22T11:55:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161066</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161066"/>
		<updated>2024-12-12T21:08:16Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Checks if there are any slots currently available&lt;br /&gt;
  # Returns true if the number of available slots is greater than 0, otherwise false&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for the current topic.&lt;br /&gt;
  # Checks if the team is already signed up, and if so, ensures they are not waitlisted.&lt;br /&gt;
  # If a slot is available, assigns the topic to the team; otherwise, adds the team to the waitlist.&lt;br /&gt;
  def signup_team(team_id)&lt;br /&gt;
    # Check if the team has already signed up for this topic&lt;br /&gt;
    team_signup_record = SignedUpTeam.find_by(sign_up_topic_id: self.id, team_id: team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already signed up, return false&lt;br /&gt;
    if !team_signup_record.nil?&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Create a new sign-up entry for the team&lt;br /&gt;
    new_signup_record = SignedUpTeam.new(sign_up_topic_id: self.id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
     # If there are available slots, assign the topic to the team and remove the team from the waitlist&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      new_signup_record.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
      result = SignedUpTeam.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      # If no slots are available, add the team to the waitlist&lt;br /&gt;
      result = new_signup_record.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team with the earliest waitlisted record for a given topic.&lt;br /&gt;
  # The team is determined based on the creation time of the waitlisted record.&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes a team from the current topic.&lt;br /&gt;
  # If the team is not waitlisted, the next waitlisted team is reassigned to the topic.&lt;br /&gt;
  # The team is then destroyed (removed from the sign-up record).&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    # Find the sign-up record for the team for this topic&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    # If the team is not waitlisted, reassign the topic to the next waitlisted team&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.assign_topic_to_waitlisted_team(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Destroy the sign-up record for the team&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves all teams that are signed up for a given topic.&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Calculates the number of available slots for a topic.&lt;br /&gt;
  # It checks how many teams have already chosen the topic and subtracts that from the maximum allowed choosers.&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    # Find the number of teams who have already chosen the topic and are not waitlisted&lt;br /&gt;
    # This would give us the number of teams who have been assigned the topic&lt;br /&gt;
    num_teams_registered = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false).size&lt;br /&gt;
&lt;br /&gt;
    # Compute the number of available slots and return&lt;br /&gt;
    self.max_choosers.to_i - num_teams_registered&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The `SignedUpTeam` class is essential for managing the lifecycle of team sign-ups and their associations with topics, ensuring efficient and consistent handling of team-topic relationships. This class facilitates creating sign-up records using methods like `signup_team_for_topic`, enabling teams to associate seamlessly with topics by leveraging the `signup_team` method of the `ProjectTopic` class. It also manages waitlist operations, allowing for the removal of waitlisted entries through `drop_off_team_waitlists` and assignment of waitlisted teams to their topics via `assign_topic_to_waitlisted_team`. For robust data management, it provides functionality to clear all topic associations for a team using `delete_team_signup_records`. The class also supports administrative operations, such as retrieving team IDs for specific users via `get_team_id_for_user`, ensuring streamlined integration with other system components. By maintaining data integrity and supporting dynamic updates to team-topic relationships, the `SignedUpTeam` class plays a crucial role in the overall project management system.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes all waitlist entries for a given team.&lt;br /&gt;
  # This deletes all sign-up records where the team is waitlisted.&lt;br /&gt;
  def self.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signup_team_for_topic(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for a specific project topic.&lt;br /&gt;
  # Finds the project topic by its ID and associates the given team with the topic by calling `signup_team`.&lt;br /&gt;
  def self.signup_team_for_topic(topic_id, team_id)&lt;br /&gt;
    # Find the project topic by its ID&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
&lt;br /&gt;
    # Sign up the team for the topic&lt;br /&gt;
    project_topic.signup_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id_for_user(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team ID for a given user and assignment.&lt;br /&gt;
  # This first finds the team(s) the user is associated with and then retrieves the team for the specified assignment.&lt;br /&gt;
  # NOTE: This method is called in signed_up_teams_controller&lt;br /&gt;
  def self.get_team_id_for_user(user_id, assignment_id)&lt;br /&gt;
    # Get the team IDs associated with the given user&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
&lt;br /&gt;
    if team_ids.empty?&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
    # Find the team that matches the assignment ID and retrieve its team_id&lt;br /&gt;
    team_id = Team.where(id: team_ids, assignment_id: assignment_id).first.id&lt;br /&gt;
    # Return the team ID&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''delete_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Deletes all sign-up records for a given team.&lt;br /&gt;
  # This removes all sign-up entries associated with the specified team.&lt;br /&gt;
  def self.delete_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_waitlisted_team(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method assigns a waitlisted team to a given topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the given topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Reassigns the team to a new topic by removing them from their current topic&lt;br /&gt;
  # and marking them as no longer waitlisted for the new topic.&lt;br /&gt;
  # NOTE: This method gets called only on a waitlisted team (See project_topic.rb -&amp;gt; drop_team_from_topic)&lt;br /&gt;
  def assign_topic_to_waitlisted_team(topic_id)&lt;br /&gt;
    # Find the team's current sign-up record where they are not waitlisted&lt;br /&gt;
    # As this method gets called only on a waitlisted team, we need to check if the team has been assigned another topic&lt;br /&gt;
    assigned_team = SignedUpTeam.find_by(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already assigned to a topic, remove them from that topic&lt;br /&gt;
    if assigned_team&lt;br /&gt;
      project_topic = ProjectTopic.find(assigned_team.sign_up_topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Update the team's waitlist status to false (indicating they are no longer waitlisted)&lt;br /&gt;
    self.update(sign_up_topic_id: topic_id, is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Project Topic class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. slot_available?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test suite validates the `#slot_available?` method of `project_topic`, ensuring it returns `true` when no teams have chosen the topic and `false` when all slots (`max_choosers`) are filled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. sign_up_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test suite validates the `#signup_team` method of `project_topic`. It ensures the method assigns the topic to a team and clears team waitlists when slots are available, adds the team to the waitlist when slots are full, and returns `false` if the team is already signed up and not waitlisted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#signup_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_topic_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.signup_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_topic_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.signup_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.signup_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. longest_waiting_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test validates the `#longest_waiting_team` method of `project_topic`, ensuring it correctly returns the team that has been on the waitlist for the longest duration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. drop_team_from_topic&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test suite verifies the `#drop_team_from_topic` method of `project_topic`. It ensures the method removes a team from the topic and, if applicable, assigns the topic to the next longest-waitlisted team by updating its waitlist status.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. current_available_slots&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test suite validates the `#current_available_slots` method of `project_topic`. It ensures the method returns the total `max_choosers` when no teams have signed up and accurately calculates the remaining slots when some teams have already signed up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Signed Up Team class&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. get_team_id_for_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test suite validates the `.get_team_id_for_user` class method of `SignedUpTeam`. It ensures the method returns the correct team ID for a user associated with a specific assignment and returns `nil` if the user is not associated with any team for that assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.get_team_id_for_user' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. delete_team_signup_records&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test validates the `.delete_team_signup_records` class method of `SignedUpTeam`. It ensures that the method correctly removes all sign-up records associated with a given team, reducing the count of relevant records by the expected amount.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.delete_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.delete_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. assign_topic_to_waitlisted_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This RSpec test validates the `#assign_topic_to_waitlisted_team` method. It ensures that the method successfully reassigns a waitlisted team to a new topic, marks them as not waitlisted, and triggers the `drop_team_from_topic` method on the previous topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '#assign_topic_to_waitlisted_team' do&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        let!(:signed_up_team_2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic_2.id).and_return(project_topic_2)&lt;br /&gt;
            allow(project_topic_2).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.assign_topic_to_waitlisted_team(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic_2).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161065</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161065"/>
		<updated>2024-12-12T20:42:05Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Checks if there are any slots currently available&lt;br /&gt;
  # Returns true if the number of available slots is greater than 0, otherwise false&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for the current topic.&lt;br /&gt;
  # Checks if the team is already signed up, and if so, ensures they are not waitlisted.&lt;br /&gt;
  # If a slot is available, assigns the topic to the team; otherwise, adds the team to the waitlist.&lt;br /&gt;
  def signup_team(team_id)&lt;br /&gt;
    # Check if the team has already signed up for this topic&lt;br /&gt;
    team_signup_record = SignedUpTeam.find_by(sign_up_topic_id: self.id, team_id: team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already signed up, return false&lt;br /&gt;
    if !team_signup_record.nil?&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Create a new sign-up entry for the team&lt;br /&gt;
    new_signup_record = SignedUpTeam.new(sign_up_topic_id: self.id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
     # If there are available slots, assign the topic to the team and remove the team from the waitlist&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      new_signup_record.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
      result = SignedUpTeam.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      # If no slots are available, add the team to the waitlist&lt;br /&gt;
      result = new_signup_record.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team with the earliest waitlisted record for a given topic.&lt;br /&gt;
  # The team is determined based on the creation time of the waitlisted record.&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes a team from the current topic.&lt;br /&gt;
  # If the team is not waitlisted, the next waitlisted team is reassigned to the topic.&lt;br /&gt;
  # The team is then destroyed (removed from the sign-up record).&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    # Find the sign-up record for the team for this topic&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    # If the team is not waitlisted, reassign the topic to the next waitlisted team&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.assign_topic_to_waitlisted_team(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Destroy the sign-up record for the team&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves all teams that are signed up for a given topic.&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Calculates the number of available slots for a topic.&lt;br /&gt;
  # It checks how many teams have already chosen the topic and subtracts that from the maximum allowed choosers.&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    # Find the number of teams who have already chosen the topic and are not waitlisted&lt;br /&gt;
    # This would give us the number of teams who have been assigned the topic&lt;br /&gt;
    num_teams_registered = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false).size&lt;br /&gt;
&lt;br /&gt;
    # Compute the number of available slots and return&lt;br /&gt;
    self.max_choosers.to_i - num_teams_registered&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The `SignedUpTeam` class is essential for managing the lifecycle of team sign-ups and their associations with topics, ensuring efficient and consistent handling of team-topic relationships. This class facilitates creating sign-up records using methods like `signup_team_for_topic`, enabling teams to associate seamlessly with topics by leveraging the `signup_team` method of the `ProjectTopic` class. It also manages waitlist operations, allowing for the removal of waitlisted entries through `drop_off_team_waitlists` and assignment of waitlisted teams to their topics via `assign_topic_to_waitlisted_team`. For robust data management, it provides functionality to clear all topic associations for a team using `delete_team_signup_records`. The class also supports administrative operations, such as retrieving team IDs for specific users via `get_team_id_for_user`, ensuring streamlined integration with other system components. By maintaining data integrity and supporting dynamic updates to team-topic relationships, the `SignedUpTeam` class plays a crucial role in the overall project management system.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes all waitlist entries for a given team.&lt;br /&gt;
  # This deletes all sign-up records where the team is waitlisted.&lt;br /&gt;
  def self.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signup_team_for_topic(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for a specific project topic.&lt;br /&gt;
  # Finds the project topic by its ID and associates the given team with the topic by calling `signup_team`.&lt;br /&gt;
  def self.signup_team_for_topic(topic_id, team_id)&lt;br /&gt;
    # Find the project topic by its ID&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
&lt;br /&gt;
    # Sign up the team for the topic&lt;br /&gt;
    project_topic.signup_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id_for_user(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team ID for a given user and assignment.&lt;br /&gt;
  # This first finds the team(s) the user is associated with and then retrieves the team for the specified assignment.&lt;br /&gt;
  # NOTE: This method is called in signed_up_teams_controller&lt;br /&gt;
  def self.get_team_id_for_user(user_id, assignment_id)&lt;br /&gt;
    # Get the team IDs associated with the given user&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
&lt;br /&gt;
    if team_ids.empty?&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
    # Find the team that matches the assignment ID and retrieve its team_id&lt;br /&gt;
    team_id = Team.where(id: team_ids, assignment_id: assignment_id).first.id&lt;br /&gt;
    # Return the team ID&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''delete_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Deletes all sign-up records for a given team.&lt;br /&gt;
  # This removes all sign-up entries associated with the specified team.&lt;br /&gt;
  def self.delete_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_waitlisted_team(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method assigns a waitlisted team to a given topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the given topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Reassigns the team to a new topic by removing them from their current topic&lt;br /&gt;
  # and marking them as no longer waitlisted for the new topic.&lt;br /&gt;
  # NOTE: This method gets called only on a waitlisted team (See project_topic.rb -&amp;gt; drop_team_from_topic)&lt;br /&gt;
  def assign_topic_to_waitlisted_team(topic_id)&lt;br /&gt;
    # Find the team's current sign-up record where they are not waitlisted&lt;br /&gt;
    # As this method gets called only on a waitlisted team, we need to check if the team has been assigned another topic&lt;br /&gt;
    assigned_team = SignedUpTeam.find_by(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already assigned to a topic, remove them from that topic&lt;br /&gt;
    if assigned_team&lt;br /&gt;
      project_topic = ProjectTopic.find(assigned_team.sign_up_topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Update the team's waitlist status to false (indicating they are no longer waitlisted)&lt;br /&gt;
    self.update(sign_up_topic_id: topic_id, is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Project Topic class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. slot_available?&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. sign_up_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#signup_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_topic_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.signup_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_topic_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.signup_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.signup_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. longest_waiting_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;4. drop_team_from_topic&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;5. current_available_slots&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Signed Up Team class&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;1. get_team_id_for_user&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.get_team_id_for_user' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;2. drop_off_team_signup_records&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.delete_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.delete_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;3. assign_topic_to_waitlisted_team&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '#assign_topic_to_waitlisted_team' do&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        let!(:signed_up_team_2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic_2.id).and_return(project_topic_2)&lt;br /&gt;
            allow(project_topic_2).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.assign_topic_to_waitlisted_team(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic_2).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161064</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161064"/>
		<updated>2024-12-12T20:31:01Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Checks if there are any slots currently available&lt;br /&gt;
  # Returns true if the number of available slots is greater than 0, otherwise false&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for the current topic.&lt;br /&gt;
  # Checks if the team is already signed up, and if so, ensures they are not waitlisted.&lt;br /&gt;
  # If a slot is available, assigns the topic to the team; otherwise, adds the team to the waitlist.&lt;br /&gt;
  def signup_team(team_id)&lt;br /&gt;
    # Check if the team has already signed up for this topic&lt;br /&gt;
    team_signup_record = SignedUpTeam.find_by(sign_up_topic_id: self.id, team_id: team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already signed up, return false&lt;br /&gt;
    if !team_signup_record.nil?&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Create a new sign-up entry for the team&lt;br /&gt;
    new_signup_record = SignedUpTeam.new(sign_up_topic_id: self.id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
     # If there are available slots, assign the topic to the team and remove the team from the waitlist&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      new_signup_record.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
      result = SignedUpTeam.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      # If no slots are available, add the team to the waitlist&lt;br /&gt;
      result = new_signup_record.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team with the earliest waitlisted record for a given topic.&lt;br /&gt;
  # The team is determined based on the creation time of the waitlisted record.&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes a team from the current topic.&lt;br /&gt;
  # If the team is not waitlisted, the next waitlisted team is reassigned to the topic.&lt;br /&gt;
  # The team is then destroyed (removed from the sign-up record).&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    # Find the sign-up record for the team for this topic&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    # If the team is not waitlisted, reassign the topic to the next waitlisted team&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.assign_topic_to_waitlisted_team(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Destroy the sign-up record for the team&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves all teams that are signed up for a given topic.&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Calculates the number of available slots for a topic.&lt;br /&gt;
  # It checks how many teams have already chosen the topic and subtracts that from the maximum allowed choosers.&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    # Find the number of teams who have already chosen the topic and are not waitlisted&lt;br /&gt;
    # This would give us the number of teams who have been assigned the topic&lt;br /&gt;
    num_teams_registered = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false).size&lt;br /&gt;
&lt;br /&gt;
    # Compute the number of available slots and return&lt;br /&gt;
    self.max_choosers.to_i - num_teams_registered&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The `SignedUpTeam` class is essential for managing the lifecycle of team sign-ups and their associations with topics, ensuring efficient and consistent handling of team-topic relationships. This class facilitates creating sign-up records using methods like `signup_team_for_topic`, enabling teams to associate seamlessly with topics by leveraging the `signup_team` method of the `ProjectTopic` class. It also manages waitlist operations, allowing for the removal of waitlisted entries through `drop_off_team_waitlists` and assignment of waitlisted teams to their topics via `assign_topic_to_waitlisted_team`. For robust data management, it provides functionality to clear all topic associations for a team using `delete_team_signup_records`. The class also supports administrative operations, such as retrieving team IDs for specific users via `get_team_id_for_user`, ensuring streamlined integration with other system components. By maintaining data integrity and supporting dynamic updates to team-topic relationships, the `SignedUpTeam` class plays a crucial role in the overall project management system.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes all waitlist entries for a given team.&lt;br /&gt;
  # This deletes all sign-up records where the team is waitlisted.&lt;br /&gt;
  def self.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signup_team_for_topic(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for a specific project topic.&lt;br /&gt;
  # Finds the project topic by its ID and associates the given team with the topic by calling `signup_team`.&lt;br /&gt;
  def self.signup_team_for_topic(topic_id, team_id)&lt;br /&gt;
    # Find the project topic by its ID&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
&lt;br /&gt;
    # Sign up the team for the topic&lt;br /&gt;
    project_topic.signup_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id_for_user(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team ID for a given user and assignment.&lt;br /&gt;
  # This first finds the team(s) the user is associated with and then retrieves the team for the specified assignment.&lt;br /&gt;
  # NOTE: This method is called in signed_up_teams_controller&lt;br /&gt;
  def self.get_team_id_for_user(user_id, assignment_id)&lt;br /&gt;
    # Get the team IDs associated with the given user&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
&lt;br /&gt;
    if team_ids.empty?&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
    # Find the team that matches the assignment ID and retrieve its team_id&lt;br /&gt;
    team_id = Team.where(id: team_ids, assignment_id: assignment_id).first.id&lt;br /&gt;
    # Return the team ID&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''delete_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Deletes all sign-up records for a given team.&lt;br /&gt;
  # This removes all sign-up entries associated with the specified team.&lt;br /&gt;
  def self.delete_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_waitlisted_team(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method assigns a waitlisted team to a given topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the given topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Reassigns the team to a new topic by removing them from their current topic&lt;br /&gt;
  # and marking them as no longer waitlisted for the new topic.&lt;br /&gt;
  # NOTE: This method gets called only on a waitlisted team (See project_topic.rb -&amp;gt; drop_team_from_topic)&lt;br /&gt;
  def assign_topic_to_waitlisted_team(topic_id)&lt;br /&gt;
    # Find the team's current sign-up record where they are not waitlisted&lt;br /&gt;
    # As this method gets called only on a waitlisted team, we need to check if the team has been assigned another topic&lt;br /&gt;
    assigned_team = SignedUpTeam.find_by(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already assigned to a topic, remove them from that topic&lt;br /&gt;
    if assigned_team&lt;br /&gt;
      project_topic = ProjectTopic.find(assigned_team.sign_up_topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Update the team's waitlist status to false (indicating they are no longer waitlisted)&lt;br /&gt;
    self.update(sign_up_topic_id: topic_id, is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Project Topic class.&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#signup_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_topic_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.signup_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_topic_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.signup_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.signup_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Signed Up Team class&lt;br /&gt;
&lt;br /&gt;
1.get_team_id_for_user&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.get_team_id_for_user' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.delete_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.delete_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.assign_topic_to_waitlisted_team&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '#assign_topic_to_waitlisted_team' do&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        let!(:signed_up_team_2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic_2.id).and_return(project_topic_2)&lt;br /&gt;
            allow(project_topic_2).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.assign_topic_to_waitlisted_team(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic_2).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161060</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161060"/>
		<updated>2024-12-12T20:13:16Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Checks if there are any slots currently available&lt;br /&gt;
  # Returns true if the number of available slots is greater than 0, otherwise false&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for the current topic.&lt;br /&gt;
  # Checks if the team is already signed up, and if so, ensures they are not waitlisted.&lt;br /&gt;
  # If a slot is available, assigns the topic to the team; otherwise, adds the team to the waitlist.&lt;br /&gt;
  def signup_team(team_id)&lt;br /&gt;
    # Check if the team has already signed up for this topic&lt;br /&gt;
    team_signup_record = SignedUpTeam.find_by(sign_up_topic_id: self.id, team_id: team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already signed up, return false&lt;br /&gt;
    if !team_signup_record.nil?&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Create a new sign-up entry for the team&lt;br /&gt;
    new_signup_record = SignedUpTeam.new(sign_up_topic_id: self.id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
     # If there are available slots, assign the topic to the team and remove the team from the waitlist&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      new_signup_record.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
      result = SignedUpTeam.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      # If no slots are available, add the team to the waitlist&lt;br /&gt;
      result = new_signup_record.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team with the earliest waitlisted record for a given topic.&lt;br /&gt;
  # The team is determined based on the creation time of the waitlisted record.&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes a team from the current topic.&lt;br /&gt;
  # If the team is not waitlisted, the next waitlisted team is reassigned to the topic.&lt;br /&gt;
  # The team is then destroyed (removed from the sign-up record).&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    # Find the sign-up record for the team for this topic&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    # If the team is not waitlisted, reassign the topic to the next waitlisted team&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.assign_topic_to_waitlisted_team(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Destroy the sign-up record for the team&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves all teams that are signed up for a given topic.&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Calculates the number of available slots for a topic.&lt;br /&gt;
  # It checks how many teams have already chosen the topic and subtracts that from the maximum allowed choosers.&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    # Find the number of teams who have already chosen the topic and are not waitlisted&lt;br /&gt;
    # This would give us the number of teams who have been assigned the topic&lt;br /&gt;
    num_teams_registered = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false).size&lt;br /&gt;
&lt;br /&gt;
    # Compute the number of available slots and return&lt;br /&gt;
    self.max_choosers.to_i - num_teams_registered&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The `SignedUpTeam` class is essential for managing the lifecycle of team sign-ups and their associations with topics, ensuring efficient and consistent handling of team-topic relationships. This class facilitates creating sign-up records using methods like `create_signed_up_team`, enabling teams to associate seamlessly with topics by leveraging the `sign_up_team` method of the `ProjectTopic` class. It also manages waitlist operations, allowing for the removal of waitlisted entries through `drop_off_team_waitlists` and reassignment of teams to new topics via `reassign_topic`. For robust data management, it provides functionality to clear all topic associations for a team using `drop_off_team_signup_records`. The class also supports administrative operations, such as retrieving team IDs for specific assignments via `get_team_id`, ensuring streamlined integration with other system components. By maintaining data integrity and supporting dynamic updates to team-topic relationships, the `SignedUpTeam` class plays a crucial role in the overall project management system.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Removes all waitlist entries for a given team.&lt;br /&gt;
  # This deletes all sign-up records where the team is waitlisted.&lt;br /&gt;
  def self.drop_off_topic_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signup_team_for_topic(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Signs up a team for a specific project topic.&lt;br /&gt;
  # Finds the project topic by its ID and associates the given team with the topic by calling `signup_team`.&lt;br /&gt;
  def self.signup_team_for_topic(topic_id, team_id)&lt;br /&gt;
    # Find the project topic by its ID&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
&lt;br /&gt;
    # Sign up the team for the topic&lt;br /&gt;
    project_topic.signup_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id_for_user(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Retrieves the team ID for a given user and assignment.&lt;br /&gt;
  # This first finds the team(s) the user is associated with and then retrieves the team for the specified assignment.&lt;br /&gt;
  # NOTE: This method is called in signed_up_teams_controller&lt;br /&gt;
  def self.get_team_id_for_user(user_id, assignment_id)&lt;br /&gt;
    # Get the team IDs associated with the given user&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
&lt;br /&gt;
    if team_ids.empty?&lt;br /&gt;
      return nil&lt;br /&gt;
    end&lt;br /&gt;
    # Find the team that matches the assignment ID and retrieve its team_id&lt;br /&gt;
    team_id = Team.where(id: team_ids, assignment_id: assignment_id).first.id&lt;br /&gt;
    # Return the team ID&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''delete_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Deletes all sign-up records for a given team.&lt;br /&gt;
  # This removes all sign-up entries associated with the specified team.&lt;br /&gt;
  def self.delete_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_waitlisted_team(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method assigns a waitlisted team to a given topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the given topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Reassigns the team to a new topic by removing them from their current topic&lt;br /&gt;
  # and marking them as no longer waitlisted for the new topic.&lt;br /&gt;
  # NOTE: This method gets called only on a waitlisted team (See project_topic.rb -&amp;gt; drop_team_from_topic)&lt;br /&gt;
  def assign_topic_to_waitlisted_team(topic_id)&lt;br /&gt;
    # Find the team's current sign-up record where they are not waitlisted&lt;br /&gt;
    # As this method gets called only on a waitlisted team, we need to check if the team has been assigned another topic&lt;br /&gt;
    assigned_team = SignedUpTeam.find_by(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    # If the team is already assigned to a topic, remove them from that topic&lt;br /&gt;
    if assigned_team&lt;br /&gt;
      project_topic = ProjectTopic.find(assigned_team.sign_up_topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Update the team's waitlist status to false (indicating they are no longer waitlisted)&lt;br /&gt;
    self.update(sign_up_topic_id: topic_id, is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Project Topic class.&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#signup_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_topic_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.signup_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_topic_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.signup_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.signup_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
These set of tests are written for Signed Up Team class&lt;br /&gt;
&lt;br /&gt;
1.get_team_id_for_user&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.get_team_id_for_user' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id_for_user(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '.delete_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.delete_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.assign_topic_to_waitlisted_team&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
    describe '#assign_topic_to_waitlisted_team' do&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        let!(:signed_up_team_2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic_2.id).and_return(project_topic_2)&lt;br /&gt;
            allow(project_topic_2).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.assign_topic_to_waitlisted_team(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic_2).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161042</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161042"/>
		<updated>2024-12-12T04:21:38Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* app/models/signed_up_team.rb */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The `SignedUpTeam` class is essential for managing the lifecycle of team sign-ups and their associations with topics, ensuring efficient and consistent handling of team-topic relationships. This class facilitates creating sign-up records using methods like `create_signed_up_team`, enabling teams to associate seamlessly with topics by leveraging the `sign_up_team` method of the `ProjectTopic` class. It also manages waitlist operations, allowing for the removal of waitlisted entries through `drop_off_team_waitlists` and reassignment of teams to new topics via `reassign_topic`. For robust data management, it provides functionality to clear all topic associations for a team using `drop_off_team_signup_records`. The class also supports administrative operations, such as retrieving team IDs for specific assignments via `get_team_id`, ensuring streamlined integration with other system components. By maintaining data integrity and supporting dynamic updates to team-topic relationships, the `SignedUpTeam` class plays a crucial role in the overall project management system.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&lt;br /&gt;
This method should assign the topic to a team. The below test case is to check if it assigns the topic properly.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&lt;br /&gt;
This method should save a waitlist entry for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161041</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161041"/>
		<updated>2024-12-12T04:16:12Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* app/models/project_topic.rb */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
The `ProjectTopic` class is a pivotal component for managing team-based project topics, ensuring fairness, data consistency, and efficient slot allocation. It handles real-time slot availability, allowing teams to sign up for topics directly if slots are open while maintaining a fair waitlist for overflow through chronological assignment. The class dynamically reassigns slots when teams drop out, ensuring optimal utilization of resources. Methods like `current_available_slots` provide accurate slot tracking, while administrative functionality such as `signed_up_teams_for_topic` offers comprehensive reporting of both active and waitlisted teams. By managing these operations seamlessly, the class upholds fairness and integrity across team-topic assignments. The following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages team sign-ups and associations with topics. It provides functionality for creating, modifying, and removing sign-up records while supporting seamless team-topic management and waitlist operations.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&lt;br /&gt;
This method should assign the topic to a team. The below test case is to check if it assigns the topic properly.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&lt;br /&gt;
This method should save a waitlist entry for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161004</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161004"/>
		<updated>2024-12-11T19:06:55Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages topics for team-based projects, handling slot availability, topic assignment, and waitlist management. It ensures that teams are efficiently allocated to topics based on availability while maintaining fairness and data consistency. Following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages team sign-ups and associations with topics. It provides functionality for creating, modifying, and removing sign-up records while supporting seamless team-topic management and waitlist operations.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&lt;br /&gt;
This method should assign the topic to a team. The below test case is to check if it assigns the topic properly.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&lt;br /&gt;
This method should save a waitlist entry for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&lt;br /&gt;
This method returns team ID given user ID and assignment ID. The below code tests for cases when the user is associated with a team and when the user is not associated with any team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&lt;br /&gt;
This method should drop off all signup records for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&lt;br /&gt;
This method should reassign the topic for a given team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161003</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161003"/>
		<updated>2024-12-11T19:03:43Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages topics for team-based projects, handling slot availability, topic assignment, and waitlist management. It ensures that teams are efficiently allocated to topics based on availability while maintaining fairness and data consistency. Following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages team sign-ups and associations with topics. It provides functionality for creating, modifying, and removing sign-up records while supporting seamless team-topic management and waitlist operations.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&lt;br /&gt;
This method should assign the topic to a team. The below test case is to check if it assigns the topic properly.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&lt;br /&gt;
This method should save a waitlist entry for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&lt;br /&gt;
This method should return the longest waiting team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
&lt;br /&gt;
This method should drop a signed up team from a project topic. The below code tests for cases when the team is not waitlisted and when it is waitlisted.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&lt;br /&gt;
This method returns the number of available slots. The below code tests for cases when no teams have signed up for the topic and when some teams have signed up for the topic.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161002</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=161002"/>
		<updated>2024-12-11T18:59:22Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages topics for team-based projects, handling slot availability, topic assignment, and waitlist management. It ensures that teams are efficiently allocated to topics based on availability while maintaining fairness and data consistency. Following methods were reimplemented in this model:&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
This class manages team sign-ups and associations with topics. It provides functionality for creating, modifying, and removing sign-up records while supporting seamless team-topic management and waitlist operations.&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
This method should return a boolean value indicating whether slots are available or not. Below code tests if it returns the right value when no teams have chosen the topic and when no slots are available.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
This method should assign the topic to a team. The below test case is to check if it assigns the topic properly.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
This method should save a waitlist entry for a team.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
This method should sign a team up for a project. The below code as test cases for when a slot is available, when no slots are available and when the team is already signed up for the topic and not waitlisted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160699</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160699"/>
		<updated>2024-12-04T05:00:28Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==Video==&lt;br /&gt;
*[https://youtube.com/watch?v=oRxrtW5v05A Video]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160696</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160696"/>
		<updated>2024-12-04T04:59:40Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* signed_up_team */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===app/models/signed_up_team.rb===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160695</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160695"/>
		<updated>2024-12-04T04:59:19Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* project_topics */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===app/models/project_topic.rb===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160688</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160688"/>
		<updated>2024-12-04T04:56:30Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Introduction */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend. Expertiza backend is being reimplemented to leverage recent updates in Ruby on Rails ecosystem. This project is part of those efforts.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160655</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160655"/>
		<updated>2024-12-04T04:30:54Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
'''spec/models/project_topic_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''spec/models/signed_up_team_spec.rb'''&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160654</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160654"/>
		<updated>2024-12-04T04:23:10Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
      describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160653</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160653"/>
		<updated>2024-12-04T04:22:05Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
6.drop_team_from_topic&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160648</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160648"/>
		<updated>2024-12-04T04:19:27Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
      &lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160642</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160642"/>
		<updated>2024-12-04T04:18:45Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    &lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
      &lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160633</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160633"/>
		<updated>2024-12-04T04:13:14Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Testing */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
    &lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
      &lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160615</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160615"/>
		<updated>2024-12-04T04:06:18Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Test Plan */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
spec/models/project_topic_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.slot_available?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#slot_available?' do&lt;br /&gt;
    context 'when no teams have chosen the topic' do&lt;br /&gt;
      it 'returns true' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.slot_available?).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2.assign_topic_to_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#assign_topic_to_team' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'assigns the topic to the team and updates waitlist status' do&lt;br /&gt;
      project_topic.assign_topic_to_team(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be false&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.save_waitlist_entry&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#save_waitlist_entry' do&lt;br /&gt;
    let(:new_sign_up) { SignedUpTeam.new(sign_up_topic_id: nil, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
    it 'adds a new sign-up to the waitlist' do&lt;br /&gt;
      project_topic.save_waitlist_entry(new_sign_up)&lt;br /&gt;
      expect(new_sign_up.is_waitlisted).to be true&lt;br /&gt;
      expect(new_sign_up.sign_up_topic_id).to eq(project_topic.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.sign_up_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#sign_up_team' do&lt;br /&gt;
    let(:new_team) { Team.create!(assignment_id: assignment.id) }&lt;br /&gt;
&lt;br /&gt;
    context 'when slot is available' do&lt;br /&gt;
      it 'assigns the topic to the team and drops team waitlists' do&lt;br /&gt;
        allow(SignedUpTeam).to receive(:drop_off_team_waitlists).with(new_team.id).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        expect(project_topic.sign_up_team(new_team.id)).to be true&lt;br /&gt;
        expect(SignedUpTeam).to have_received(:drop_off_team_waitlists).with(new_team.id)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when no slots are available' do&lt;br /&gt;
      before do&lt;br /&gt;
        project_topic.max_choosers.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'adds the team to the waitlist' do&lt;br /&gt;
        expect { project_topic.sign_up_team(new_team.id) }.to change { SignedUpTeam.count }.by(1)&lt;br /&gt;
        expect(SignedUpTeam.last.is_waitlisted).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is already signed up and not waitlisted' do&lt;br /&gt;
      before do&lt;br /&gt;
        SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team, is_waitlisted: false)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns false' do&lt;br /&gt;
        expect(project_topic.sign_up_team(team.id)).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.longest_waiting_team&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#longest_waiting_team' do&lt;br /&gt;
    let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
    it 'returns the team that has been waitlisted the longest' do&lt;br /&gt;
      expect(project_topic.longest_waiting_team).to eq(waitlisted_team)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe '#drop_team_from_topic' do&lt;br /&gt;
    let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, team: team) }&lt;br /&gt;
&lt;br /&gt;
    it 'removes the team from the topic' do&lt;br /&gt;
      expect { project_topic.drop_team_from_topic(team.id) }.to change { SignedUpTeam.count }.by(-1)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when the team is not waitlisted' do&lt;br /&gt;
      let!(:waitlisted_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, created_at: 1.day.ago, team: Team.create!(assignment_id: assignment.id)) }&lt;br /&gt;
&lt;br /&gt;
      it 'assigns the topic to the next waitlisted team' do&lt;br /&gt;
        project_topic.drop_team_from_topic(team.id)&lt;br /&gt;
        expect(waitlisted_team.reload.is_waitlisted).to be false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6.current_available_slots&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#current_available_slots' do&lt;br /&gt;
    context 'when no teams have signed up' do&lt;br /&gt;
      it 'returns max_choosers as available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(project_topic.max_choosers)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    context 'when some teams have signed up' do&lt;br /&gt;
      before do&lt;br /&gt;
        2.times do&lt;br /&gt;
          SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team: Team.create!(assignment_id: assignment.id))&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      it 'returns the remaining available slots' do&lt;br /&gt;
        expect(project_topic.current_available_slots).to eq(1)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
spec/models/signed_up_team_spec.rb&lt;br /&gt;
&lt;br /&gt;
1.get_team_id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.get_team_id' do&lt;br /&gt;
        let!(:user) { User.create!(name: &amp;quot;Name&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id) }&lt;br /&gt;
        let!(:teams_user) { TeamsUser.create!(team_id: team.id, user_id: user.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'returns the correct team ID for the given user and assignment' do&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(user.id, assignment.id)).to eq(team.id)&lt;br /&gt;
        end&lt;br /&gt;
      &lt;br /&gt;
        it 'returns nil if the user is not associated with any team for the assignment' do&lt;br /&gt;
          other_user = User.create!(name: &amp;quot;Name 2&amp;quot;, password: &amp;quot;password&amp;quot;, full_name: &amp;quot;Full Name&amp;quot;, email: &amp;quot;email@example.com&amp;quot;, mru_directory_path: &amp;quot;/dummy/path&amp;quot;, role_id: role.id)&lt;br /&gt;
          expect(SignedUpTeam.get_team_id(other_user.id, assignment.id)).to be_nil&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2..drop_off_team_signup_records&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
describe '.drop_off_team_signup_records' do&lt;br /&gt;
        let!(:signup1) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: false, team_id: team.id) }&lt;br /&gt;
        let!(:project_topic_2) { ProjectTopic.create!(topic_name: &amp;quot;Dummy Topic 2&amp;quot;, assignment_id: assignment.id, max_choosers: 3) }&lt;br /&gt;
        let!(:signup2) { SignedUpTeam.create!(sign_up_topic_id: project_topic_2.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
      &lt;br /&gt;
        it 'removes all sign-up records for the given team' do&lt;br /&gt;
          expect { SignedUpTeam.drop_off_team_signup_records(team.id) }&lt;br /&gt;
            .to change { SignedUpTeam.where(team_id: team.id).count }.by(-2)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3.reassign_topic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 describe '#reassign_topic' do&lt;br /&gt;
        let!(:signed_up_team) { SignedUpTeam.create!(sign_up_topic_id: project_topic.id, is_waitlisted: true, team_id: team.id) }&lt;br /&gt;
&lt;br /&gt;
        before do&lt;br /&gt;
            allow(ProjectTopic).to receive(:find).with(project_topic.id).and_return(project_topic)&lt;br /&gt;
            allow(project_topic).to receive(:drop_team_from_topic)&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        it 'reassigns the team to a new topic and marks them as not waitlisted' do&lt;br /&gt;
            signed_up_team.reassign_topic(project_topic.id)&lt;br /&gt;
            expect(signed_up_team.reload.is_waitlisted).to be_falsey&lt;br /&gt;
            expect(project_topic).to have_received(:drop_team_from_topic).with(team_id: team.id)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160473</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160473"/>
		<updated>2024-12-04T02:20:56Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Implementation */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods implemented for the `project_topic` and `signed_up_team` classes. These methods handle slot availability, team sign-ups, waitlist management, topic reassignment, and data consistency. They ensure efficient topic allocation and seamless team management.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160461</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160461"/>
		<updated>2024-12-04T02:13:59Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Implementation */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods we implemented for &amp;lt;b&amp;gt;project_topic&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;signed_up_team&amp;lt;/b&amp;gt; classes.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160460</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160460"/>
		<updated>2024-12-04T02:13:15Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Implementation */&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods we implemented for &amp;lt;b&amp;gt;project_topic and &amp;lt;b&amp;gt;signed_up_team classes.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160459</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=160459"/>
		<updated>2024-12-04T02:12:31Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
Below are the methods we implemented for *project_topic* and *signed_up_team classes*.&lt;br /&gt;
===project_topics ===&lt;br /&gt;
&lt;br /&gt;
'''slot_available?''':&lt;br /&gt;
&lt;br /&gt;
This method checks if there are any available slots for a team to sign up for the topic. This function is crucial for managing team assignments effectively without exceeding the maximum allowed capacity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def slot_available?&lt;br /&gt;
    current_available_slots &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''assign_topic_to_team(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method assigns the current topic to a team by updating the provided sign-up record. It removes the team from the waitlist and associates the team with this topic. This ensures that the team's assignment is finalized and marked as active, not waitlisted. It is used in scenarios where a slot is available and the team can be directly assigned to the topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def assign_topic_to_team(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: false, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''save_waitlist_entry(new_sign_up)''':&lt;br /&gt;
&lt;br /&gt;
This method adds a team to the waitlist for the current topic by marking the sign-up record as waitlisted and associating it with this topic. This function is invoked when no slots are available, ensuring the team is placed in the queue for future assignment. It maintains fairness and order in the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_waitlist_entry(new_sign_up)&lt;br /&gt;
    new_sign_up.update(is_waitlisted: true, sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''sign_up_team(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method handles the team sign-up process for the current topic. It first checks if the team is already signed up for the topic and ensures it is not waitlisted. If slots are available, the team is assigned to the topic directly. Otherwise, the team is added to the waitlist. This method is central to managing both immediate assignments and waitlisted entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def sign_up_team(team_id)&lt;br /&gt;
    topic_id = self.id&lt;br /&gt;
&lt;br /&gt;
    existing_sign_up = SignedUpTeam.find_by(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
    return false if !existing_sign_up.nil? &amp;amp;&amp;amp; !existing_sign_up.is_waitlisted&lt;br /&gt;
&lt;br /&gt;
    new_sign_up = SignedUpTeam.new(sign_up_topic_id: topic_id, team_id: team_id)&lt;br /&gt;
&lt;br /&gt;
    if slot_available?&lt;br /&gt;
      assign_topic_to_team(new_sign_up)&lt;br /&gt;
      result = SignedUpTeam.drop_off_team_waitlists(team_id)&lt;br /&gt;
    else&lt;br /&gt;
      result = save_waitlist_entry(new_sign_up)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    result&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''longest_waiting_team''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves the team that has been on the waitlist the longest for the current topic. It sorts the waitlisted entries by their creation time and returns the oldest entry. This is useful for assigning slots to teams in a fair and chronological manner as slots become available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def longest_waiting_team&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: true).order(:created_at).first&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_team_from_topic(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This method removes a team from the current topic. If the removed team was not waitlisted, it reassigns the topic to the next waitlisted team, ensuring efficient utilization of available slots. The method then deletes the team's sign-up record, maintaining data consistency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def drop_team_from_topic(team_id)&lt;br /&gt;
    signed_up_team = SignedUpTeam.find_by(team_id: team_id, sign_up_topic_id: self.id)&lt;br /&gt;
    return nil unless signed_up_team&lt;br /&gt;
&lt;br /&gt;
    unless signed_up_team.is_waitlisted&lt;br /&gt;
      next_waitlisted_team = longest_waiting_team&lt;br /&gt;
      next_waitlisted_team&amp;amp;.reassign_topic(self.id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    signed_up_team.destroy&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''signed_up_teams_for_topic''':&lt;br /&gt;
&lt;br /&gt;
This method retrieves all teams that have signed up for the current topic, including both waitlisted and non-waitlisted teams. It provides an overview of the teams associated with a particular topic, aiding in administrative and reporting tasks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def signed_up_teams_for_topic&lt;br /&gt;
    SignedUpTeam.where(sign_up_topic_id: self.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''current_available_slots''':&lt;br /&gt;
&lt;br /&gt;
This method calculates the number of available slots for the topic by subtracting the count of non-waitlisted teams from the maximum allowed capacity. It ensures the integrity of slot management by providing real-time availability data, which is critical for the sign-up and waitlisting processes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def current_available_slots&lt;br /&gt;
    teams_who_chose_the_topic = SignedUpTeam.where(sign_up_topic_id: self.id, is_waitlisted: false)&lt;br /&gt;
    self.max_choosers.to_i - teams_who_chose_the_topic.size&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===signed_up_team===&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_waitlists(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method removes all waitlisted entries for a specific team. It deletes all sign-up records where the team is marked as waitlisted, ensuring the team is no longer on any waitlists.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_waitlists(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id, is_waitlisted: true).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''create_signed_up_team(topic_id, team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method creates a sign-up record for a team by associating it with the specified topic. It retrieves the project topic by its ID and uses the `sign_up_team` method to handle the sign-up process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.create_signed_up_team(topic_id, team_id)&lt;br /&gt;
    project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
    project_topic.sign_up_team(team_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''get_team_id(user_id, assignment_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method retrieves the team ID associated with a specific user and assignment. It first identifies the teams the user belongs to and then filters the team linked to the given assignment, returning its ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.get_team_id(user_id, assignment_id)&lt;br /&gt;
    team_ids = TeamsUser.select('team_id').where(user_id: user_id)&lt;br /&gt;
    team_id = Team.where(team_id: team_ids, assignment_id: assignment_id).first.team_id&lt;br /&gt;
    team_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''drop_off_team_signup_records(team_id)''':&lt;br /&gt;
&lt;br /&gt;
This class method deletes all sign-up records for a given team. It removes every entry associated with the specified team, clearing all their topic associations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.drop_off_team_signup_records(team_id)&lt;br /&gt;
    SignedUpTeam.where(team_id: team_id).destroy_all&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''reassign_topic(topic_id)''':&lt;br /&gt;
&lt;br /&gt;
This instance method reassigns a team to a new topic. It first removes the team from its current topic if they are assigned, then updates the team's waitlist status to indicate they are now assigned to the new topic.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def reassign_topic(topic_id)&lt;br /&gt;
    assigned_team = SignedUpTeam.where(team_id: self.team_id, is_waitlisted: false)&lt;br /&gt;
&lt;br /&gt;
    unless assigned_team.nil?&lt;br /&gt;
      project_topic = ProjectTopic.find(topic_id)&lt;br /&gt;
      project_topic.drop_team_from_topic(team_id: self.team_id)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    self.update(is_waitlisted: false)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159464</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159464"/>
		<updated>2024-11-13T04:39:03Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be implemented:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;sign_up_team:&amp;lt;/b&amp;gt; This method assigns a team to a specific topic if an open slot is available. In the reimplementation, it should check slot availability before proceeding with the assignment, updating slot count, and preventing duplicate signups. This method will handle both cases where slots are manually assigned and when automatically managed through deadlines.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;drop_team_from_topic:&amp;lt;/b&amp;gt; When a team drops a topic, this method should update the topic’s slot count and reassign the topic to the next team on the waitlist if one exists. In cases where a team has no members remaining, this function will automatically release the topic and perform necessary reassignment operations, using get_waiting_teams(topic_id) and reassign_topic(topic_id) as helper methods.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;get_waiting_teams:&amp;lt;/b&amp;gt; This method will retrieve a list of all teams waiting for a specific topic, ordered by the length of time they have been on the waitlist.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;reassign_topic:&amp;lt;/b&amp;gt; This method will manage the reassignment process when a topic is dropped. The reimplemented version should prioritize longest-waiting teams by calling get_waiting_teams and update the slot availability to ensure integrity across assignments and waitlist handling.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;assignment_teams_for_topic:&amp;lt;/b&amp;gt; This method retrieves all teams currently signed up for a given topic. In the reimplementation, it should use Active Record associations to fetch relevant AssignmentTeams with minimal database queries, optimizing performance and reducing overhead.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;current_available_slots:&amp;lt;/b&amp;gt; This method will retrieve and modify the current number of available slots for a topic, ensuring that the slot count reflects changes as teams sign up or drop topics. In the reimplementation, the slot count will be calculated based on assignments and adjusted dynamically.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;collect_due_dates:&amp;lt;/b&amp;gt; This method retrieves all due dates for a particular assignment's signup topics. For the reimplementation, due dates for submissions and reviews will be organized by assignment and topic, reducing complexity by structuring due dates for easier reference and retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159460</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159460"/>
		<updated>2024-11-13T04:34:19Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be implemented:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;sign_up_team:&amp;lt;/b&amp;gt; This method assigns a team to a specific topic if an open slot is available. In the reimplementation, it should check slot availability before proceeding with the assignment, updating slot count, and preventing duplicate signups. This method will handle both cases where slots are manually assigned and when automatically managed through deadlines.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;drop_team_from_topic:&amp;lt;/b&amp;gt; When a team drops a topic, this method should update the topic’s slot count and reassign the topic to the next team on the waitlist if one exists. In cases where a team has no members remaining, this function will automatically release the topic and perform necessary reassignment operations, using get_waiting_teams(topic_id) and reassign_topic(topic_id) as helper methods.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;get_waiting_teams:&amp;lt;/b&amp;gt; This method will retrieve a list of all teams waiting for a specific topic, ordered by the length of time they have been on the waitlist.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;reassign_topic:&amp;lt;/b&amp;gt; This method will manage the reassignment process when a topic is dropped. The reimplemented version should prioritize longest-waiting teams by calling get_waiting_teams and update the slot availability to ensure integrity across assignments and waitlist handling.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;assignment_teams_for_topic:&amp;lt;/b&amp;gt; This method retrieves all teams currently signed up for a given topic. In the reimplementation, it should use Active Record associations to fetch relevant AssignmentTeams with minimal database queries, optimizing performance and reducing overhead.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;current_available_slots:&amp;lt;/b&amp;gt; This method will retrieve and modify the current number of available slots for a topic, ensuring that the slot count reflects changes as teams sign up or drop topics. In the reimplementation, the slot count will be calculated based on assignments and adjusted dynamically.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;collect_due_dates:&amp;lt;/b&amp;gt; This method retrieves all due dates for a particular assignment's signup topics. For the reimplementation, due dates for submissions and reviews will be organized by assignment and topic, reducing complexity by structuring due dates for easier reference and retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159458</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159458"/>
		<updated>2024-11-13T04:32:54Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be implemented:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;sign_up_team:&amp;lt;/b&amp;gt; This method assigns a team to a specific topic if an open slot is available. In the reimplementation, it should check slot availability before proceeding with the assignment, updating slot count, and preventing duplicate signups. This method will handle both cases where slots are manually assigned and when automatically managed through deadlines.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;drop_team_from_topic:&amp;lt;/b&amp;gt; When a team drops a topic, this method should update the topic’s slot count and reassign the topic to the next team on the waitlist if one exists. In cases where a team has no members remaining, this function will automatically release the topic and perform necessary reassignment operations, using get_waiting_teams(topic_id) and reassign_topic(topic_id) as helper methods.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;get_waiting_teams:&amp;lt;/b&amp;gt; This method will retrieve a list of all teams waiting for a specific topic, ordered by the length of time they have been on the waitlist.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;reassign_topic:&amp;lt;/b&amp;gt; This method will manage the reassignment process when a topic is dropped. The reimplemented version should prioritize longest-waiting teams by calling get_waiting_teams and update the slot availability to ensure integrity across assignments and waitlist handling.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;assignment_teams_for_topic:&amp;lt;/b&amp;gt; This method retrieves all teams currently signed up for a given topic. In the reimplementation, it should use Active Record associations to fetch relevant AssignmentTeams with minimal database queries, optimizing performance and reducing overhead.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;current_available_slots:&amp;lt;/b&amp;gt; This method will retrieve and modify the current number of available slots for a topic, ensuring that the slot count reflects changes as teams sign up or drop topics. In the reimplementation, the slot count will be calculated based on assignments and adjusted dynamically.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;collect_due_dates:&amp;lt;/b&amp;gt; This method retrieves all due dates for a particular assignment's signup topics. For the reimplementation, due dates for submissions and reviews will be organized by assignment and topic, reducing complexity by structuring due dates for easier reference and retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
The following table outlines the test scenarios for the reimplementation of ProjectTopic, covering core functionalities for handling team signups, topic reassignment, and slot availability. Each scenario includes expected outcomes to guide RSpec testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;sign_up_team&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Open slot available for the topic. Expected: slot count decreases by 1.&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: No open slots for the topic. Expected: Team is not signed up, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Team already signed up for the topic. Expected: Team is not signed up again, slot count remains unchanged.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;drop_team_from_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Team with assigned topic drops the topic manually. Expected: Slot count increases by 1, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Last member leaves the team, releasing the assigned topic. Expected: Topic is released, slot count increases, longest-waiting team (if any) is assigned.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;get_waiting_teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: Multiple teams on the waitlist. Expected: Returns all teams that are in the waitlist in the order of time.&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: No teams on the waitlist. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;reassign_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Open slot is available, and a team is waiting. Expected: Topic is reassigned to the longest-waiting team.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: No teams are waiting. Expected: Slot remains available, no reassignment occurs.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;assignment_teams_for_topic&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Teams are signed up for the topic. Expected: Returns list of AssignmentTeams signed up for the topic.&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: No teams are signed up for the topic. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;current_available_slots&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Slots are available for team sign-ups. Expected: Returns the correct number of available slots.&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: All slots are occupied. Expected: Returns 0.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;collect_due_dates&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Due dates exist for the assignment. Expected: Returns due dates for submissions and reviews.&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: No due dates exist for the assignment. Expected: Returns an empty list.&lt;br /&gt;
|-&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125 Pull Request 125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159424</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159424"/>
		<updated>2024-11-13T03:27:19Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be implemented:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;sign_up_team:&amp;lt;/b&amp;gt; This method assigns a team to a specific topic if an open slot is available. In the reimplementation, it should check slot availability before proceeding with the assignment, updating slot count, and preventing duplicate signups. This method will handle both cases where slots are manually assigned and when automatically managed through deadlines.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;drop_team_from_topic:&amp;lt;/b&amp;gt; When a team drops a topic, this method should update the topic’s slot count and reassign the topic to the next team on the waitlist if one exists. In cases where a team has no members remaining, this function will automatically release the topic and perform necessary reassignment operations, using get_waiting_teams(topic_id) and reassign_topic(topic_id) as helper methods.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;get_waiting_teams:&amp;lt;/b&amp;gt; This method will retrieve a list of all teams waiting for a specific topic, ordered by the length of time they have been on the waitlist.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;reassign_topic:&amp;lt;/b&amp;gt; This method will manage the reassignment process when a topic is dropped. The reimplemented version should prioritize longest-waiting teams by calling get_waiting_teams and update the slot availability to ensure integrity across assignments and waitlist handling.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;assignment_teams_for_topic:&amp;lt;/b&amp;gt; This method retrieves all teams currently signed up for a given topic. In the reimplementation, it should use Active Record associations to fetch relevant AssignmentTeams with minimal database queries, optimizing performance and reducing overhead.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;current_available_slots:&amp;lt;/b&amp;gt; This method will retrieve and modify the current number of available slots for a topic, ensuring that the slot count reflects changes as teams sign up or drop topics. In the reimplementation, the slot count will be calculated based on assignments and adjusted dynamically.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;collect_due_dates:&amp;lt;/b&amp;gt; This method retrieves all due dates for a particular assignment's signup topics. For the reimplementation, due dates for submissions and reviews will be organized by assignment and topic, reducing complexity by structuring due dates for easier reference and retrieval.&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We plan to use the given test skeletons for assignment model and implement the respective Rspec test cases. The test cases for other methods will be included later as reimplementation might have methods which are combined versions of multiple other methods. The test scenarios for some for the methods are mentioned in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Max_team_size is greater than 0. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: Max_team_size is equal to 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Max_team_size is less than 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;topics&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Sign_up_topics is empty. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Sign_up_topics is not empty. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: The object is calibrated. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: The object is not calibrated. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Teams are present. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: Teams are not present. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Number of reviews required is greater than the number of reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: Number of meta-reviews required is greater than the number of meta-reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;dynamic_reviewer_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Review assignment strategy is RS_AUTO_SELECTED. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: Review assignment strategy is not RS_AUTO_SELECTED. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Has_badge is nil. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: Has_badge is true. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 7.3 || Scenario 3: Has_badge is false. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 8 || &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8.1 || Scenario 1: Parent node exists. Expected: New node created with parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 8.2 || Scenario 2: Parent node does not exist. Expected: New node created with no parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9.1 || Scenario 1: Rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.2 || Scenario 2: Multiple rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.3 || Scenario 3: No rubrics of a given type exist in round 2. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 10 || &amp;lt;strong&amp;gt;num_review_rounds&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10.1 || Scenario 1: No due dates. Expected: 0&lt;br /&gt;
|-&lt;br /&gt;
| 10.2 || Scenario 2: Single due date with round 1. Expected: 1&lt;br /&gt;
|-&lt;br /&gt;
| 10.3 || Scenario 3: Multiple due dates with different rounds. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 10.4 || Scenario 4: Multiple due dates with the same round number. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 11 || &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11.1 || Scenario 1: No round_number and topic_id provided. Expected: id of the current round's review questionnaire.&lt;br /&gt;
|-&lt;br /&gt;
| 11.2 || Scenario 2: No round_number and topic_id provided, no next due date. Expected: nil&lt;br /&gt;
|-&lt;br /&gt;
| 12 || &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 12.1 || Scenario 1: Pair programming is enabled. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 12.2 || Scenario 2: Pair programming is disabled. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 13 || &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 13.1 || Scenario 1: Staggered deadline is enabled, topic_id not provided. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 13.2 || Scenario 2: Staggered deadline is enabled, topic_id provided. Expected: false&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159415</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159415"/>
		<updated>2024-11-13T03:12:17Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementing the SignUpTopic as ProjectTopic, the following design rules must be ensured:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintain Functional Integrity:&amp;lt;/b&amp;gt; Validate the functionality of existing and new methods, incorporating any necessary improvements to meet updated requirements for managing topic signups, slot availability, and team assignments.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Promote Loose Coupling and Tight Cohesion:&amp;lt;/b&amp;gt; Ensure that ProjectTopic and related classes, such as SignedUpTeam, are designed for optimal organization and maintainability, with clear separation of responsibilities to improve code quality and reduce dependencies.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Apply the DRY Principle:&amp;lt;/b&amp;gt; Refactor any redundant code in the previous implementation, adhering to DRY principles by eliminating duplicated functionality from the Expertiza system and implementing reusable methods where possible.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;b&amp;gt;Ensure Robust Testing and Documentation:&amp;lt;/b&amp;gt; Validate the accuracy of existing test cases, updating them to reflect changes in ProjectTopic. Add comprehensive RSpec tests for new functionality, and perform Swagger UI testing on API endpoints to ensure complete coverage and reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be re-implemented and implemented as it is:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method raises an error if more reviews are required than are allowed. But it is a single method for both reviews and meta reviews. In the reimplemented method, type of review will be a parameter.&lt;br /&gt;
* &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether different rubrics are being used in different rounds of review.  It does it, however, by checking whether more than one rubric is listed as being used in Round 2 (used_in_round = 2). The reimplemented method will check if we have more than one rubric of a given type for an assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the has_badge instance variable and this should be renamed to has_badge?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the is_calibrated instance variable and should be renamed is_calibrated?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage&amp;lt;/strong&amp;gt;&lt;br /&gt;
his method returns the current stage (Submission, Review, Finished, etc.) potentially based on which topic the logged-in user holds.  It returns a string, which is useful for printing, though a bit informal.  However, since this method is quite similar to two other methods - current_stage_name and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage_name&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a convoluted method that returns the same thing as current_stage, except in a few specialized cases, such as when the assignment has topics and the user hasn’t chosen a topic.  However, since this method is quite similar to two other methods - current_stage and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;stage_deadline&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is similar to current_stage, but returns the time of the next deadline unless the assignment is finished. However, since this method is quite similar to two other methods - current_stage_name and current_stage, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;num_reviews_greater?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether the number of reviews required is greater than the number of reviews allowed.  Basically, it just compares two instance variables of Assignment,but handles the special cases of reviews_allowed being null or negative. In the reimplemented method, we will check if reviews_allowed is valid or not in a separate function.&lt;br /&gt;
* &amp;lt;strong&amp;gt;quiz_allowed&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the quiz_allowed_id field of the next due date, i.e., whether a participant is currently allowed to take a quiz. This method will be reimplemented without making a direct call to the check_condition.&lt;br /&gt;
* &amp;lt;strong&amp;gt;response_map_to_metareview&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the “most appropriate” ResponseMap to use as the reviewed_object in a new MetareviewResponseMap.  This can be made as a class method of MetareviewResponseMap and combined with the reviewer_metareviews_map method that is basically a step of this method.&lt;br /&gt;
* &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the questionnaire in use for reviews of work submitted for the assignment. This is a complicated method because it calculates to find the round number, instead of using number_of_current_round(...). In the reimplementation, instead of creating a new form, we can use an already existing form that is associated with the assignment. The logic behind determining a round number based on the topic can also be improved.  &lt;br /&gt;
* &amp;lt;strong&amp;gt;reviewer_metareviews_map&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a step in finding the response_map_to_metareview.  There is no need for a separate method for finding reviewer_metareviews_map. This method can be combined with response_map_to_metareview during reimplementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note : &amp;lt;/strong&amp;gt;The following methods do not require specific changes and will be implemented accordingly.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment. &lt;br /&gt;
* &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the enable_pair_programming instance variable.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks if the assignment is a staggered-deadline assignment and the logged-in user has not chosen a topic. &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether max_team_size &amp;gt; 0 (should be &amp;gt; 1). &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;teams?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any teams exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;topics?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any topics exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note :&amp;lt;/strong&amp;gt; The following methods will be removed as they are no longer required in the new implementation -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be moved to another models : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*assign_metareviewer_dynamically&lt;br /&gt;
*can_review&lt;br /&gt;
*check_condition&lt;br /&gt;
*find_current_stage&lt;br /&gt;
*find_due_dates&lt;br /&gt;
*find_reveiw_period&lt;br /&gt;
*link_for_current_stage&lt;br /&gt;
*metareview_allowed&lt;br /&gt;
*num_review_rounds&lt;br /&gt;
*num_of_current_round&lt;br /&gt;
*submission_allowed&lt;br /&gt;
*user_on_team?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be removed : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*microtask?&lt;br /&gt;
*min_metareview&lt;br /&gt;
*questionnaire_ids&lt;br /&gt;
*remove_empty_teams&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We plan to use the given test skeletons for assignment model and implement the respective Rspec test cases. The test cases for other methods will be included later as reimplementation might have methods which are combined versions of multiple other methods. The test scenarios for some for the methods are mentioned in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Max_team_size is greater than 0. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: Max_team_size is equal to 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Max_team_size is less than 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;topics&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Sign_up_topics is empty. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Sign_up_topics is not empty. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: The object is calibrated. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: The object is not calibrated. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Teams are present. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: Teams are not present. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Number of reviews required is greater than the number of reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: Number of meta-reviews required is greater than the number of meta-reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;dynamic_reviewer_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Review assignment strategy is RS_AUTO_SELECTED. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: Review assignment strategy is not RS_AUTO_SELECTED. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Has_badge is nil. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: Has_badge is true. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 7.3 || Scenario 3: Has_badge is false. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 8 || &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8.1 || Scenario 1: Parent node exists. Expected: New node created with parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 8.2 || Scenario 2: Parent node does not exist. Expected: New node created with no parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9.1 || Scenario 1: Rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.2 || Scenario 2: Multiple rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.3 || Scenario 3: No rubrics of a given type exist in round 2. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 10 || &amp;lt;strong&amp;gt;num_review_rounds&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10.1 || Scenario 1: No due dates. Expected: 0&lt;br /&gt;
|-&lt;br /&gt;
| 10.2 || Scenario 2: Single due date with round 1. Expected: 1&lt;br /&gt;
|-&lt;br /&gt;
| 10.3 || Scenario 3: Multiple due dates with different rounds. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 10.4 || Scenario 4: Multiple due dates with the same round number. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 11 || &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11.1 || Scenario 1: No round_number and topic_id provided. Expected: id of the current round's review questionnaire.&lt;br /&gt;
|-&lt;br /&gt;
| 11.2 || Scenario 2: No round_number and topic_id provided, no next due date. Expected: nil&lt;br /&gt;
|-&lt;br /&gt;
| 12 || &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 12.1 || Scenario 1: Pair programming is enabled. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 12.2 || Scenario 2: Pair programming is disabled. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 13 || &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 13.1 || Scenario 1: Staggered deadline is enabled, topic_id not provided. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 13.2 || Scenario 2: Staggered deadline is enabled, topic_id provided. Expected: false&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159398</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159398"/>
		<updated>2024-11-13T03:00:13Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation of sign up topic as project topic in the Expertiza backend.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Redesigning SignUpTopic as ProjectTopic:&amp;lt;/b&amp;gt; This involves reimplementing SignUpTopic class from the original expertiza repository as ProjectTopic within reimplementation-backend repository. This reimplementation should follow Rails best practices, use Ruby naming conventions, and adhere to the DRY principle to improve code maintainability and readability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Implementing Team Signup and Topic Drop Functionality:&amp;lt;/b&amp;gt; Adding methods to sign a team up for a topic and handling cases when a team drops a topic.&lt;br /&gt;
#&amp;lt;b&amp;gt;Assignment Team Retrieval:&amp;lt;/b&amp;gt; Implementing a method to retrieve AssignmentTeams that are currently signed up for a specific topic, allowing for efficient tracking and management of team assignments.&lt;br /&gt;
#&amp;lt;b&amp;gt;Slot Availability Management:&amp;lt;/b&amp;gt; Including methods for managing and retrieving the current number of available slots for a topic, updating as teams sign up or drop topics to reflect accurate availability.&lt;br /&gt;
#&amp;lt;b&amp;gt;Due Date Retrieval for Signup Topics:&amp;lt;/b&amp;gt; Implementing methods to collect and return signup topics with their associated submission and review due dates for a particular assignment, aiding in deadline management for teams.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for project topic model:&amp;lt;/b&amp;gt; RSpec tests have to be written for ProjectTopic Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing Swagger UI tests for API endpoints:&amp;lt;/b&amp;gt; Swagger UI tests have to be written to test ProjectTopic and SignedUpTeam functionalities.&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementation of Assignment model and controller, the following design rules have to be ensured:&lt;br /&gt;
* Validate proper functioning of all existing and anticipated methods, making any required enhancements or adjustments.&lt;br /&gt;
* Establish loose coupling and tight cohesion for the model and controller to enhance code organization and maintainability.&lt;br /&gt;
* Refactor redundant code in the previous implementation's controller and model methods using DRY principle, eliminating functionality duplications already present in the expertiza system.&lt;br /&gt;
* Confirm the continued effectiveness of existing test cases following the aforementioned modifications and generate additional test cases as per the need.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be re-implemented and implemented as it is:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method raises an error if more reviews are required than are allowed. But it is a single method for both reviews and meta reviews. In the reimplemented method, type of review will be a parameter.&lt;br /&gt;
* &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether different rubrics are being used in different rounds of review.  It does it, however, by checking whether more than one rubric is listed as being used in Round 2 (used_in_round = 2). The reimplemented method will check if we have more than one rubric of a given type for an assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the has_badge instance variable and this should be renamed to has_badge?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the is_calibrated instance variable and should be renamed is_calibrated?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage&amp;lt;/strong&amp;gt;&lt;br /&gt;
his method returns the current stage (Submission, Review, Finished, etc.) potentially based on which topic the logged-in user holds.  It returns a string, which is useful for printing, though a bit informal.  However, since this method is quite similar to two other methods - current_stage_name and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage_name&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a convoluted method that returns the same thing as current_stage, except in a few specialized cases, such as when the assignment has topics and the user hasn’t chosen a topic.  However, since this method is quite similar to two other methods - current_stage and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;stage_deadline&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is similar to current_stage, but returns the time of the next deadline unless the assignment is finished. However, since this method is quite similar to two other methods - current_stage_name and current_stage, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;num_reviews_greater?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether the number of reviews required is greater than the number of reviews allowed.  Basically, it just compares two instance variables of Assignment,but handles the special cases of reviews_allowed being null or negative. In the reimplemented method, we will check if reviews_allowed is valid or not in a separate function.&lt;br /&gt;
* &amp;lt;strong&amp;gt;quiz_allowed&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the quiz_allowed_id field of the next due date, i.e., whether a participant is currently allowed to take a quiz. This method will be reimplemented without making a direct call to the check_condition.&lt;br /&gt;
* &amp;lt;strong&amp;gt;response_map_to_metareview&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the “most appropriate” ResponseMap to use as the reviewed_object in a new MetareviewResponseMap.  This can be made as a class method of MetareviewResponseMap and combined with the reviewer_metareviews_map method that is basically a step of this method.&lt;br /&gt;
* &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the questionnaire in use for reviews of work submitted for the assignment. This is a complicated method because it calculates to find the round number, instead of using number_of_current_round(...). In the reimplementation, instead of creating a new form, we can use an already existing form that is associated with the assignment. The logic behind determining a round number based on the topic can also be improved.  &lt;br /&gt;
* &amp;lt;strong&amp;gt;reviewer_metareviews_map&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a step in finding the response_map_to_metareview.  There is no need for a separate method for finding reviewer_metareviews_map. This method can be combined with response_map_to_metareview during reimplementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note : &amp;lt;/strong&amp;gt;The following methods do not require specific changes and will be implemented accordingly.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment. &lt;br /&gt;
* &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the enable_pair_programming instance variable.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks if the assignment is a staggered-deadline assignment and the logged-in user has not chosen a topic. &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether max_team_size &amp;gt; 0 (should be &amp;gt; 1). &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;teams?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any teams exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;topics?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any topics exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note :&amp;lt;/strong&amp;gt; The following methods will be removed as they are no longer required in the new implementation -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be moved to another models : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*assign_metareviewer_dynamically&lt;br /&gt;
*can_review&lt;br /&gt;
*check_condition&lt;br /&gt;
*find_current_stage&lt;br /&gt;
*find_due_dates&lt;br /&gt;
*find_reveiw_period&lt;br /&gt;
*link_for_current_stage&lt;br /&gt;
*metareview_allowed&lt;br /&gt;
*num_review_rounds&lt;br /&gt;
*num_of_current_round&lt;br /&gt;
*submission_allowed&lt;br /&gt;
*user_on_team?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be removed : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*microtask?&lt;br /&gt;
*min_metareview&lt;br /&gt;
*questionnaire_ids&lt;br /&gt;
*remove_empty_teams&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We plan to use the given test skeletons for assignment model and implement the respective Rspec test cases. The test cases for other methods will be included later as reimplementation might have methods which are combined versions of multiple other methods. The test scenarios for some for the methods are mentioned in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Max_team_size is greater than 0. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: Max_team_size is equal to 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Max_team_size is less than 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;topics&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Sign_up_topics is empty. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Sign_up_topics is not empty. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: The object is calibrated. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: The object is not calibrated. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Teams are present. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: Teams are not present. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Number of reviews required is greater than the number of reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: Number of meta-reviews required is greater than the number of meta-reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;dynamic_reviewer_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Review assignment strategy is RS_AUTO_SELECTED. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: Review assignment strategy is not RS_AUTO_SELECTED. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Has_badge is nil. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: Has_badge is true. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 7.3 || Scenario 3: Has_badge is false. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 8 || &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8.1 || Scenario 1: Parent node exists. Expected: New node created with parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 8.2 || Scenario 2: Parent node does not exist. Expected: New node created with no parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9.1 || Scenario 1: Rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.2 || Scenario 2: Multiple rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.3 || Scenario 3: No rubrics of a given type exist in round 2. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 10 || &amp;lt;strong&amp;gt;num_review_rounds&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10.1 || Scenario 1: No due dates. Expected: 0&lt;br /&gt;
|-&lt;br /&gt;
| 10.2 || Scenario 2: Single due date with round 1. Expected: 1&lt;br /&gt;
|-&lt;br /&gt;
| 10.3 || Scenario 3: Multiple due dates with different rounds. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 10.4 || Scenario 4: Multiple due dates with the same round number. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 11 || &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11.1 || Scenario 1: No round_number and topic_id provided. Expected: id of the current round's review questionnaire.&lt;br /&gt;
|-&lt;br /&gt;
| 11.2 || Scenario 2: No round_number and topic_id provided, no next due date. Expected: nil&lt;br /&gt;
|-&lt;br /&gt;
| 12 || &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 12.1 || Scenario 1: Pair programming is enabled. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 12.2 || Scenario 2: Pair programming is disabled. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 13 || &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 13.1 || Scenario 1: Staggered deadline is enabled, topic_id not provided. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 13.2 || Scenario 2: Staggered deadline is enabled, topic_id provided. Expected: false&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=159357</id>
		<title>CSC/ECE 517 Fall 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=159357"/>
		<updated>2024-11-13T01:47:16Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Fall 2024 - E2450. Refactor assignments_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2451. Reimplement feedback_response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2452. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2453. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2454. Refactor student_task.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2455. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2456. Refactor teams_user.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2456. Refactor teams_user.rb (Phase 2 - Design Document)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2457. GitHub metrics integration]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2458. User management and users table]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2459. View for results of bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2460 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2461. UI for Courses]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2461. UI and Backend for Courses]]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2462._UI_for_Questionnaires CSC/ECE 517 Fall 2024 - E2462. UI for Questionnaire.rb]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2463_Implement_Front_End_for_Student_Task_List CSC/ECE 517 Fall 2024 - E2463. UI for Student Task List]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2464 UI for Project Topics (was: Sign_up_Topics)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2465. UI for Institutions and Notification]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2467. UI for View Submissions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2468. Reimplement due_date]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2469. Reimplement grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2470. Reimplement grades_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2471. Reimplement logger]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2472. Reimplement responses_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2474. Reimplement student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2475. Reimplement student_task view]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2476. Reimplement student_teams_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2477. Reimplement suggestion_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2478. Reimplement the Question hierarchy as Item hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2479. Reimplement teams_users_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2480. Implement testing for new Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2481 Reimplement response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2482. Reimplement heatgrid for reviews]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2483. Reimplement Notification Controller and Model]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2484. Reimplement participants_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2485. Allow reviewers to bid on what to review]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2487. Reimplement authorization_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2488 Reimplementation of Add TA to course]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2491.UI for View assignments in Courses view]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2492. UI for View submissions/assign grades (except heatgrid)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2493. UI for Assign Reviewers]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2401 Refactor Graphql API endpoint for contribution metrics]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2402 Refactor Graphql API endpoint for repositories]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159356</id>
		<title>CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159356"/>
		<updated>2024-11-13T01:46:49Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb: Misspelled title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159355</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159355"/>
		<updated>2024-11-13T01:46:49Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb: Misspelled title&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;
==Introduction==&lt;br /&gt;
This project is a reimplementation for the assignment model and assignment controller in the Expertiza backend. &lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Enhancing Code Clarity:&amp;lt;/b&amp;gt; This involves renaming methods with ambiguous names, optimizing loops and adding comments for unclear lines of code.&lt;br /&gt;
#&amp;lt;b&amp;gt;Removing unused methods&amp;lt;/b&amp;gt; Removing unused methods will reduce complexity.&lt;br /&gt;
#&amp;lt;b&amp;gt;Reimplement Assignment model and controller:&amp;lt;/b&amp;gt; Reimplement the methods from Assignment model that are complex and can be implemented in a better way to reduce complexity and by not violating the DRY principles.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for assignment models:&amp;lt;/b&amp;gt; Tests have to be written for Assignment Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for the assignment controller:&amp;lt;/b&amp;gt; RSwag tests should be written for Assignment Controller&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementation of Assignment model and controller, the following design rules have to be ensured:&lt;br /&gt;
* Validate proper functioning of all existing and anticipated methods, making any required enhancements or adjustments.&lt;br /&gt;
* Establish loose coupling and tight cohesion for the model and controller to enhance code organization and maintainability.&lt;br /&gt;
* Refactor redundant code in the previous implementation's controller and model methods using DRY principle, eliminating functionality duplications already present in the expertiza system.&lt;br /&gt;
* Confirm the continued effectiveness of existing test cases following the aforementioned modifications and generate additional test cases as per the need.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be re-implemented and implemented as it is:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method raises an error if more reviews are required than are allowed. But it is a single method for both reviews and meta reviews. In the reimplemented method, type of review will be a parameter.&lt;br /&gt;
* &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether different rubrics are being used in different rounds of review.  It does it, however, by checking whether more than one rubric is listed as being used in Round 2 (used_in_round = 2). The reimplemented method will check if we have more than one rubric of a given type for an assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the has_badge instance variable and this should be renamed to has_badge?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the is_calibrated instance variable and should be renamed is_calibrated?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage&amp;lt;/strong&amp;gt;&lt;br /&gt;
his method returns the current stage (Submission, Review, Finished, etc.) potentially based on which topic the logged-in user holds.  It returns a string, which is useful for printing, though a bit informal.  However, since this method is quite similar to two other methods - current_stage_name and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage_name&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a convoluted method that returns the same thing as current_stage, except in a few specialized cases, such as when the assignment has topics and the user hasn’t chosen a topic.  However, since this method is quite similar to two other methods - current_stage and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;stage_deadline&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is similar to current_stage, but returns the time of the next deadline unless the assignment is finished. However, since this method is quite similar to two other methods - current_stage_name and current_stage, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;num_reviews_greater?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether the number of reviews required is greater than the number of reviews allowed.  Basically, it just compares two instance variables of Assignment,but handles the special cases of reviews_allowed being null or negative. In the reimplemented method, we will check if reviews_allowed is valid or not in a separate function.&lt;br /&gt;
* &amp;lt;strong&amp;gt;quiz_allowed&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the quiz_allowed_id field of the next due date, i.e., whether a participant is currently allowed to take a quiz. This method will be reimplemented without making a direct call to the check_condition.&lt;br /&gt;
* &amp;lt;strong&amp;gt;response_map_to_metareview&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the “most appropriate” ResponseMap to use as the reviewed_object in a new MetareviewResponseMap.  This can be made as a class method of MetareviewResponseMap and combined with the reviewer_metareviews_map method that is basically a step of this method.&lt;br /&gt;
* &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the questionnaire in use for reviews of work submitted for the assignment. This is a complicated method because it calculates to find the round number, instead of using number_of_current_round(...). In the reimplementation, instead of creating a new form, we can use an already existing form that is associated with the assignment. The logic behind determining a round number based on the topic can also be improved.  &lt;br /&gt;
* &amp;lt;strong&amp;gt;reviewer_metareviews_map&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a step in finding the response_map_to_metareview.  There is no need for a separate method for finding reviewer_metareviews_map. This method can be combined with response_map_to_metareview during reimplementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note : &amp;lt;/strong&amp;gt;The following methods do not require specific changes and will be implemented accordingly.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment. &lt;br /&gt;
* &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the enable_pair_programming instance variable.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks if the assignment is a staggered-deadline assignment and the logged-in user has not chosen a topic. &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether max_team_size &amp;gt; 0 (should be &amp;gt; 1). &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;teams?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any teams exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;topics?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any topics exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note :&amp;lt;/strong&amp;gt; The following methods will be removed as they are no longer required in the new implementation -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be moved to another models : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*assign_metareviewer_dynamically&lt;br /&gt;
*can_review&lt;br /&gt;
*check_condition&lt;br /&gt;
*find_current_stage&lt;br /&gt;
*find_due_dates&lt;br /&gt;
*find_reveiw_period&lt;br /&gt;
*link_for_current_stage&lt;br /&gt;
*metareview_allowed&lt;br /&gt;
*num_review_rounds&lt;br /&gt;
*num_of_current_round&lt;br /&gt;
*submission_allowed&lt;br /&gt;
*user_on_team?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be removed : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*microtask?&lt;br /&gt;
*min_metareview&lt;br /&gt;
*questionnaire_ids&lt;br /&gt;
*remove_empty_teams&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We plan to use the given test skeletons for assignment model and implement the respective Rspec test cases. The test cases for other methods will be included later as reimplementation might have methods which are combined versions of multiple other methods. The test scenarios for some for the methods are mentioned in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Max_team_size is greater than 0. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: Max_team_size is equal to 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Max_team_size is less than 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;topics&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Sign_up_topics is empty. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Sign_up_topics is not empty. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: The object is calibrated. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: The object is not calibrated. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Teams are present. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: Teams are not present. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Number of reviews required is greater than the number of reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: Number of meta-reviews required is greater than the number of meta-reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;dynamic_reviewer_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Review assignment strategy is RS_AUTO_SELECTED. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: Review assignment strategy is not RS_AUTO_SELECTED. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Has_badge is nil. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: Has_badge is true. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 7.3 || Scenario 3: Has_badge is false. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 8 || &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8.1 || Scenario 1: Parent node exists. Expected: New node created with parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 8.2 || Scenario 2: Parent node does not exist. Expected: New node created with no parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9.1 || Scenario 1: Rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.2 || Scenario 2: Multiple rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.3 || Scenario 3: No rubrics of a given type exist in round 2. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 10 || &amp;lt;strong&amp;gt;num_review_rounds&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10.1 || Scenario 1: No due dates. Expected: 0&lt;br /&gt;
|-&lt;br /&gt;
| 10.2 || Scenario 2: Single due date with round 1. Expected: 1&lt;br /&gt;
|-&lt;br /&gt;
| 10.3 || Scenario 3: Multiple due dates with different rounds. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 10.4 || Scenario 4: Multiple due dates with the same round number. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 11 || &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11.1 || Scenario 1: No round_number and topic_id provided. Expected: id of the current round's review questionnaire.&lt;br /&gt;
|-&lt;br /&gt;
| 11.2 || Scenario 2: No round_number and topic_id provided, no next due date. Expected: nil&lt;br /&gt;
|-&lt;br /&gt;
| 12 || &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 12.1 || Scenario 1: Pair programming is enabled. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 12.2 || Scenario 2: Pair programming is disabled. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 13 || &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 13.1 || Scenario 1: Staggered deadline is enabled, topic_id not provided. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 13.2 || Scenario 2: Staggered deadline is enabled, topic_id provided. Expected: false&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=159354</id>
		<title>CSC/ECE 517 Fall 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024&amp;diff=159354"/>
		<updated>2024-11-13T01:45:45Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Fall 2024 - E2450. Refactor assignments_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2451. Reimplement feedback_response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2452. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2453. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2454. Refactor student_task.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2455. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2456. Refactor teams_user.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2456. Refactor teams_user.rb (Phase 2 - Design Document)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2457. GitHub metrics integration]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2458. User management and users table]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2459. View for results of bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2460 Mentor-Meeting Management]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2461. UI for Courses]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2461. UI and Backend for Courses]]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2462._UI_for_Questionnaires CSC/ECE 517 Fall 2024 - E2462. UI for Questionnaire.rb]&lt;br /&gt;
* [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2463_Implement_Front_End_for_Student_Task_List CSC/ECE 517 Fall 2024 - E2463. UI for Student Task List]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2464 UI for Project Topics (was: Sign_up_Topics)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2465. UI for Institutions and Notification]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2466. UI for Impersonate User]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2467. UI for View Submissions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2468. Reimplement due_date]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2469. Reimplement grades/view_team]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2470. Reimplement grades_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2471. Reimplement logger]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2472. Reimplement responses_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2474. Reimplement student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2475. Reimplement student_task view]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2476. Reimplement student_teams_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2477. Reimplement suggestion_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2478. Reimplement the Question hierarchy as Item hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2479. Reimplement teams_users_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2480. Implement testing for new Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2481 Reimplement response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2482. Reimplement heatgrid for reviews]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2483. Reimplement Notification Controller and Model]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2484. Reimplement participants_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2485. Allow reviewers to bid on what to review]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2487. Reimplement authorization_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2488 Reimplementation of Add TA to course]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2491.UI for View assignments in Courses view]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2492. UI for View submissions/assign grades (except heatgrid)]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - E2493. UI for Assign Reviewers]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2401 Refactor Graphql API endpoint for contribution metrics]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024 - G2402 Refactor Graphql API endpoint for repositories]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159352</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=159352"/>
		<updated>2024-11-13T01:44:11Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &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;
==Introduction==&lt;br /&gt;
This project is a reimplementation for the assignment model and assignment controller in the Expertiza backend. &lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The following tasks were required for the reimplementation :&lt;br /&gt;
#&amp;lt;b&amp;gt;Enhancing Code Clarity:&amp;lt;/b&amp;gt; This involves renaming methods with ambiguous names, optimizing loops and adding comments for unclear lines of code.&lt;br /&gt;
#&amp;lt;b&amp;gt;Removing unused methods&amp;lt;/b&amp;gt; Removing unused methods will reduce complexity.&lt;br /&gt;
#&amp;lt;b&amp;gt;Reimplement Assignment model and controller:&amp;lt;/b&amp;gt; Reimplement the methods from Assignment model that are complex and can be implemented in a better way to reduce complexity and by not violating the DRY principles.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for assignment models:&amp;lt;/b&amp;gt; Tests have to be written for Assignment Model.&lt;br /&gt;
#&amp;lt;b&amp;gt;Writing tests for the assignment controller:&amp;lt;/b&amp;gt; RSwag tests should be written for Assignment Controller&lt;br /&gt;
&lt;br /&gt;
==Design Goal==&lt;br /&gt;
While reimplementation of Assignment model and controller, the following design rules have to be ensured:&lt;br /&gt;
* Validate proper functioning of all existing and anticipated methods, making any required enhancements or adjustments.&lt;br /&gt;
* Establish loose coupling and tight cohesion for the model and controller to enhance code organization and maintainability.&lt;br /&gt;
* Refactor redundant code in the previous implementation's controller and model methods using DRY principle, eliminating functionality duplications already present in the expertiza system.&lt;br /&gt;
* Confirm the continued effectiveness of existing test cases following the aforementioned modifications and generate additional test cases as per the need.&lt;br /&gt;
&lt;br /&gt;
==Implementation Plan==&lt;br /&gt;
&lt;br /&gt;
Documentation for methods that will be re-implemented and implemented as it is:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method raises an error if more reviews are required than are allowed. But it is a single method for both reviews and meta reviews. In the reimplemented method, type of review will be a parameter.&lt;br /&gt;
* &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether different rubrics are being used in different rounds of review.  It does it, however, by checking whether more than one rubric is listed as being used in Round 2 (used_in_round = 2). The reimplemented method will check if we have more than one rubric of a given type for an assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the has_badge instance variable and this should be renamed to has_badge?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the is_calibrated instance variable and should be renamed is_calibrated?.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage&amp;lt;/strong&amp;gt;&lt;br /&gt;
his method returns the current stage (Submission, Review, Finished, etc.) potentially based on which topic the logged-in user holds.  It returns a string, which is useful for printing, though a bit informal.  However, since this method is quite similar to two other methods - current_stage_name and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;current_stage_name&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a convoluted method that returns the same thing as current_stage, except in a few specialized cases, such as when the assignment has topics and the user hasn’t chosen a topic.  However, since this method is quite similar to two other methods - current_stage and stage_deadline, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;stage_deadline&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is similar to current_stage, but returns the time of the next deadline unless the assignment is finished. However, since this method is quite similar to two other methods - current_stage_name and current_stage, these three can be combined with some modifications in the reimplementation for clarity. For these, we will create a duedate model and implement the get_next_due_date method 2 subclasses- TopicDueDate and AssignmentDueDate.&lt;br /&gt;
* &amp;lt;strong&amp;gt;num_reviews_greater?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether the number of reviews required is greater than the number of reviews allowed.  Basically, it just compares two instance variables of Assignment,but handles the special cases of reviews_allowed being null or negative. In the reimplemented method, we will check if reviews_allowed is valid or not in a separate function.&lt;br /&gt;
* &amp;lt;strong&amp;gt;quiz_allowed&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the quiz_allowed_id field of the next due date, i.e., whether a participant is currently allowed to take a quiz. This method will be reimplemented without making a direct call to the check_condition.&lt;br /&gt;
* &amp;lt;strong&amp;gt;response_map_to_metareview&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the “most appropriate” ResponseMap to use as the reviewed_object in a new MetareviewResponseMap.  This can be made as a class method of MetareviewResponseMap and combined with the reviewer_metareviews_map method that is basically a step of this method.&lt;br /&gt;
* &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method finds the questionnaire in use for reviews of work submitted for the assignment. This is a complicated method because it calculates to find the round number, instead of using number_of_current_round(...). In the reimplementation, instead of creating a new form, we can use an already existing form that is associated with the assignment. The logic behind determining a round number based on the topic can also be improved.  &lt;br /&gt;
* &amp;lt;strong&amp;gt;reviewer_metareviews_map&amp;lt;/strong&amp;gt;&lt;br /&gt;
This is a step in finding the response_map_to_metareview.  There is no need for a separate method for finding reviewer_metareviews_map. This method can be combined with response_map_to_metareview during reimplementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note : &amp;lt;/strong&amp;gt;The following methods do not require specific changes and will be implemented accordingly.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment. &lt;br /&gt;
* &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method returns the value of the enable_pair_programming instance variable.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks if the assignment is a staggered-deadline assignment and the logged-in user has not chosen a topic. &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method checks whether max_team_size &amp;gt; 0 (should be &amp;gt; 1). &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;teams?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any teams exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;topics?&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method is used to check whether any topics exist for this assignment.&lt;br /&gt;
* &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
This method creates an AssignmentNode for this assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note :&amp;lt;/strong&amp;gt; The following methods will be removed as they are no longer required in the new implementation -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be moved to another models : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*assign_metareviewer_dynamically&lt;br /&gt;
*can_review&lt;br /&gt;
*check_condition&lt;br /&gt;
*find_current_stage&lt;br /&gt;
*find_due_dates&lt;br /&gt;
*find_reveiw_period&lt;br /&gt;
*link_for_current_stage&lt;br /&gt;
*metareview_allowed&lt;br /&gt;
*num_review_rounds&lt;br /&gt;
*num_of_current_round&lt;br /&gt;
*submission_allowed&lt;br /&gt;
*user_on_team?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Methods to be removed : &amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*microtask?&lt;br /&gt;
*min_metareview&lt;br /&gt;
*questionnaire_ids&lt;br /&gt;
*remove_empty_teams&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
We plan to use the given test skeletons for assignment model and implement the respective Rspec test cases. The test cases for other methods will be included later as reimplementation might have methods which are combined versions of multiple other methods. The test scenarios for some for the methods are mentioned in the following table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left:30px&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Sr No !! Test Description &lt;br /&gt;
|-&lt;br /&gt;
| 1 || &amp;lt;strong&amp;gt;team_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || Scenario 1: Max_team_size is greater than 0. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 1.2 || Scenario 2: Max_team_size is equal to 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 1.3 || Scenario 3: Max_team_size is less than 0. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2 || &amp;lt;strong&amp;gt;topics&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2.1 || Scenario 1: Sign_up_topics is empty. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 2.2 || Scenario 2: Sign_up_topics is not empty. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3 || &amp;lt;strong&amp;gt;calibrated?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3.1 || Scenario 1: The object is calibrated. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 3.2 || Scenario 2: The object is not calibrated. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 4 || &amp;lt;strong&amp;gt;teams&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.1 || Scenario 1: Teams are present. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 4.2 || Scenario 2: Teams are not present. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 5 || &amp;lt;strong&amp;gt;valid_num_review&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5.1 || Scenario 1: Number of reviews required is greater than the number of reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 5.2 || Scenario 2: Number of meta-reviews required is greater than the number of meta-reviews allowed. Expected: Error message&lt;br /&gt;
|-&lt;br /&gt;
| 6 || &amp;lt;strong&amp;gt;dynamic_reviewer_assignment?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6.1 || Scenario 1: Review assignment strategy is RS_AUTO_SELECTED. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 6.2 || Scenario 2: Review assignment strategy is not RS_AUTO_SELECTED. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7 || &amp;lt;strong&amp;gt;badge?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7.1 || Scenario 1: Has_badge is nil. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 7.2 || Scenario 2: Has_badge is true. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 7.3 || Scenario 3: Has_badge is false. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 8 || &amp;lt;strong&amp;gt;create_node&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8.1 || Scenario 1: Parent node exists. Expected: New node created with parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 8.2 || Scenario 2: Parent node does not exist. Expected: New node created with no parent_id set.&lt;br /&gt;
|-&lt;br /&gt;
| 9 || &amp;lt;strong&amp;gt;varying_rubrics_by_round?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9.1 || Scenario 1: Rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.2 || Scenario 2: Multiple rubrics of a given type exist in round 2. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 9.3 || Scenario 3: No rubrics of a given type exist in round 2. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 10 || &amp;lt;strong&amp;gt;num_review_rounds&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10.1 || Scenario 1: No due dates. Expected: 0&lt;br /&gt;
|-&lt;br /&gt;
| 10.2 || Scenario 2: Single due date with round 1. Expected: 1&lt;br /&gt;
|-&lt;br /&gt;
| 10.3 || Scenario 3: Multiple due dates with different rounds. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 10.4 || Scenario 4: Multiple due dates with the same round number. Expected: Highest round number&lt;br /&gt;
|-&lt;br /&gt;
| 11 || &amp;lt;strong&amp;gt;review_questionnaire_id&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11.1 || Scenario 1: No round_number and topic_id provided. Expected: id of the current round's review questionnaire.&lt;br /&gt;
|-&lt;br /&gt;
| 11.2 || Scenario 2: No round_number and topic_id provided, no next due date. Expected: nil&lt;br /&gt;
|-&lt;br /&gt;
| 12 || &amp;lt;strong&amp;gt;pair_programming_enabled?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 12.1 || Scenario 1: Pair programming is enabled. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 12.2 || Scenario 2: Pair programming is disabled. Expected: false&lt;br /&gt;
|-&lt;br /&gt;
| 13 || &amp;lt;strong&amp;gt;staggered_and_no_topic?&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 13.1 || Scenario 1: Staggered deadline is enabled, topic_id not provided. Expected: true&lt;br /&gt;
|-&lt;br /&gt;
| 13.2 || Scenario 2: Staggered deadline is enabled, topic_id provided. Expected: false&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
=====Mentors===== &lt;br /&gt;
*Dinesh Pasupuleti&lt;br /&gt;
*Ankur Banerji&lt;br /&gt;
&lt;br /&gt;
=====Members=====&lt;br /&gt;
*Ajith Kanumuri &amp;lt;skanumu2@ncsu.edu&amp;gt;&lt;br /&gt;
*Suhas Adidela &amp;lt;sadidel@ncsu.edu&amp;gt;&lt;br /&gt;
*Ravi Chandu Bollepalli &amp;lt;rbollep@ncsu.edu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
*[https://github.com/expertiza/reimplementation-back-end/pull/125]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[https://docs.google.com/document/d/1LHVacylQmB15I6VcYUA5nuC7GRRU9szHzZhjlPcE-PA/edit#heading=h.10bl58em5q36 Project Instructions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158570</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158570"/>
		<updated>2024-10-30T04:09:47Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.jpg |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158569</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158569"/>
		<updated>2024-10-30T04:06:55Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Team Members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8:3002/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.png |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Project_topic.jpg&amp;diff=158567</id>
		<title>File:Project topic.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Project_topic.jpg&amp;diff=158567"/>
		<updated>2024-10-30T04:05:38Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158566</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158566"/>
		<updated>2024-10-30T04:05:22Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Team Members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
* Deployment Link:- http://152.7.177.8/api-docs&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.png |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158565</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158565"/>
		<updated>2024-10-30T04:05:09Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:Project_topic.png |1000px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158561</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158561"/>
		<updated>2024-10-30T04:02:36Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Set Up Initial Data: Create necessary records (Role, Instructor, Assignment, ProjectTopic, and Team) to establish relationships and dependencies required for testing ProjectTopic.&lt;br /&gt;
&lt;br /&gt;
*Verify Slot Availability with No Teams Signed Up: Test slot_available? to ensure it returns true when no teams have chosen the topic, confirming that the method correctly identifies open slots.&lt;br /&gt;
&lt;br /&gt;
*Test Topic Assignment Without Waitlisting: Use assign_topic_to_team to assign a topic to a team directly (without waitlisting) and check that is_waitlisted is set to false and the topic ID is correctly assigned.&lt;br /&gt;
&lt;br /&gt;
*Simulate Slot Availability with Waitlist Clearance: Test sign_up_team when slots are available, mock drop_off_team_waitlists, and verify that the new team is assigned to the topic and the waitlist is cleared.&lt;br /&gt;
&lt;br /&gt;
*Assert Expected Outcomes for Each Scenario: Validate results of each test by checking specific conditions, such as correct topic ID assignment, is_waitlisted status, and expected method calls, ensuring all methods perform accurately across various conditions.&lt;br /&gt;
* Test Cases for project_topic.rb model&lt;br /&gt;
[[File:WhatsApp Image 2024-10-29 at 23.56.25_6b9058ad.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:WhatsApp_Image_2024-10-29_at_23.56.25_6b9058ad.jpg&amp;diff=158554</id>
		<title>File:WhatsApp Image 2024-10-29 at 23.56.25 6b9058ad.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:WhatsApp_Image_2024-10-29_at_23.56.25_6b9058ad.jpg&amp;diff=158554"/>
		<updated>2024-10-30T03:59:07Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158547</id>
		<title>CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158547"/>
		<updated>2024-10-30T03:55:54Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158546</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158546"/>
		<updated>2024-10-30T03:55:54Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Fall 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Upgrade RSpec test cases for `signed_up_team.rb` to validate `delete_signed_up_team` and `get_team_participants` methods.&lt;br /&gt;
* Enhance and expand RSpec test cases for `project_topic.rb` to validate participant retrieval, slot availability, and assignment status handling.&lt;br /&gt;
* Develop RSpec test cases for `waitlist.rb` to validate adding teams to the waitlist, removing teams from the waitlist, and querying the waitlist status of a team.&lt;br /&gt;
* Add general RSpec test cases for error handling and ensure correct JSON serialization of data..&lt;br /&gt;
* Test Cases for signed_up_team.rb model&lt;br /&gt;
[[File:Signedup_team_rspec.png|900px]]&lt;br /&gt;
* Test Cases for waitlist.rb model&lt;br /&gt;
[[File:Waitlist_rspec.png|900px]]&lt;br /&gt;
* Test Cases for signup_topic.rb&lt;br /&gt;
[[File:Signup_topic_rspec.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:CSC/ECE_517_Spring_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158286</id>
		<title>User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:CSC/ECE_517_Spring_2024_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158286"/>
		<updated>2024-10-30T02:41:01Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158285</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158285"/>
		<updated>2024-10-30T02:41:01Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb to CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Upgrade RSpec test cases for `signed_up_team.rb` to validate `delete_signed_up_team` and `get_team_participants` methods.&lt;br /&gt;
* Enhance and expand RSpec test cases for `project_topic.rb` to validate participant retrieval, slot availability, and assignment status handling.&lt;br /&gt;
* Develop RSpec test cases for `waitlist.rb` to validate adding teams to the waitlist, removing teams from the waitlist, and querying the waitlist status of a team.&lt;br /&gt;
* Add general RSpec test cases for error handling and ensure correct JSON serialization of data..&lt;br /&gt;
* Test Cases for signed_up_team.rb model&lt;br /&gt;
[[File:Signedup_team_rspec.png|900px]]&lt;br /&gt;
* Test Cases for waitlist.rb model&lt;br /&gt;
[[File:Waitlist_rspec.png|900px]]&lt;br /&gt;
* Test Cases for signup_topic.rb&lt;br /&gt;
[[File:Signup_topic_rspec.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Skanumu2&amp;diff=158283</id>
		<title>User:Skanumu2</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Skanumu2&amp;diff=158283"/>
		<updated>2024-10-30T02:40:35Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page User:Skanumu2 to User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158282</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158282"/>
		<updated>2024-10-30T02:40:35Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Skanumu2 moved page User:Skanumu2 to User:CSC/ECE 517 Spring 2024 E2473. Reimplement sign up topic.rb as project topic.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Upgrade RSpec test cases for `signed_up_team.rb` to validate `delete_signed_up_team` and `get_team_participants` methods.&lt;br /&gt;
* Enhance and expand RSpec test cases for `project_topic.rb` to validate participant retrieval, slot availability, and assignment status handling.&lt;br /&gt;
* Develop RSpec test cases for `waitlist.rb` to validate adding teams to the waitlist, removing teams from the waitlist, and querying the waitlist status of a team.&lt;br /&gt;
* Add general RSpec test cases for error handling and ensure correct JSON serialization of data..&lt;br /&gt;
* Test Cases for signed_up_team.rb model&lt;br /&gt;
[[File:Signedup_team_rspec.png|900px]]&lt;br /&gt;
* Test Cases for waitlist.rb model&lt;br /&gt;
[[File:Waitlist_rspec.png|900px]]&lt;br /&gt;
* Test Cases for signup_topic.rb&lt;br /&gt;
[[File:Signup_topic_rspec.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158262</id>
		<title>CSC/ECE 517 Fall 2024 - E2473. Reimplement sign up topic.rb as project topic.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2473._Reimplement_sign_up_topic.rb_as_project_topic.rb&amp;diff=158262"/>
		<updated>2024-10-30T02:32:47Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: Created page with &amp;quot;== Team Members ==  * Ajith Kanumuri * Suhas Adidela * Ravi Chandu Bollepalli * Mentor - Dinesh Pasupuleti * PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125 * Project Board:- https://github.com/users/ajith05/projects/1/views/1  == Project Description ==    The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new rep...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Upgrade RSpec test cases for `signed_up_team.rb` to validate `delete_signed_up_team` and `get_team_participants` methods.&lt;br /&gt;
* Enhance and expand RSpec test cases for `project_topic.rb` to validate participant retrieval, slot availability, and assignment status handling.&lt;br /&gt;
* Develop RSpec test cases for `waitlist.rb` to validate adding teams to the waitlist, removing teams from the waitlist, and querying the waitlist status of a team.&lt;br /&gt;
* Add general RSpec test cases for error handling and ensure correct JSON serialization of data..&lt;br /&gt;
* Test Cases for signed_up_team.rb model&lt;br /&gt;
[[File:Signedup_team_rspec.png|900px]]&lt;br /&gt;
* Test Cases for waitlist.rb model&lt;br /&gt;
[[File:Waitlist_rspec.png|900px]]&lt;br /&gt;
* Test Cases for signup_topic.rb&lt;br /&gt;
[[File:Signup_topic_rspec.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2023_-&amp;diff=158249</id>
		<title>CSC/ECE 517 Spring 2023 -</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2023_-&amp;diff=158249"/>
		<updated>2024-10-30T02:30:14Z</updated>

		<summary type="html">&lt;p&gt;Skanumu2: /* Design Strategy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team Members ==&lt;br /&gt;
&lt;br /&gt;
* Ajith Kanumuri&lt;br /&gt;
* Suhas Adidela&lt;br /&gt;
* Ravi Chandu Bollepalli&lt;br /&gt;
* Mentor - Dinesh Pasupuleti&lt;br /&gt;
* PR Request:- https://github.com/expertiza/reimplementation-back-end/pull/125&lt;br /&gt;
* Project Board:- https://github.com/users/ajith05/projects/1/views/1&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main goal of this project is to reimplement essential Ruby on Rails model classes—SignedUpTeam and ProjectTopic (renamed from SignUpTopic)—from the Expertiza repository in a new repository. Each of these model classes plays a critical role in managing topics and team sign-ups within course assignments, and the reimplementation aims to bring them into alignment with Rails best practices and the DRY (Don't Repeat Yourself) principle.&lt;br /&gt;
&lt;br /&gt;
The SignedUpTeam model represents a team that has signed up for a specific topic within an assignment. This model manages team-specific data and oversees interactions that occur during the sign-up process. The ProjectTopic model, on the other hand, represents the topics available for sign-up within an assignment, managing essential details like slot availability and assigning teams to open topics.&lt;br /&gt;
&lt;br /&gt;
Since this project is being implemented from scratch, a range of components have been developed to ensure the functionality is both streamlined and maintainable. To guarantee the reliability of each part of the reimplementation, unit test cases have been created to verify the integrity of the new design and implementation.&lt;br /&gt;
&lt;br /&gt;
== Issue Description ==&lt;br /&gt;
&lt;br /&gt;
* Comprehensive RSpec tests are essential for all reimplemented models to ensure correctness and reliability in functionality.&lt;br /&gt;
&lt;br /&gt;
* Update all references from `sign_up_topics` to `project_topics` throughout the codebase to maintain consistency with the new naming convention.&lt;br /&gt;
&lt;br /&gt;
* Address all code review feedback to improve code quality and alignment with best practices.&lt;br /&gt;
&lt;br /&gt;
* Refactor methods with readability issues to make the code more maintainable and easier to understand.&lt;br /&gt;
&lt;br /&gt;
* Optimize ambiguous class and instance methods to enhance reusability and improve the overall structure of the code.&lt;br /&gt;
&lt;br /&gt;
* The old codebase has several instances of unnecessary calls to database, such as fetching all project topics for a user when fetching first topic would be sufficient. This effects efficiency and readability. Optimize such instances of code to streamline and increase readability.&lt;br /&gt;
&lt;br /&gt;
== Design Strategy ==&lt;br /&gt;
&lt;br /&gt;
* Implemented three model classes: `sign_up_team.rb` and `project_topic.rb` to address project requirements.&lt;br /&gt;
* Each model now has a focused role, improving maintainability and clarity.&lt;br /&gt;
* In signed_up_team.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| drop_off_team_waitlists || Implemented || Removes the team from all waitlists for topics within the assignment.&lt;br /&gt;
|-&lt;br /&gt;
| find_first_existing_sign_up || Implemented || Finds the first existing sign-up entry for a given topic and team, checking for both active and waitlisted sign-ups.&lt;br /&gt;
|-&lt;br /&gt;
| create_signed_up_team || Implemented || Creates a SignedUpTeam instance with specified topic_id and team_id if the topic is available for sign-up.&lt;br /&gt;
|-&lt;br /&gt;
| get_team_id || Implemented || Retrieves the team ID associated with a given SignedUpTeam entry.&lt;br /&gt;
|-&lt;br /&gt;
| delete_signed_up_team || Implemented || Deletes the signed-up team entry for a specific topic, managing any dependent records as necessary.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
* Add necessary schema migrations to rename signup topic to project topic. &lt;br /&gt;
* In project_topic.rb, the following functionality are being implemented:-&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;
! Method Name !! Status !! Description&lt;br /&gt;
|-&lt;br /&gt;
| slot_available? || Implemented || Checks if there are available slots for the topic based on the maximum allowed choosers. Returns true if available.&lt;br /&gt;
|-&lt;br /&gt;
| assign_topic_to_team || Implemented || Assigns the topic to a team by updating the sign-up entry to set is_waitlisted as false and assign the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| save_waitlist_entry || Implemented || Saves a sign-up entry as a waitlist entry by setting is_waitlisted to true and assigning the topic_id.&lt;br /&gt;
|-&lt;br /&gt;
| sign_up_team || Implemented || Manages the sign-up process for a team, checking slot availability, assigning the topic, or placing the team on the waitlist as needed&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== E/R Diagram ==&lt;br /&gt;
[[File:oodd.png |500px|center]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;Edit Button Tooltip&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Upgrade RSpec test cases for `signed_up_team.rb` to validate `delete_signed_up_team` and `get_team_participants` methods.&lt;br /&gt;
* Enhance and expand RSpec test cases for `project_topic.rb` to validate participant retrieval, slot availability, and assignment status handling.&lt;br /&gt;
* Develop RSpec test cases for `waitlist.rb` to validate adding teams to the waitlist, removing teams from the waitlist, and querying the waitlist status of a team.&lt;br /&gt;
* Add general RSpec test cases for error handling and ensure correct JSON serialization of data..&lt;br /&gt;
* Test Cases for signed_up_team.rb model&lt;br /&gt;
[[File:Signedup_team_rspec.png|900px]]&lt;br /&gt;
* Test Cases for waitlist.rb model&lt;br /&gt;
[[File:Waitlist_rspec.png|900px]]&lt;br /&gt;
* Test Cases for signup_topic.rb&lt;br /&gt;
[[File:Signup_topic_rspec.png|900px]]&lt;/div&gt;</summary>
		<author><name>Skanumu2</name></author>
	</entry>
</feed>