Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API endpoint for minimal user profile information #2092

Merged
merged 8 commits into from
Dec 17, 2023

Conversation

relm
Copy link
Contributor

@relm relm commented Dec 9, 2023

This PR adds a new endpoint to retrieve minimal user profile information - API_GetUserProfile.php

We use the existing API_GetUserSummary.php endpoint to check if a user exists as well as other details like their untracked/tracked status and then pull additional profile information based on that. This results in some unnecessary DB queries as we only really need fields from the main user table. So I propose adding this as a lighter alternative.

One argument is accepted - u which represents the user's username

Example output:

{
	"User": "Root",
	"MemberSince": "2023-12-09 19:24:46",
	"RichPresenceMsg": null,
	"LastGameID": 0,
	"ContribCount": 0,
	"ContribYield": 0,
	"TotalPoints": 1000,
	"TotalSoftcorePoints": 0,
	"TotalTruePoints": 1010,
	"Permissions": 4,
	"Untracked": 0,
	"ID": 1000001,
	"UserWallActive": 1,
	"Motto": "I am root",
	"UserPic": "\/UserPic\/root.png"
}

Copy link
Member

@wescopeland wescopeland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting a PR.

Please add tests for any new endpoint.

Also, let's not add new functionality to any Helpers file unless absolutely necessary. We plan on phasing these out soon. As an alternative, perhaps it would just be best for this new functionality to live within the endpoint itself.

@wescopeland
Copy link
Member

#2090 may be a helpful reference.

@relm
Copy link
Contributor Author

relm commented Dec 9, 2023

Done! Moved the functionality to the endpoint itself and added tests.

@wescopeland wescopeland dismissed their stale review December 10, 2023 13:02

Tests added and code refactored

Copy link
Member

@wescopeland wescopeland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. A few minor nits.

public/API/API_GetUserProfile.php Show resolved Hide resolved
public/API/API_GetUserProfile.php Outdated Show resolved Hide resolved
public/API/API_GetUserProfile.php Outdated Show resolved Hide resolved
@relm
Copy link
Contributor Author

relm commented Dec 10, 2023

Should be good now!

public/API/API_GetUserProfile.php Show resolved Hide resolved
public/API/API_GetUserProfile.php Show resolved Hide resolved
public/API/API_GetUserProfile.php Outdated Show resolved Hide resolved
tests/Feature/Api/V1/UserProfileTest.php Outdated Show resolved Hide resolved
@Jamiras Jamiras merged commit 927cd96 into RetroAchievements:master Dec 17, 2023
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.

4 participants