CSC/ECE 517 Spring 2025 - E2531 Refactor participants controller.rb
Introduction
From the project description: "This project aims to refactor the participants_controller.rb and its helper class, participants_helper.rb, in the Expertiza system. The focus will be on improving code structure by implementing DRY and SOLID principles, enhancing readability with meaningful comments and clear naming conventions, and ensuring robustness through comprehensive RSpec testing." Since this is a refactoring project, we will also be utilizing Large Language Models (LLMs) to aid in development. More information on how we used them can be found in the section below.
Use of Large Language Models (LLMs)
Requirements
Objectives:
- Apply DRY principles to eliminate redundant code.
- Ensure adherence to SOLID principles for better maintainability.
- Use appropriate design patterns to optimize code architecture.
- Write clear, informative comments and use meaningful naming conventions.
- Test the refactored code extensively with RSpec to verify functionality.
Deliverables:
- Refactored code for participants_controller.rb and helper class.
- Comprehensive test suite and coverage report.
- Updated and detailed documentation.
- Video demonstration of the API functionality.
Existing Issues
- There are some API functions that are currently not functioning properly, making it somewhat difficult to test
- In-code comments should be more descriptive
- Eliminate instances of redundant code
- The method naming should be more descriptive
Design / Proposed Solution (TEMP)
Simplifying Redundant JSON Rendering Code
Many of the functions in the current implementation contain a conditional if-else statement that determines what HTML status code is returned alongside any necessary values that are requested. Due to its simple nature, it might be possible to reduce the amount of space this takes up by implementing a private helper method that would shorten the process.
Example:
if participants.nil?
render json: participants.errors, status: :unprocessable_entity
else
render json: participants, status: :ok
end
Simplifying the Assignment of Participant Fields
In the add() and update both take up a significant amount of space to assign values to database fields and are essentially the same in functionality (in terms of this specific section. We can remove redundancy by creating a method that can remove this redundancy.
Example
permissions = retrieve_participant_permissions(authorization) participant.authorization = authorization participant.can_submit = permissions[:can_submit] participant.can_review = permissions[:can_review] participant.can_take_quiz = permissions[:can_take_quiz] participant.can_mentor = permissions[:can_mentor]
Provide More Clarity in Function Names
There are some functions that are somewhat unclear/vague in participants_controller.rb. For example, the list_user_participants() and list_assignment_participants().
Improve Documentation and Comments
Implementation (TEMP)
Testing Plan (TEMP)
From the previous implementation, there are 24 tests that are all passing.
Tests
| Test ID | Test Description |
|---|---|
| 1 | (TEMP) |
Next Steps (TEMP)
Key concerns identified include the overlap and redundancy within the current system:
Team
Mentor
- Aniruddha Rajnekar <aarajnek@ncsu.edu>
Students
- Akhil Adusumilli <aadusum@ncsu.edu>
- Vansh Dodiya <vkdodiya@ncsu.edu>
- Brian Huynh <bhhuynh@ncsu.edu>
Relevant Links
Pull Request (Unimplemented) []
GitHub Repository [1]
GitHub Project Board [2]
participants_controller.rb in Old Expertiza [3]
participants_helper.rb in Old Expertiza [4]