Implement Paginated Recent Activity Endpoint for Use#116
Merged
phertyameen merged 1 commit intoMindBlockLabs:mainfrom Jul 29, 2025
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧩 Feature: Paginated Recent Activity Endpoint for Users
📌 Overview
This PR introduces a new paginated endpoint to retrieve a user's recent activity, including puzzle completions and achievement unlocks. The logic is modularized via a dedicated provider and clean service-controller structure.
Implementation Details
✅ PuzzleActivityProvider
Created PuzzleActivityProvider to encapsulate logic for fetching and formatting recent puzzle events.
Queries PuzzleEvent repository using skip, take, and orderBy for pagination and sorting.
Formats entries into simplified, user-friendly activity descriptors.
✅ UserActivityService
Injects PuzzleActivityProvider.
Delegates logic to provider to maintain lean service architecture.
✅ UserController
Added new route handler for GET /users/:id/activity.
Validates and parses page and limit query params.
📂 Affected Files
src/user/controller/user.controller.ts
src/user/services/user-activity.service.ts (new)
src/user/providers/puzzle-activity.provider.ts (new)
src/user/interfaces/user-activity.interface.ts (new)
src/puzzle/entities/puzzle-event.entity.ts
✅ Acceptance Criteria
Pagination works with page and limit query params.
Activity is ordered by createdAt DESC.
Responses are clean, structured, and readable.
Logic is encapsulated within a dedicated provider.
Unit tests added for provider and service layers.
🧪 Tests Added
✅ Provider method tests (fetch + format logic).
✅ Service forwarding logic.
✅ Controller input validation and integration tests.
🚀 New Endpoint
close #101
GET
/users/:id/activity?page=1&limit=5🔍 Example Response:
[ { "description": "Completed \"Binary Tree Maximum Depth\" puzzle", "timestamp": "2025-07-05T08:00:00Z" }, { "description": "Unlocked \"Code Ninja\" achievement", "timestamp": "2025-07-04T16:30:00Z" } ]