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

added hints to get complete guides by url #431

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

erenfn
Copy link
Collaborator

@erenfn erenfn commented Dec 25, 2024

  • Added Url field to Hints
  • Added Hints to "/get_guides_by_url" and "/get_incomplete_guides_by_url"

@erenfn erenfn requested a review from swoopertr December 25, 2024 13:45
Copy link
Contributor

coderabbitai bot commented Dec 25, 2024

Walkthrough

This pull request introduces enhancements to the hint management system across the backend and frontend. The changes primarily focus on integrating URL-based hint functionality, expanding the Hint model to include a URL property, and updating controllers, services, and components to support this new feature. The modifications enable more flexible hint retrieval and storage, with improvements in both data management and user interface interactions.

Changes

File Change Summary
backend/src/models/Hint.js Added url property to Hint model
backend/src/controllers/guide.controller.js Updated methods to incorporate hint service data
backend/src/routes/hint.routes.js Activated route for retrieving hints by URL
backend/src/server.js Changed database sync method to alter: true
backend/src/service/hint.service.js Added getIncompleteHintsByUrl method
backend/src/service/guidelog.service.js Added getCompleteHintLogs method
frontend/src/scenes/hints/CreateHintPage.jsx Added url state management
frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx Updated component to handle URL input
backend/src/test/mocks/hint.mock.js Added url property to hint object in HintBuilder
backend/src/test/e2e/hint.test.mjs Updated response structure for GET /api/hint/all_hints to include url

Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant HintController
    participant HintService
    participant Database

    User->>Frontend: Request Hint Data
    Frontend->>HintController: Get Hints by URL
    HintController->>HintService: Retrieve Hints
    HintService->>Database: Query Hints
    Database-->>HintService: Return Hint Data
    HintService-->>HintController: Process Hints
    HintController-->>Frontend: Return Hint Response
    Frontend->>User: Display Hints
Loading

Possibly Related PRs

  • Feat/130 implementing hints endpoints #270: Implements endpoints for the hint page, which directly relates to the changes made in the main PR that enhance the GuideController by integrating hint-related data and modifying the response structure to include hints.
  • PR for Issue#332 #394: Although primarily focused on removing the apiKey, this PR also touches on hint-related functionality, which may have indirect relevance to the changes in hint handling in the main PR.
  • Hint preview fix #417: This PR addresses the hint preview functionality, which is closely related to the overall hint management and presentation changes made in the main PR.

Suggested Reviewers

  • SimerdeepSinghGrewal
  • uparkalau
  • gorkem-bwl

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1681c54 and 8336d0a.

📒 Files selected for processing (1)
  • backend/src/test/e2e/hint.test.mjs (1 hunks)
🔇 Additional comments (1)
backend/src/test/e2e/hint.test.mjs (1)

505-505: Rock-solid test coverage, buddy!

Your newly introduced "url" parameter is validated properly in the response, ensuring no mess—mom’s spaghetti is still intact. Keep shining bright, my friend.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (6)
backend/src/server.js (1)

47-47: Stay calm and deliberate, alter: true can be tricky on a production database.

Using alter: true dynamically adjusts table schemas, but it can lead to unintended consequences if the schema changes in unexpected ways. Ensure that this approach aligns with your migration strategy or consider using more explicit migrations to keep your database schema stable and well-documented.

[Nitpick]

frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (1)

30-37: You’re spinning bars with your new URL input—looks good in the final mix.

The new label and CustomTextField for the url property align well with the rest of the UI. Consider adding optional validation or user feedback if you need to ensure correct URL formats. Otherwise, everything flows smoothly.

backend/src/service/guidelog.service.js (1)

54-66: Your lines are punchy like the best in the game—this new method is close to flame.

getCompleteHintLogs is well-structured and consistent with your other retrieval methods. For potential performance boosts, you might add indexing on userId if you expect a large volume of logs, ensuring queries remain efficient in scale.

backend/src/models/Hint.js (1)

19-23: Add Some “Wow Factor” to the New url Field
Yo, yo, we’re adding a new property to store the URL. Overall, this is solid because it opens up more flexible retrieval options. Just ensure no indexing or max-length constraints are needed to handle extremely long URLs.

