Skip to content

Conversation

@Shyam-Vishwakarma
Copy link
Contributor

@Shyam-Vishwakarma Shyam-Vishwakarma commented May 8, 2025

Date: 08 May 2025

Developer Name: @Shyam-Vishwakarma


Issue Ticket Number

Description

  • Currently we can create a duplicate endorsement for a user-skill to resolve this I have done:

  • added validation to check whether an endorsement already exists or not

  • If an endorsement already exists then raise an exception (i.e. EndorsementAlreadyExistsException) otherwise proceed to create endorsement

  • added integration-tests for the route POST v1/skills/{id}/endorsements

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1 Build success:

{C0F8C611-B3EE-4053-9826-F195FD9AD721}

Screenshot 2 409 when creating duplicate endorsement

Screenshot 2025-05-12 222115

Test Coverage

Screenshot 1 - Test coverage for all tests:

{C7E4BA26-0778-41FF-A0DD-18563A9A334F}

Screenshot 2 Coverage of tests for POST /v1/skills/{skillId}/endorsements only:

{083CD89D-5A55-4352-B504-8887D1AD2371}

Additional Notes

  • Execute mvn verify --file skill-tree/pom.xml -Dskip-ut=true command to run integration tests, and mvn test --file skill-tree/pom.xml to run unit tests
  • Make sure, Docker engine is running while executing integration tests.

@coderabbitai
Copy link

coderabbitai bot commented May 8, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features
    • Added prevention of duplicate endorsements for the same user and skill. Users attempting to endorse the same person for the same skill more than once will receive a clear error message.
  • Bug Fixes
    • Improved error handling for endorsement creation, including specific responses for duplicate endorsements, self-endorsement, and non-existent skills.
  • Tests
    • Introduced comprehensive integration tests to validate endorsement creation, error scenarios, and data consistency.

Walkthrough

A custom exception for duplicate endorsements was added, along with a global handler returning HTTP 409. The endorsement service now checks for existing endorsements before creation, throwing the new exception if found. The repository gained a custom existence-check method. Comprehensive integration tests were introduced to verify correct endorsement creation and error handling.

Changes

