CSC/ECE 517 Fall 2023 - E2375. Refactor classes relating to signing up for topics

From Expertiza_Wiki
Revision as of 02:50, 16 November 2023 by Dpasupu (talk | contribs)
Jump to navigation Jump to search

Introduction

When managing sign-ups within expertiza, the evolution of functionality often leads to a need for refactoring existing code. In this case, several classes—sign_up_sheet.rb, sign_up_topic.rb, and signed_up_team.rb—require restructuring to streamline their functionalities and ensure they align with the current project landscape. This refactoring endeavor aims to declutter, reorganize, and enhance code readability and maintainability by removing redundant functionalities and repositioning methods in classes where they serve their intended purposes more explicitly. The end goal is a more coherent and efficient codebase that reflects the current needs of the project while laying the groundwork for future enhancements.

Methods to be refactored

File: sign_up_sheet.rb

(1) Method: self.signup_team

Code:

 def self.signup_team(assignment_id, user_id, topic_id = nil)
    users_team = SignedUpTeam.find_team_users(assignment_id, user_id)
    if users_team.empty?
      # if team is not yet created, create new team.
      # create Team and TeamNode
      team = AssignmentTeam.create_team_with_users(assignment_id, [user_id])
      # create SignedUpTeam
      confirmationStatus = SignUpSheet.confirmTopic(user_id, team.id, topic_id, assignment_id) if topic_id
    else
      confirmationStatus = SignUpSheet.confirmTopic(user_id, users_team[0].t_id, topic_id, assignment_id) if topic_id
    end
    ExpertizaLogger.info "The signup topic save status:#{confirmationStatus} for assignment #{assignment_id} by #{user_id}"
    confirmationStatus
  end

Code smells:

  • Conditional Complexity: There's conditional complexity within the method based on whether users_team is empty or not, leading to slightly repetitive code.
  • Lack of Clear Separation of Concerns: The method handles team creation, sign-up confirmation, and logging within the same block, which might violate the single responsibility principle.
  • Magic Numbers/Variables: users_team[0].t_id uses index 0 directly, assuming there's always at least one entry in users_team.
  • Change method name to Signup_sheet.

What to improve

  • Error Handling: Add error handling for potential failures during team creation or sign-up processes.

Team

Mentor
  • Ed Gehringer
Members
  • Dinesh Pasupuleti <dpasupu@ncsu.edu>
  • Prateek Singamsetty <pksingam@ncsu.edu>
  • Rushabh Shah <rshah32@ncsu.edu>