Skip to content

notification-service: split configureRouting to cut cognitive complexity (kotlin:S3776) - #1541

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1788969448-notification-routes-complexity
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1788969448-notification-routes-complexity

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes SonarCloud kotlin:S3776 (issue_key AZ6OP-RWRoUIIbwnU9es, Cognitive Complexity 46 > 15) on Application.configureRouting in services/notification-service/.../routes/Routes.kt.

Behavior-preserving refactor: the single routing lambda is split into private Route extensions plus shared ApplicationCall helpers that replace the six copy-pasted user-id/notification-id guards:

fun Application.configureRouting(registry) = routing {
    get("/health") {...}; get("/metrics") {...}
    notificationRoutes(notificationService)      // /api/v1/notifications/**
    preferenceRoutes(notificationService)        // /api/v1/preferences
    notificationWebSocket(webSocketManager)      // /ws/notifications/{userId} -> handleIncomingFrames()
}

private fun ApplicationCall.requestedUserId(): String?          // X-User-ID header ?: user_id query, null if blank
private suspend fun ApplicationCall.respondUserIdRequired()      // 400, same message as before
private suspend fun ApplicationCall.respondNotificationIdRequired()
private suspend fun ApplicationCall.respondNoContentOrNotFound(success: Boolean)

Status codes, error messages and response bodies are unchanged. No rule suppression, no sonar config changes.

Testing

Added routes/RoutesTest.kt (ktor testApplication + Koin + mockk) covering the 400 missing-user-id path with exact body, unread-count with X-User-ID, mark-as-read 204/404, and /health. ./gradlew test and ./gradlew build pass locally in services/notification-service.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/8a04b6f2804e42caa0c6ebdffd12f40d
Open in Devin Desktop: https://partner-workshops.devinenterprise.com/desktop/session/8a04b6f2804e42caa0c6ebdffd12f40d?variant=devin
Requested by: @mbatchelor81


Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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