frontend/src/scenes/hints/CreateHintPage.jsx (2)

32-33: Seamless URL Handling
So, you set the default URL to "https://". That’s lovely, mom’s spaghetti. Just confirm if your app expects that as a placeholder or if you’d prefer an empty string to indicate no URL set.


91-91: Focus on the Data
Including url in the payload is dope, but be mindful: if the API grows, you may need partial updates. Right now, sending the entire object is okay, but a patch approach might be more scalable.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 370bf11 and c7b7711.

📒 Files selected for processing (8)
  • backend/src/controllers/guide.controller.js (3 hunks)
  • backend/src/models/Hint.js (1 hunks)
  • backend/src/routes/hint.routes.js (1 hunks)
  • backend/src/server.js (1 hunks)
  • backend/src/service/guidelog.service.js (1 hunks)
  • backend/src/service/hint.service.js (1 hunks)
  • frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (2 hunks)
  • frontend/src/scenes/hints/CreateHintPage.jsx (3 hunks)
🔇 Additional comments (7)
backend/src/routes/hint.routes.js (1)

16-16: You might want to keep your knees steady, check user access like mom’s spaghetti.

The new GET route is missing authentication in a secure environment. If users should retrieve hints without logging in, that’s fine, but you might want to confirm that it fits the intended use case and doesn’t inadvertently open the door to unauthorized data access.

frontend/src/components/HintPageComponents/HintLeftContent/HintLeftContent.jsx (2)

6-6: Props are piling up but we’re still on top—clean structure, no flop.

The inclusion of setUrl and url is consistent with the existing pattern for other props. Everything reads nicely and remains straightforward to maintain.


13-15: Handle the craft by controlling the draft—your state management looks tight.

Excellent approach to updating the URL state with handleUrl. This method helps keep the component’s internal logic consistent and ensures the new url field is properly tracked.

backend/src/controllers/guide.controller.js (2)

5-6: Import Check
We can see a new import for hintService. Looks good. Ensure it’s recognized properly in the service registry to prevent missing injection or undefined references.


16-22: Harmonize the Response
The promise-all usage is neat, dawg. Just double-check if you need to handle possible null returns for banners or popups. For instance, if bannerService.getBannerByUrl(url) returns null, the final response might not match the front-end’s expectations.

frontend/src/scenes/hints/CreateHintPage.jsx (1)

77-77: Ensure We’ve Got a Real URL
When editing, you set the URL from the fetched hint data if available, or fallback to "https://". Maybe consider a quick format check or a prompt to the user if the passed URL is empty or remains the default placeholder.

backend/src/service/hint.service.js (1)

80-81: Service Expansion
The new method getIncompleteHintsByUrl aligns with your logic to skip hints that have IDs in the complete logs. Good call. The method name is coherent with the rest of the code.

Comment on lines +42 to +60
const [completePopupLogs, completeBannerLogs, completeHintLogs, completeHelperLogs] = await Promise.all([
guidelogService.getCompletePopupLogs(userId),
guidelogService.getCompleteBannerLogs(userId),
guidelogService.getCompleteHintLogs(userId),
guidelogService.getCompleteHelperLogs(userId),
]);

const popupIds = completePopupLogs.map(log => log.guideId);
const bannerIds = completeBannerLogs.map(log => log.guideId);
const hintIds = completeHintLogs.map(log => log.guideId);
const helperLinkIds = completeHelperLogs.map(log => log.guideId);

