Pitsco / personal

MIT License
0 stars 0 forks source link

Debugging Session with Individual Project #7

Open Pitsco opened 5 months ago

Pitsco commented 5 months ago

Debugging Comment Section of our project:

Frontend fetch:

image

3 Key Lines highlighted (Detailed):

fetch(http://localhost:8062/api/comments/${encodeURIComponent(gameName)}`)`

Uses the fetch function to make an HTTP GET request to a specified URL. The URL includes the game name from the input, and encodeURIComponent is used to encode special characters in the URL.

.then(response => response.json())

Chain a then callback to the fetch promise. This callback converts the response to JSON format. The fetch function returns a Promise, and when the HTTP request is successful, the response is passed to this callback.

.then(data => {...})

Another then callback that processes the parsed JSON data. Inside this callback, existing comments in the 'comments' div are cleared, and new comment elements are created based on the fetched data.

However, if we were to look at it in a simplistic perspective, it would be much easier to understand. Shown in the console, we have our fantasy comments fetching data from the backend from the comments we stored.

Debugging backend:

image

As our data is stored in the backend, each comment is stored and then when "current" is typed above the "Load Comments button", it will load out all the stored comments. In the photo above, we can see that local variables are stored and each comment is numbered.

image

In this piece of code, The getCommentsByGameName method in the CommentService class is designed to retrieve and return a list of comments associated with a specific game. It takes a game name as a parameter, and internally calls a corresponding method on the commentRepository. This repository method is likely using Spring Data JPA query derivation, querying the database to fetch comments for the specified game name and ordering the results by timestamp in ascending order. The method returns a list of Comment entities, providing a convenient way to access and display comments related to a particular game in a chronological order.

image

We can see that right after we went through the debugging process, our comment of "test" loads and we are able to see that the comment section works.

Original Debugging Feature:

image

Originally, I decided to try to debug the feature that I created (tracking NBA players stats in the current 2023-2024 season). It didn't go as planned because the API changed and the backend can't pull the data from the API. Therefore, if no data is being pulled from the API, that means the data can't be pulled to the frontend. Essentially, I COULD debug it step by step but I need to add additional code because the new API requires a API key. Well, it wouldn't really work but it could still be debug.

Glows:

Grows:

Overall, learning about debugging is something that I did not expect to need. It is a strong option for me in the future and I think, especially when it comes to CORS errors, it helps me figure out why the errors even exist instead of asking ChatGPT or my mom.