Skip to content

838: add metrics api endpoint in UserController#865

Merged
naanci merged 1 commit intomainfrom
838
Mar 19, 2026
Merged

838: add metrics api endpoint in UserController#865
naanci merged 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

@naanci
Copy link
Collaborator Author

naanci commented Mar 19, 2026

/deploy

@naanci naanci enabled auto-merge (rebase) March 19, 2026 01:24
@github-actions
Copy link
Contributor

Title

838: add metrics api endpoint in UserController


PR Type

Enhancement


Description

  • Adds user metrics API endpoint.

  • Introduces MetricsDto for data transfer.

  • Implements feature flag for metrics.

  • Includes comprehensive unit tests.


Diagram Walkthrough

flowchart LR
  A[Client Request] --> B{GET /api/user/{userId}/metrics};
  B --> C{UserController};
  C -- "Check ff.isUserMetrics()" --> D{FeatureFlagConfiguration};
  D -- "Forbidden (403)" --> E[Error Response];
  C -- "Validate Date Range" --> F{Date Validation};
  F -- "Bad Request (400)" --> E;
  C -- "Build UserMetricsFilterOptions" --> G{UserMetricsRepository};
  G -- "findUserMetrics & countUserMetrics" --> H[List<UserMetrics> & Total Count];
  H --> I{Map to MetricsDto & Paginate};
  I --> J[Paginated MetricsDto Response];
Loading

File Walkthrough

Relevant files
Api
UserController.java
Add user metrics API endpoint                                                       

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

  • Added a new GET endpoint /api/user/{userId}/metrics for paginated user
    metrics.
  • Injected UserMetricsRepository and FeatureFlagConfiguration into the
    controller.
  • Implemented logic for date range filtering, pagination, and feature
    flag enforcement.
  • Mapped UserMetrics database models to MetricsDto for API responses.
+85/-1   
Dto
MetricsDto.java
Introduce MetricsDto for user metrics                                       

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

  • Created a new DTO MetricsDto to represent user metrics data.
  • Includes fields id, userId, points, and createdAt.
  • Provided a static factory method fromUserMetrics for conversion from
    the database model.
+38/-0   
Configuration
FeatureFlagConfiguration.java
Add user metrics feature flag                                                       

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

  • Added a new boolean property userMetrics to control the availability
    of the user metrics feature.
+2/-0     
application-stg.yml
Enable user metrics in staging                                                     

src/main/resources/application-stg.yml

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

src/main/resources/application.yml

  • Added the user-metrics feature flag with a default value of false.
+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.
  • Tested scenarios including feature flag disabled, invalid date ranges,
    successful retrieval, default date ranges, empty results, page size
    capping, and pagination.
  • 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 Impact

The FakeLag.sleep(500) call introduces an intentional delay of 500 milliseconds. While this is likely for development/staging purposes, it's important to ensure this utility is appropriately managed and does not inadvertently affect performance in production environments or under heavy load in staging. The feature flag check should prevent it from running in production, but its presence is noteworthy.

FakeLag.sleep(500);

@naanci naanci merged commit e33c42c into main Mar 19, 2026
35 checks passed
@naanci naanci deleted the 838 branch March 19, 2026 01:36
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.

2 participants