const [banner, popup, helperLink] = await Promise.all([
bannerService.getIncompleteBannersByUrl(url, bannerIds),
const [popup, banner, hint, helperLink] = await Promise.all([
popupService.getIncompletePopupsByUrl(url, popupIds),
bannerService.getIncompleteBannersByUrl(url, bannerIds),
hintService.getIncompletePopupsByUrl(url, hintIds),
helperLinkService.getIncompleteHelpers(helperLinkIds),
]);
res.status(200).json({ banner, popup, helperLink });
res.status(200).json({popup, banner, hint, helperLink });
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mistake in Incomplete Hints
The function call is referencing guidelogService.getCompleteHintLogs(userId), but at line 57 we call hintService.getIncompletePopupsByUrl(url, hintIds). Doesn’t appear consistent with the naming, since we specifically want “incomplete hints” but the function is “getIncompletePopupsByUrl.” Double-check that or rename it for clarity to avoid a spaghetti meltdown.

- hintService.getIncompletePopupsByUrl(url, hintIds),
+ hintService.getIncompleteHintsByUrl(url, hintIds),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [completePopupLogs, completeBannerLogs, completeHintLogs, completeHelperLogs] = await Promise.all([
guidelogService.getCompletePopupLogs(userId),
guidelogService.getCompleteBannerLogs(userId),
guidelogService.getCompleteHintLogs(userId),
guidelogService.getCompleteHelperLogs(userId),
]);
const popupIds = completePopupLogs.map(log => log.guideId);
const bannerIds = completeBannerLogs.map(log => log.guideId);
const hintIds = completeHintLogs.map(log => log.guideId);
const helperLinkIds = completeHelperLogs.map(log => log.guideId);
const [banner, popup, helperLink] = await Promise.all([
bannerService.getIncompleteBannersByUrl(url, bannerIds),
const [popup, banner, hint, helperLink] = await Promise.all([
popupService.getIncompletePopupsByUrl(url, popupIds),
bannerService.getIncompleteBannersByUrl(url, bannerIds),
hintService.getIncompletePopupsByUrl(url, hintIds),
helperLinkService.getIncompleteHelpers(helperLinkIds),
]);
res.status(200).json({ banner, popup, helperLink });
res.status(200).json({popup, banner, hint, helperLink });
const [completePopupLogs, completeBannerLogs, completeHintLogs, completeHelperLogs] = await Promise.all([
guidelogService.getCompletePopupLogs(userId),
guidelogService.getCompleteBannerLogs(userId),
guidelogService.getCompleteHintLogs(userId),
guidelogService.getCompleteHelperLogs(userId),
]);
const popupIds = completePopupLogs.map(log => log.guideId);
const bannerIds = completeBannerLogs.map(log => log.guideId);
const hintIds = completeHintLogs.map(log => log.guideId);
const helperLinkIds = completeHelperLogs.map(log => log.guideId);
const [popup, banner, hint, helperLink] = await Promise.all([
popupService.getIncompletePopupsByUrl(url, popupIds),
bannerService.getIncompleteBannersByUrl(url, bannerIds),
hintService.getIncompleteHintsByUrl(url, hintIds),
helperLinkService.getIncompleteHelpers(helperLinkIds),
]);
res.status(200).json({popup, banner, hint, helperLink });

Comment on lines +81 to +92
async getIncompleteHintsByUrl(url, ids) {
try {
return await Hint.findAll({
where: {
url,
id: { [Op.notIn]: ids }
}
});
} catch (error) {
throw new Error("Error retrieving hint by URL");
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Strengthen Error Handling
We’re just throwing a generic “Error retrieving hint by URL.” Might be nice to pass the underlying error.message to the thrown Error, like you do in other methods, for better debugging.

catch (error) {
-  throw new Error("Error retrieving hint by URL");
+  throw new Error("Error retrieving hint by URL: " + error.message);
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async getIncompleteHintsByUrl(url, ids) {
try {
return await Hint.findAll({
where: {
url,
id: { [Op.notIn]: ids }
}
});
} catch (error) {
throw new Error("Error retrieving hint by URL");
}
};
async getIncompleteHintsByUrl(url, ids) {
try {
return await Hint.findAll({
where: {
url,
id: { [Op.notIn]: ids }
}
});
} catch (error) {
throw new Error("Error retrieving hint by URL: " + error.message);
}
};

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
backend/src/test/mocks/hint.mock.js (1)

12-12: Great addition of the url property!
Including an empty string as a default is an acceptable approach; however, consider verifying whether or not the URL must always remain optional or if it should hold a valid link. Incorporating a quick validation or test case for the URL property will help ensure data integrity and catch potential user errors.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7b7711 and 1681c54.

📒 Files selected for processing (2)
  • backend/src/test/mocks/hint.mock.js (1 hunks)
  • frontend/src/scenes/hints/CreateHintPage.jsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/scenes/hints/CreateHintPage.jsx

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.

1 participant