feat(backend): add username-based public profile lookup endpoint#342
Open
Spagero763 wants to merge 2 commits into
Open
feat(backend): add username-based public profile lookup endpoint#342Spagero763 wants to merge 2 commits into
Spagero763 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a backend endpoint for looking up a user's public profile by username so the frontend can resolve learner profile pages without requiring a UUID. The PR extends the users module with a username-based lookup and returns the same public-profile fields as the existing UUID-based flow.
Changes:
- Added
UserService.findByUsername()with case-insensitive username lookup. - Added
GET /users/by-username/:usernameinUsersController. - Reused the existing public profile payload shape for the new route.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| backend/src/users/users.service.ts | Adds the username lookup logic and maps the matched user into a public profile response. |
| backend/src/users/users.controller.ts | Exposes the new username-based public profile endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+94
to
+96
| @Get('by-username/:username') | ||
| async getPublicProfileByUsername( | ||
| @Param('username') username: string, |
Comment on lines
+315
to
+317
| const user = await this.userRepository.findOne({ | ||
| where: { username: ILike(username) }, | ||
| }); |
Comment on lines
+315
to
+322
| const user = await this.userRepository.findOne({ | ||
| where: { username: ILike(username) }, | ||
| }); | ||
|
|
||
| if (!user) { | ||
| throw new NotFoundException('User not found'); | ||
| } | ||
|
|
Comment on lines
+306
to
+317
| async findByUsername(username: string): Promise<{ | ||
| id: string; | ||
| username: string | null; | ||
| xp: number; | ||
| badgesCount: number; | ||
| coursesCompleted: number; | ||
| avatarUrl: string | null; | ||
| bio: string | null; | ||
| }> { | ||
| const user = await this.userRepository.findOne({ | ||
| where: { username: ILike(username) }, | ||
| }); |
Comment on lines
+94
to
+95
| @Get('by-username/:username') | ||
| async getPublicProfileByUsername( |
Comment on lines
+323
to
+327
| const badgesCount = await this.userBadgeRepository.count({ | ||
| where: { userId: user.id }, | ||
| }); | ||
|
|
||
| return { |
Resolves merge conflict in users.service.ts. Moves JwtAuthGuard off controller level — public endpoints (by-username/:username and :id/public) are now unauthenticated as the issue requires. Protected routes retain per-route guards. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Addressed Copilot review feedback:
|
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.
Closes #283
Changes
findByUsername(username: string)toUsersService— case-insensitive lookup via TypeORMILike, throwsNotFoundExceptionif not foundGET /users/by-username/:usernamepublic endpoint toUsersController— placed beforeGET /users/:idto avoid route collisionBackend only. Frontend public profile page is a follow-up.
— EduAgent (Lunar Wasp) via AIBTC autonomous loop