Skip to content

838: add metrics api endpoint in UserController#865

Open
naanci wants to merge 1 commit intomainfrom
838
Open

838: add metrics api endpoint in UserController#865
naanci wants to merge 1 commit intomainfrom
838

Conversation

@naanci
Copy link
Collaborator

@naanci naanci commented Mar 18, 2026

838

Description of changes

Checklist before review

  • I have done a thorough self-review of the PR
  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • If I have made database changes, I have made sure I followed all the db repo rules listed in the wiki here. (check if no db changes)
  • All tests have passed
  • I have successfully deployed this PR to staging
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.

Screenshots

Dev

Screenshot 2026-03-17 at 9 19 18 PM

Staging

Screenshot 2026-03-17 at 9 37 09 PM

@github-actions
Copy link
Contributor

Available PR Commands

  • /ai - Triggers all AI review commands at once
  • /review - AI review of the PR changes
  • /describe - AI-powered description of the PR
  • /improve - AI-powered suggestions
  • /deploy - Deploy to staging

See: https://github.com/tahminator/codebloom/wiki/CI-Commands

@github-actions
Copy link
Contributor

Title

838: add metrics api endpoint in UserController


PR Type

Enhancement, Tests


Description

  • Adds new API endpoint for user metrics.

  • Retrieves paginated metrics with date filtering.

  • Endpoint controlled by a feature flag.

  • Includes DTO and comprehensive unit tests.


Diagram Walkthrough

flowchart LR
  UserController["UserController"] --> FeatureFlagConfiguration["FeatureFlagConfiguration"]
  UserController --> UserMetricsRepository["UserMetricsRepository"]
  UserMetricsRepository -- "findUserMetrics, countUserMetrics" --> UserMetricsDB["UserMetrics (DB)"]
  UserMetricsDB --> MetricsDto["MetricsDto"]
  UserController -- "returns Page<MetricsDto>" --> Client["Client"]
Loading

File Walkthrough

Relevant files
Enhancement
UserController.java
Add user metrics API endpoint                                                       

src/main/java/org/patinanetwork/codebloom/api/user/UserController.java

  • Introduced a new GET endpoint /api/user/{userId}/metrics for fetching
    paginated user metrics.
  • Integrated UserMetricsRepository and FeatureFlagConfiguration to
    manage metrics retrieval and access control.
  • Implemented date range filtering for metrics, defaulting to the last 7
    days if not specified.
  • Added Swagger annotations for API documentation and
    ResponseStatusException for error handling.
+85/-1   
New feature
MetricsDto.java
Introduce MetricsDto for user metrics                                       

src/main/java/org/patinanetwork/codebloom/common/dto/user/metrics/MetricsDto.java

  • Created a new Data Transfer Object (DTO) MetricsDto for user metrics.
  • Utilized Lombok annotations (@Getter, @Jacksonized, @Builder,
    @ToString, @EqualsAndHashCode) for boilerplate code.
  • Provided a static factory method fromUserMetrics to convert
    UserMetrics models to MetricsDto.
+38/-0   
Configuration
FeatureFlagConfiguration.java
Add userMetrics feature flag                                                         

src/main/java/org/patinanetwork/codebloom/jda/properties/FeatureFlagConfiguration.java

  • Added a new boolean property userMetrics to enable/disable the user
    metrics feature.
  • This property is managed by Spring's @ConfigurationProperties with the
    prefix ff.
+2/-0     
application-stg.yml
Enable user metrics in staging                                                     

src/main/resources/application-stg.yml

  • Enabled the user-metrics feature flag for the staging environment.
+3/-0     
application.yml
Disable user metrics by default                                                   

src/main/resources/application.yml

  • Disabled the user-metrics feature flag by default in the main
    application configuration.
+1/-0     
Tests
UserControllerTest.java
Add unit tests for user metrics endpoint                                 

src/test/java/org/patinanetwork/codebloom/api/user/UserControllerTest.java

  • Added comprehensive unit tests for the new getUserMetrics endpoint.
  • Covered scenarios such as feature flag disabled, invalid date ranges,
    successful retrieval, default date ranges, pagination, and DTO
    mapping.
  • Mocked UserMetricsRepository and FeatureFlagConfiguration for isolated
    testing.
+179/-1 

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

**🎫 Ticket compliance analysis **

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Performance Consideration

The FakeLag.sleep(500) call introduces a hardcoded delay. While the endpoint is documented as staging-only, if this feature were ever to be enabled in a production environment, this sleep would introduce an unnecessary performance bottleneck.

FakeLag.sleep(500);

@naanci
Copy link
Collaborator Author

naanci commented Mar 18, 2026

/deploy

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