Skip to content

[BACKEND] - Add user profile and account management endpoints - #453

Merged
Hydrax117 merged 2 commits into
Arenax-gaming:mainfrom
iyanumajekodunmi756:No-user-profile-or-account-management-endpoints
Jun 2, 2026
Merged

Hydrax117 merged 2 commits into
Arenax-gaming:mainfrom
iyanumajekodunmi756:No-user-profile-or-account-management-endpoints

Conversation

@iyanumajekodunmi756

@iyanumajekodunmi756 iyanumajekodunmi756 commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Issue Reference

Fixes #445 - [BACKEND] - No user profile or account management endpoints

Summary

This PR implements user profile and account management endpoints to address issue #445. The User model exists in src/models/user.rs but was never exposed via HTTP. This implementation provides the necessary endpoints for clients to fetch profiles, update usernames, change avatars, and view their own account details.

Implementation Comparison

Required Endpoints (from #445)

  • GET /api/users/{id} — public profile
  • GET /api/users/me — authenticated user's own profile
  • PUT /api/users/me — update profile (username, avatar)
  • GET /api/users/{id}/stats — win/loss record, Elo history

Implementation Details

New Files Created:

  1. src/service/user_service.rs (199 lines)

    • UserService with methods for user profile management
    • Database queries for user operations
    • Support for partial profile updates
    • User stats aggregation with win/loss records and Elo history
  2. src/http/users.rs (125 lines)

    • HTTP handlers for user endpoints
    • Request/response DTOs
    • Authentication middleware integration
    • Unit tests for request validation

Modified Files:

  1. src/service/mod.rs - Added user_service module export
  2. src/http/mod.rs - Added users module
  3. src/main.rs - Registered user routes under /api/users scope

API Endpoints Implemented

GET /api/users/{id} - Public User Profile

  • Returns public profile information for any user
  • Excludes sensitive data (email, phone)
  • Includes: id, username, display_name, avatar_url, is_verified, created_at, skill_score, fair_play_score

GET /api/users/me - Current User Profile

  • Returns full user profile for authenticated user
  • Requires JWT authentication via middleware
  • Returns all user fields including sensitive data

PUT /api/users/me - Update Profile

  • Updates authenticated user's profile
  • Supports partial updates (only provided fields are updated)
  • Accepts: username, avatar_url, display_name, bio
  • Returns updated user object
  • Enhancement: Added display_name and bio beyond the basic username/avatar requirement

GET /api/users/{id}/stats - User Statistics

  • Returns comprehensive user statistics
  • Includes: current_rating, peak_rating, games_played, wins, losses, draws
  • Calculates win_rate percentage
  • Includes win_streak and loss_streak
  • Returns recent Elo history (last 50 matches)
  • Defaults to starting rating (1000) if no matches played

Code Quality

  • Follows existing codebase patterns and conventions
  • Proper error handling with ApiError
  • Authentication middleware integration for protected endpoints
  • Database queries using sqlx with parameter binding
  • Unit tests included for request validation
  • Consistent JSON response format with success and data fields

Testing Considerations

The implementation includes basic unit tests for request validation. Additional testing should include:

  • Integration tests with actual database
  • Authentication/authorization testing
  • Edge cases (non-existent users, invalid UUIDs)
  • Performance testing for stats endpoint

Breaking Changes

None - this adds new functionality without modifying existing endpoints

Migration Notes

No database migrations required - uses existing tables (users, user_elo, elo_history)

Generated with Devin (https://cli.devin.ai/docs)

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

@iyanumajekodunmi756 is attempting to deploy a commit to the paul joseph's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 1, 2026

Copy link
Copy Markdown

@iyanumajekodunmi756 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Hydrax117
Hydrax117 merged commit bc040b6 into Arenax-gaming:main Jun 2, 2026
0 of 5 checks passed
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.

[BACKEND] - No user profile or account management endpoints

2 participants