Skip to content

Commit 1c0be83

Browse files
authored
Expose VitaIconHash and BetaIconHash to the API (#919)
Also allows users to edit their own Vita and Beta profile pictures through the API, and makes more use of `DataContext.GetIconFromHash` for user responses.
2 parents 7f6d22b + b194ab2 commit 1c0be83

7 files changed

Lines changed: 30 additions & 3 deletions

File tree

Refresh.Database/GameDatabaseContext.Users.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ public void UpdateUserData(GameUser user, IApiEditUserRequest data)
184184

185185
if (data.IconHash != null)
186186
user.IconHash = data.IconHash;
187+
188+
if (data.VitaIconHash != null)
189+
user.VitaIconHash = data.VitaIconHash;
190+
191+
if (data.BetaIconHash != null)
192+
user.BetaIconHash = data.BetaIconHash;
187193

188194
if (data.Description != null)
189195
user.Description = data.Description;

Refresh.Database/Query/IApiEditUserRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Refresh.Database.Query;
55
public interface IApiEditUserRequest
66
{
77
string? IconHash { get; set; }
8+
string? VitaIconHash { get; set; }
9+
string? BetaIconHash { get; set; }
810
string? Description { get; set; }
911
bool? AllowIpAuthentication { get; set; }
1012
bool? PsnAuthenticationAllowed { get; set; }

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Request/ApiUpdateUserRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Refresh.Interfaces.APIv3.Endpoints.DataTypes.Request;
77
public class ApiUpdateUserRequest : IApiEditUserRequest
88
{
99
public string? IconHash { get; set; }
10+
public string? VitaIconHash { get; set; }
11+
public string? BetaIconHash { get; set; }
1012
public string? Description { get; set; }
1113
public bool? AllowIpAuthentication { get; set; }
1214

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Response/Users/ApiExtendedGameUserResponse.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ApiExtendedGameUserResponse : IApiResponse, IDataConvertableFrom<Ap
1616
public required string UserId { get; set; }
1717
public required string Username { get; set; }
1818
public required string IconHash { get; set; }
19+
public required string VitaIconHash { get; set; }
20+
public required string BetaIconHash { get; set; }
1921
public required string Description { get; set; }
2022
public required ApiGameLocationResponse Location { get; set; }
2123
public required DateTimeOffset JoinDate { get; set; }
@@ -57,7 +59,9 @@ public class ApiExtendedGameUserResponse : IApiResponse, IDataConvertableFrom<Ap
5759
{
5860
UserId = user.UserId.ToString()!,
5961
Username = user.Username,
60-
IconHash = dataContext.Database.GetAssetFromHash(user.IconHash)?.GetAsIcon(TokenGame.Website, dataContext) ?? user.IconHash,
62+
IconHash = dataContext.GetIconFromHash(user.IconHash),
63+
VitaIconHash = dataContext.GetIconFromHash(user.VitaIconHash),
64+
BetaIconHash = dataContext.GetIconFromHash(user.BetaIconHash),
6165
Description = user.Description,
6266
Location = ApiGameLocationResponse.FromLocation(user.LocationX, user.LocationY)!,
6367
JoinDate = user.JoinDate,

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Response/Users/ApiGameUserResponse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class ApiGameUserResponse : IApiResponse, IDataConvertableFrom<ApiGameUse
1515
public required string UserId { get; set; }
1616
public required string Username { get; set; }
1717
public required string IconHash { get; set; }
18+
public required string VitaIconHash { get; set; }
19+
public required string BetaIconHash { get; set; }
1820

1921
public required string YayFaceHash { get; set; }
2022
public required string BooFaceHash { get; set; }
@@ -39,6 +41,8 @@ public class ApiGameUserResponse : IApiResponse, IDataConvertableFrom<ApiGameUse
3941
Username = user.Username,
4042

4143
IconHash = dataContext.GetIconFromHash(user.IconHash),
44+
VitaIconHash = dataContext.GetIconFromHash(user.VitaIconHash),
45+
BetaIconHash = dataContext.GetIconFromHash(user.BetaIconHash),
4246
YayFaceHash = dataContext.GetIconFromHash(user.YayFaceHash),
4347
BooFaceHash = dataContext.GetIconFromHash(user.BooFaceHash),
4448
MehFaceHash = dataContext.GetIconFromHash(user.MehFaceHash),

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Response/Users/ApiMinimalUserResponse.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class ApiMinimalUserResponse : IApiResponse, IDataConvertableFrom<ApiMini
99
public required string UserId { get; set; }
1010
public required string Username { get; set; }
1111
public required string IconHash { get; set; }
12-
12+
public required string VitaIconHash { get; set; }
13+
public required string BetaIconHash { get; set; }
1314

1415
public static ApiMinimalUserResponse? FromOld(GameUser? old, DataContext dataContext)
1516
{
@@ -19,7 +20,9 @@ public class ApiMinimalUserResponse : IApiResponse, IDataConvertableFrom<ApiMini
1920
{
2021
UserId = old.UserId.ToString(),
2122
Username = old.Username,
22-
IconHash = old.IconHash,
23+
IconHash = dataContext.GetIconFromHash(old.IconHash),
24+
VitaIconHash = dataContext.GetIconFromHash(old.VitaIconHash),
25+
BetaIconHash = dataContext.GetIconFromHash(old.BetaIconHash),
2326
};
2427
}
2528

Refresh.Interfaces.APIv3/Endpoints/UserApiEndpoints.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public ApiResponse<ApiExtendedGameUserResponse> UpdateUser(RequestContext contex
5959
{
6060
if (body.IconHash != null && database.GetAssetFromHash(body.IconHash) == null)
6161
return ApiNotFoundError.Instance;
62+
63+
if (body.VitaIconHash != null && database.GetAssetFromHash(body.VitaIconHash) == null)
64+
return ApiNotFoundError.Instance;
65+
66+
if (body.BetaIconHash != null && database.GetAssetFromHash(body.BetaIconHash) == null)
67+
return ApiNotFoundError.Instance;
6268

6369
if (body.EmailAddress != null && !smtpService.CheckEmailDomainValidity(body.EmailAddress))
6470
return ApiValidationError.EmailDoesNotActuallyExistError;

0 commit comments

Comments
 (0)