Merge pull request #14646 from peppy/fix-user-request-typing

Use correct lookup type to ensure username based lookups always prefer username
This commit is contained in:
Dan Balasescu 2021-09-06 15:36:39 +09:00 committed by GitHub
commit c7abda8f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -8,8 +8,9 @@ namespace osu.Game.Online.API.Requests
{
public class GetUserRequest : APIRequest<User>
{
private readonly string userIdentifier;
private readonly string lookup;
public readonly RulesetInfo Ruleset;
private readonly LookupType lookupType;
/// <summary>
/// Gets the currently logged-in user.
@ -25,7 +26,8 @@ public GetUserRequest()
/// <param name="ruleset">The ruleset to get the user's info for.</param>
public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
{
this.userIdentifier = userId.ToString();
lookup = userId.ToString();
lookupType = LookupType.Id;
Ruleset = ruleset;
}
@ -36,10 +38,17 @@ public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
/// <param name="ruleset">The ruleset to get the user's info for.</param>
public GetUserRequest(string username = null, RulesetInfo ruleset = null)
{
this.userIdentifier = username;
lookup = username;
lookupType = LookupType.Username;
Ruleset = ruleset;
}
protected override string Target => userIdentifier != null ? $@"users/{userIdentifier}/{Ruleset?.ShortName}" : $@"me/{Ruleset?.ShortName}";
protected override string Target => lookup != null ? $@"users/{lookup}/{Ruleset?.ShortName}?k={lookupType.ToString().ToLower()}" : $@"me/{Ruleset?.ShortName}";
private enum LookupType
{
Id,
Username
}
}
}