Skip to content

Comments

[webhooks] add deviceId field to the API for compatibility with Clo…#224

Merged
capcom6 merged 1 commit intomasterfrom
issue/215-webhook-deviceid-api
May 17, 2025
Merged

[webhooks] add deviceId field to the API for compatibility with Clo…#224
capcom6 merged 1 commit intomasterfrom
issue/215-webhook-deviceid-api

Conversation

@capcom6
Copy link
Owner

@capcom6 capcom6 commented May 17, 2025

…ud server

Summary by CodeRabbit

  • New Features

    • Added an optional device ID field to webhooks, allowing webhooks to include a device identifier when applicable.
  • Bug Fixes

    • Improved validation to ensure device ID consistency when updating webhooks.
  • Documentation

    • Updated API documentation to reflect the new optional device ID field in webhook objects.

@coderabbitai
Copy link

coderabbitai bot commented May 17, 2025

"""

Walkthrough

A new nullable deviceId field was introduced to the WebHookDTO data class and incorporated throughout the webhook handling logic. The API schema was updated to reflect this addition. Methods converting or returning WebHookDTO now explicitly set deviceId to null. The WebhooksRoutes constructor was updated to accept LocalServerSettings, and a validation was added to ensure that posted webhooks with a deviceId match the local server’s device ID.

Changes

File(s) Change Summary
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt Added nullable deviceId property to WebHookDTO data class.
app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt Updated toDTO() mapping to explicitly set deviceId to null when converting GatewayApi.WebHook to DTO.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt Modified select and replace methods to set deviceId to null in returned DTOs.
app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt Changed WebhooksRoutes constructor call to pass two dependencies instead of one.
app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/WebhooksRoutes.kt Updated constructor to add LocalServerSettings; added validation to reject webhook posts with mismatched deviceId.
docs/api/swagger.json Added nullable deviceId to the WebHook schema; moved id property to the top of the schema properties list.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WebhooksRoutes
    participant LocalServerSettings
    participant WebHooksService

    Client->>WebhooksRoutes: POST /webhook (WebHookDTO)
    WebhooksRoutes->>LocalServerSettings: get deviceId
    alt WebHookDTO.deviceId != null and != localServerSettings.deviceId
        WebhooksRoutes-->>Client: throw IllegalArgumentException("Device ID mismatch")
    else
        WebhooksRoutes->>WebHooksService: replace(WebHookDTO)
        WebHooksService-->>WebhooksRoutes: WebHookDTO (deviceId = null)
        WebhooksRoutes-->>Client: WebHookDTO response
    end
Loading

Possibly related PRs

  • [webhooks] add read-only list UI #222: Also modifies the toDTO() function in WebhooksUpdateWorker.kt and extends WebHookDTO with additional fields including deviceId, showing a direct relation in webhook DTO handling.
    """

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5e9a43 and 3014df0.

📒 Files selected for processing (6)
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/WebhooksRoutes.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt (1 hunks)
  • docs/api/swagger.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/routes/WebhooksRoutes.kt
  • app/src/main/java/me/capcom/smsgateway/modules/localserver/WebService.kt
  • docs/api/swagger.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build / build-apk
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch issue/215-webhook-deviceid-api
  • Post Copyable Unit Tests in Comment

🪧 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 generate unit tests to generate unit tests for 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: 0

🧹 Nitpick comments (1)
app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (1)

50-59: Consider adding deviceId validation in sync method.

The sync method doesn't have the same deviceId validation as the replace method. For consistency in webhook handling, consider validating deviceId in the sync method as well.

 fun sync(source: EntitySource, webHooks: List<WebHookDTO>) {
+    // Validate device IDs if present
+    webHooks.forEach { webHook ->
+        if (webHook.deviceId != null && webHook.deviceId != localServerSettings.deviceId) {
+            throw IllegalArgumentException("Device ID mismatch")
+        }
+    }
+
     webHooksDao.replaceAll(source, webHooks.map {
         WebHook(
             id = requireNotNull(it.id) { "ID is required for sync" },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5cc83 and b71b329.

📒 Files selected for processing (4)
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (3 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt (1 hunks)
  • docs/api/swagger.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build / build-apk
🔇 Additional comments (7)
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt (1)

7-7: Property addition looks good.

The addition of the nullable deviceId field to the data class is appropriate for supporting the cloud server compatibility requirement while maintaining backward compatibility.

app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt (1)

41-41: Appropriate null handling for cloud webhooks.

Setting deviceId to null for cloud webhooks is consistent with the design intent, as device identifiers are managed separately for cloud communication.

app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (3)

42-42: Consistent null handling in select method.

Setting deviceId to null in the returned DTOs is consistent with the approach in other parts of the codebase.


73-77: Good validation for device ID consistency.

The validation ensures that webhooks cannot be associated with incorrect devices, which is crucial for proper routing and security.


89-89: Consistent null handling in replace method.

Setting deviceId to null in the returned DTOs maintains consistency with the pattern established in the select method.

docs/api/swagger.json (2)

652-657: API documentation properly updated.

The OpenAPI specification has been properly updated to include the new deviceId field with appropriate nullability and description.


647-651: Logical property ordering.

Moving the id property to the top of the properties list improves readability by emphasizing the primary identifier first.

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2025

🤖 Pull request artifacts

file commit
app-release.apk 3014df0
app-release.aab 3014df0

@capcom6 capcom6 force-pushed the issue/215-webhook-deviceid-api branch from c5e9a43 to 3014df0 Compare May 17, 2025 08:21
@capcom6 capcom6 merged commit 45edf1b into master May 17, 2025
3 checks passed
@capcom6 capcom6 deleted the issue/215-webhook-deviceid-api branch May 17, 2025 11:08
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