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

Updated request body of User Profile json for PUT method #444

Merged

Conversation

urio999
Copy link
Contributor

@urio999 urio999 commented Jan 11, 2025

GreenCityUser PR

Issue Link 📋

#8016
<Link to the issue>

Changed

*updated request body of User Profile json for PUT method
Example value before:
image
After:
image

PR Checklist Forms

(to be filled out by PR submitter)

  • Code is up-to-date with the develop branch.
  • You've successfully built and run the tests locally.
  • There are new or updated unit tests validating the change.
  • JIRA/ Github Issue number & title in PR title (ISSUE-XXXX: Ticket title)
  • This template filled (above this section).
  • Sonar's report does not contain bugs, vulnerabilities, security issues, code smells ar duplication
  • NEED_REVIEW and READY_FOR_REVIEW labels are added.
  • All files reviewed before sending to reviewers

Summary by CodeRabbit

  • New Features

    • Added support for user personal credo (max 170 characters)
    • Introduced ability to link multiple social networks to user profile
  • Documentation

    • Enhanced API documentation with Swagger annotations
    • Added read-only indicators for specific user notification preference fields

Copy link

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces API documentation enhancements for user-related data transfer objects in the Green City project. Two main changes are implemented: adding Swagger schema annotations to the UserNotificationPreferenceDto to mark certain fields as read-only, and expanding the UserProfileDtoRequest with new fields for user credo and social networks. These modifications aim to improve API documentation and provide more comprehensive user profile information.

Changes

File Change Summary
service-api/.../UserNotificationPreferenceDto.java Added @Schema(accessMode = Schema.AccessMode.READ_ONLY) annotations to id and userVO fields
service-api/.../UserProfileDtoRequest.java Added new fields: userCredo (String, max 170 chars) and socialNetworks (List) with Swagger schema annotations

Poem

🌟 API Whispers, Annotations Bright 🌐
Fields marked read-only, taking flight
Credo and networks, now taking space
Swagger's embrace, with elegant grace
Documentation dancing, clear and light! 📝✨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 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.
    • Generate unit testing code for this file.
    • 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 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

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

🧹 Nitpick comments (2)
service-api/src/main/java/greencity/dto/user/UserNotificationPreferenceDto.java (1)

21-22: Well-structured API documentation enhancement!

The addition of @Schema(accessMode = Schema.AccessMode.READ_ONLY) annotations effectively communicates the API contract to consumers. This is a good practice that helps prevent confusion about which fields can be modified.

Consider adding description fields to the Schema annotations to provide more context:

-    @Schema(accessMode = Schema.AccessMode.READ_ONLY)
+    @Schema(accessMode = Schema.AccessMode.READ_ONLY, 
+            description = "Unique identifier for the notification preference")
     private Long id;

     @JsonBackReference
-    @Schema(accessMode = Schema.AccessMode.READ_ONLY)
+    @Schema(accessMode = Schema.AccessMode.READ_ONLY,
+            description = "Associated user information")
     private UserVO userVO;

Also applies to: 25-26

service-api/src/main/java/greencity/dto/user/UserProfileDtoRequest.java (1)

32-34: Consider adding nullability constraints for userCredo

While the size constraint is properly set, it would be helpful to explicitly define whether this field is required or optional using @NotNull or @Nullable annotations. This improves API documentation and validation.

     @Size(max = 170)
+    @NotNull
     @Schema(example = "Lets Make The World A Better Place")
     private String userCredo;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9294f95 and 42bebb6.

📒 Files selected for processing (2)
  • service-api/src/main/java/greencity/dto/user/UserNotificationPreferenceDto.java (2 hunks)
  • service-api/src/main/java/greencity/dto/user/UserProfileDtoRequest.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

Comment on lines 35 to 37
@ValidSocialNetworkLinks
@Schema(example = "https://www.facebook.com/greencity")
private List<String> socialNetworks;
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Social network validation needs enhancement

The current implementation has several limitations that should be addressed:

  • The URL validator only checks for valid URL syntax without validating social network domains
  • No specific validation exists to ensure URLs belong to supported social networks
  • Test coverage could be enhanced with social network-specific test cases

Suggested improvements:

  1. Add a whitelist of supported social network domains
  2. Enhance URL validation to check against the supported domains
  3. Add comprehensive test cases for various social network URLs
  4. Update the @Schema example to show multiple URLs as it's a List
🔗 Analysis chain

Verify social network links validation implementation

The @ValidSocialNetworkLinks custom annotation is used, but let's ensure its implementation properly validates social network URLs.

Let's check the implementation of the custom validator:

Also, consider:

  1. Adding @NotNull if this field is required
  2. Updating the example to include multiple social network URLs since it's a List
  3. Adding a description to the Schema annotation explaining supported social networks
     @ValidSocialNetworkLinks
-    @Schema(example = "https://www.facebook.com/greencity")
+    @Schema(
+        description = "List of social network profile URLs (supported: Facebook, Twitter, Instagram)",
+        example = "[\"https://www.facebook.com/greencity\", \"https://twitter.com/greencity\"]"
+    )
     private List<String> socialNetworks;
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the ValidSocialNetworkLinks validator implementation
echo "Searching for ValidSocialNetworkLinks validator..."
rg -l "ValidSocialNetworkLinks"

# Search for any existing test cases
echo "Searching for related test cases..."
rg -l "ValidSocialNetworkLinks.*Test"

Length of output: 491


Script:

#!/bin/bash
# Check the validator implementation
echo "=== Validator Implementation ==="
cat service-api/src/main/java/greencity/validator/SocialNetworkLinksValidator.java

echo -e "\n=== Annotation Definition ==="
cat service-api/src/main/java/greencity/annotations/ValidSocialNetworkLinks.java

# Look for potential configuration files
echo -e "\n=== Searching for social network configuration ==="
rg -l "social.*network.*config" --type-add 'config:*.{properties,yml,yaml,xml}' -tconfig

Length of output: 2905


Script:

#!/bin/bash
# Check URL validator and constants
echo "=== URL Validator Implementation ==="
rg -l "class UrlValidator"
ast-grep --pattern 'class UrlValidator { $$$ }'

echo -e "\n=== ValidationConstants ==="
rg -l "class ValidationConstants"
ast-grep --pattern 'class ValidationConstants { $$$ }'

# Look for any error messages related to social networks
echo -e "\n=== Error Messages ==="
rg -l "class ErrorMessage"
ast-grep --pattern 'class ErrorMessage { $$$ }'

Length of output: 793


Script:

#!/bin/bash
echo "=== URL Validator Implementation ==="
cat service-api/src/main/java/greencity/validator/UrlValidator.java

echo -e "\n=== URL Validator Test ==="
cat service-api/src/test/java/greencity/validator/UrlValidatorTest.java

echo -e "\n=== Service API ValidationConstants ==="
cat service-api/src/main/java/greencity/constant/ValidationConstants.java

echo -e "\n=== Error Messages ==="
cat service-api/src/main/java/greencity/constant/ErrorMessage.java

Length of output: 8865

@urio999 urio999 self-assigned this Jan 13, 2025
@urio999 urio999 merged commit 4d18fb9 into dev Jan 13, 2025
4 checks passed
@urio999 urio999 deleted the bug/8016/fix-outdated-request-body-put-user-profile-endpoint branch January 13, 2025 10:55
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.

4 participants