Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor record controller (backend) #76

Merged
merged 3 commits into from
Oct 5, 2024

Conversation

tyin363
Copy link
Contributor

@tyin363 tyin363 commented Oct 5, 2024

Context

This change is being made to improve the maintainability of the Record Controller in the backend. The existing implementation had a significant amount of duplicate code for handling different screen types and updating overall scores, which made it difficult to maintain and extend in the future. By refactoring, we aim to enhance readability, reduce the likelihood of bugs, and simplify modifications going forward.

Closes #75

What Changed?

  • Introduced helper functions:

    • getRecordsByScreen: Centralizes logic for fetching records based on the screen type.
    • getTopScoresByScreen: Centralizes logic for retrieving top scores based on the screen type.
    • updateOverallScore: Centralizes logic for updating overall scores based on the latest records.
  • Replaced repetitive conditional logic with switch statements for improved readability.

  • Streamlined logic for checking existing records and creating them if they do not exist.

  • Ensured consistent error handling and response structure across all controller functions.

How To Review

  1. Review the changes in the Record Controller to understand the new helper functions and how they reduce duplication.
  2. Examine the implementation of switch statements and verify that they handle all screen types correctly.
  3. Check the updated error handling to ensure it aligns with the existing API structure.
  4. Review the overall code for readability and maintainability improvements.

Testing

  • All existing unit tests were run to ensure no functionality was broken during the refactoring process.
  • Added additional tests for the new helper functions to cover edge cases and ensure accuracy in fetching and updating records.

Risks

  • Reviewers should focus on the potential for existing functionality to be impacted, particularly the correct handling of scores and record retrieval across different screen types.
  • Ensure that tests cover all relevant scenarios, especially when integrating with other parts of the application.

Notes

  • This refactor was aimed at making the codebase easier to work with, and future changes should be more straightforward as a result.
  • If any issues arise post-merge, they can be tracked and addressed more efficiently due to the improved structure.

Copy link
Contributor

@today0-o today0-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have cloned and checked the new features and refactoring of the recordcontroller.js, it everything seems to work well with the changes! This is a good addition to our codebase as it shows a great practice of clean code and managable code. LGTM to merge! Thanks for the work.

@today0-o today0-o merged commit 3996829 into SOFTENG310-G5:main Oct 5, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] Improve Maintainability of Record Controller (Backend)
2 participants