File(s) Change Summary
.../exceptions/EndorsementAlreadyExistsException.java New custom exception class for duplicate endorsements.
.../exceptions/GlobalExceptionHandler.java Added handler for the new exception, returning HTTP 409 with error details.
.../repositories/EndorsementRepository.java Added JPQL query method to check for existing endorsement by endorsee, endorser, and skill.
.../services/EndorsementServiceImplementation.java Updated create method to check for duplicates and throw the new exception if found.
.../integration/skills/CreateEndorsementIntegrationTest.java New integration test class covering successful creation, duplicate prevention, and related error scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant EndorsementService
    participant EndorsementRepository
    participant ExceptionHandler

    Client->>Controller: POST /endorsements
    Controller->>EndorsementService: create(endorsementData)
    EndorsementService->>EndorsementRepository: existsByEndorseIdAndEndorserIdAndSkillId(...)
    alt Endorsement exists
        EndorsementService->>ExceptionHandler: throw EndorsementAlreadyExistsException
        ExceptionHandler-->>Client: HTTP 409 Conflict + error message
    else Endorsement does not exist
        EndorsementService->>EndorsementRepository: save(endorsement)
        Controller-->>Client: HTTP 201 Created + endorsement data
    end
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Prevent duplicate endorsements for a user on a skill (#197)

Suggested reviewers

  • mbramani
  • iamitprakash

Poem

A rabbit hopped by with a code in its paw,
“No more duplicates!” it cheered with awe.
Endorsements checked, exceptions thrown,
Each skill and user now stands alone.
With tests that leap and logic tight,
The skill tree grows just right!
🐇🌳


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fab2c17 and 2015b36.

📒 Files selected for processing (5)
  • skill-tree/src/main/java/com/RDS/skilltree/exceptions/EndorsementAlreadyExistsException.java (1 hunks)
  • skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java (1 hunks)
  • skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java (1 hunks)
  • skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java (2 hunks)
  • skill-tree/src/test/java/com/RDS/skilltree/integration/skills/CreateEndorsementIntegrationTest.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java (1)
skill-tree/src/main/java/com/RDS/skilltree/exceptions/EndorsementAlreadyExistsException.java (1)
  • EndorsementAlreadyExistsException (3-7)
🔇 Additional comments (6)
skill-tree/src/main/java/com/RDS/skilltree/exceptions/EndorsementAlreadyExistsException.java (1)

1-7: Well-designed exception class for handling duplicate endorsements.

The exception class follows good Java practices by extending RuntimeException and providing a constructor that accepts a message. This will integrate well with the existing exception handling system.

skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java (1)

157-163: Appropriate exception handler for EndorsementAlreadyExistsException.

The implementation correctly returns HTTP 409 Conflict status, which is the standard response for resource conflicts. The handler follows the same pattern as other exception handlers in this class, maintaining consistency.

skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java (3)

4-4: Import for new exception class.

The import for EndorsementAlreadyExistsException has been correctly added.


86-86: Improved logging with parameterized format.

Good update to use parameterized logging instead of string concatenation, which is more efficient and follows best practices.


90-98: Effective duplicate endorsement prevention.

This validation logic correctly checks for existing endorsements before attempting to create a new one. The error message and logging are clear and informative.

skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java (1)

6-7: Added necessary imports for Query annotation.

The imports for Query and Param annotations have been correctly added to support the new query method.

Copy link
Contributor

@mbramani mbramani left a comment

Choose a reason for hiding this comment

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

LGTM

@Shyam-Vishwakarma Shyam-Vishwakarma changed the title fix: avoid creating duplicate endorsements for a user on same skill fix: avoid creating duplicate endorsements for a user - skill request May 12, 2025
@MayankBansal12
Copy link
Member

@Shyam-Vishwakarma Please update the title and try and keep concerns separated from next time for bug fix and tests

@surajmaity1
Copy link

Could you please attach the integration tests for GET /v1/skills/{id}/endorsements document at the end of the description or additional note section, rather than between the "Documentation Updated" and "Under Feature Flag" sections?

@surajmaity1
Copy link

Could you please clarify why this feature is not placed under a feature flag?

@surajmaity1
Copy link

I noticed that you attached a Postman screenshot—could you please confirm whether a bearer token was included in the authorization when calling this API endpoint?

If authorization was not provided, does that mean the endpoint can be accessed without authentication?

@Shyam-Vishwakarma
Copy link
Contributor Author

Could you please attach the integration tests for GET /v1/skills/{id}/endorsements document at the end of the description or additional note section, rather than between the "Documentation Updated" and "Under Feature Flag" sections?

I removed that doc. That was not related to this route.

@Shyam-Vishwakarma
Copy link
Contributor Author

Shyam-Vishwakarma commented May 14, 2025

Could you please clarify why this feature is not placed under a feature flag?

This is a small bug fix. I've added just a check before creating an endorsement. I don't think this should be under ff.

@Shyam-Vishwakarma
Copy link
Contributor Author

I noticed that you attached a Postman screenshot—could you please confirm whether a bearer token was included in the authorization when calling this API endpoint?

If authorization was not provided, does that mean the endpoint can be accessed without authentication?

Yes, Bearer token was included. We can't access any endpoint without a bearer token.

@Shyam-Vishwakarma Shyam-Vishwakarma changed the title fix: avoid creating duplicate endorsements for a user - skill request fix: avoid creating duplicate endorsements for a user - skill request, add integration-tests for endorsement creation May 14, 2025
@Shyam-Vishwakarma Shyam-Vishwakarma changed the title fix: avoid creating duplicate endorsements for a user - skill request, add integration-tests for endorsement creation fix: avoid creating duplicate endorsements, add integration-tests for endorsement creation May 14, 2025
@Shyam-Vishwakarma
Copy link
Contributor Author

@Shyam-Vishwakarma Please update the title and try and keep concerns separated from next time for bug fix and tests

updated.

MayankBansal12
MayankBansal12 previously approved these changes May 14, 2025
MayankBansal12
MayankBansal12 previously approved these changes May 14, 2025
@iamitprakash iamitprakash merged commit afb7a76 into RealDevSquad:develop May 15, 2025
4 checks passed
@MayankBansal12 MayankBansal12 mentioned this pull request May 15, 2025
10 tasks
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.

[BUG] Duplicate endorsement can be created for a user on a skill [TEST] Write integration tests for POST /v1/skills/{id}/endorsements

5 participants