rcereno / REDX

0 stars 0 forks source link

Code Review Comments (Tarj Mecwan) #10

Open TarjMecwan opened 1 month ago

TarjMecwan commented 1 month ago

Code Review Comments (Tarj Mecwan)


Description:

  1. Add more commenting within your code to make it more readable.

    • As I was reviewing your code, I noticed a lack of comments explaining the purpose and logic of each function. This can make it difficult for others (and even yourself in the future!) to understand what's happening. I suggest adding more inline comments, especially in complex code blocks. For instance, in the cart_view function in carts.py, you could add comments to explain how the game results are fetched and processed. This will not only help organize the logic but also make it clear what each part of the code does.
  2. Add docstrings to the endpoint functions in which they do not already exist.

    • It seems that many endpoint functions lack docstrings, which makes it challenging to understand their purpose and usage. To address this, I suggest adding docstrings to all endpoint functions. These docstrings should describe the functionality of the function, its input parameters, and return values. Additionally, including request and response specifications will enhance clarity and ensure that everyone knows what each endpoint does.
  3. Clean up the Catalog Search function to simplify the SQL query construction.

    • In catalog.py, I noticed that there are multiple if/elif statements used for the order_by logic, which can clutter the code and make it harder to understand. To improve this, I recommend simplifying the construction of the SQL query by directly using the selected sort column. By doing so, you can make the code cleaner and easier to follow, enhancing its readability and maintainability.
  4. Remove or implement the inventory/audit endpoint.

    • In inventory.py, I noticed that the audit endpoint is not functional. To address this, you have two options. You can either fully implement the inventory audit functionality to make the endpoint functional, or you can remove the placeholder endpoint altogether. By taking either of these actions, we can eliminate unnecessary code and potential confusion within the project.
  5. Combine SQL queries in the Cart View function to improve efficiency.

    • In carts.py, I noticed that there are separate queries for fetching games and account information. To streamline the code and improve efficiency, I suggest using a single SQL query with multiple joins to fetch all necessary information at once. This approach reduces the number of database calls and simplifies the code, making it more efficient and easier to maintain.
  6. Add more try/except statements to handle potential errors gracefully.

    • Across all files, I noticed inconsistent error handling in different endpoint functions. To enhance the reliability and debuggability of the code, I recommend including try/except blocks to handle potential exceptions consistently. You can follow the implementation in set_item_quantity() as a model. Consistent error handling ensures that your code behaves predictably in various scenarios and facilitates easier troubleshooting. For example, in the set_item_quantity() function within carts.py, you'll find a good illustration of how try/except blocks are used to manage exceptions effectively.
  7. Combine SELECT and INSERT queries in the Set Item Quantity function.

    • In carts.py, I noticed that separate SELECT and INSERT queries are being used, which could be impacting the efficiency of the logic. To improve this, I suggest using a single query to insert based on the SELECT result. This approach will streamline the SQL logic and enhance efficiency. Additionally, consider reassessing the necessity of the UPDATE query for maintaining data integrity. Streamlining the database operations in this manner can lead to better performance and cleaner code.
  8. Refactor the Cart Checkout function to combine SQL operations and remove redundant code.

    • In carts.py, I observed that there are multiple separate SQL queries and commented-out code segments, which are cluttering the function. To enhance the readability and maintainability of the code, I recommend combining the select and insert operations for games_bought and purchased into a single query. Additionally, removing commented-out and redundant code will further streamline the codebase, making it easier to understand and maintain. By decluttering the function, you can improve code quality and facilitate future modifications.
  9. Ensure the logic for fetching account_id in Cart Checkout is consistent.

    • In carts.py, there's an issue where using ORDER BY when fetching a single account_id is redundant. Since cart_id should be unique, ordering the result is unnecessary. To improve performance and simplify the query, I recommend refactoring it to fetch the account_id without ordering. This optimization will enhance query efficiency and streamline the codebase, leading to better overall performance.
  10. Retrieve games_in_cart and total_cost directly from the cart_items table in Cart Checkout.

    • In carts.py, the issue lies in storing certain values redundantly in the carts table. To streamline the checkout process and eliminate unnecessary redundancy, I suggest fetching the required values directly from the cart_items table during checkout. This approach will not only remove redundant data storage but also streamline the checkout process, making the code more efficient and easier to maintain.
  11. Remove redundant and commented-out code.

    • Across all files, there's a notable presence of commented-out code and redundant queries. To enhance the cleanliness and efficiency of the codebase, I recommend reviewing and removing any commented-out lines of code that are no longer needed. Additionally, ensure that SQL queries are optimized by eliminating unnecessary ORDER BY clauses or other redundancies. This practice will not only improve code readability but also streamline performance and maintainability.