Add platform info to profile DTO with setting-based visibility
This commit is contained in:
@@ -21,13 +21,15 @@ public class ProfileService(
|
||||
ITokenService tokenService,
|
||||
IMapper mapper) : IProfileService
|
||||
{
|
||||
private const string ShowPlatformPreferenceKey = "SHOW_PLATFORM_PREF";
|
||||
|
||||
public async Task<ProfileDTO?> GetProfileAsync(Guid profileId, CancellationToken ct = default)
|
||||
{
|
||||
var profile = await profileRepository.GetByIdAsync(profileId, ct);
|
||||
|
||||
return profile is null
|
||||
? null
|
||||
: mapper.Map<ProfileDTO>(profile);
|
||||
: await MapProfileAsync(profile, ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(
|
||||
@@ -36,7 +38,11 @@ public class ProfileService(
|
||||
{
|
||||
var profiles = await profileRepository.GetByIdsAsync(profileIds, ct);
|
||||
|
||||
return mapper.Map<List<ProfileDTO>>(profiles);
|
||||
var results = new List<ProfileDTO>(profiles.Count);
|
||||
foreach (var profile in profiles)
|
||||
results.Add(await MapProfileAsync(profile, ct));
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public async Task<AvatarDTO?> GetAvatarAsync(Guid profileId, CancellationToken ct = default)
|
||||
@@ -116,7 +122,7 @@ public class ProfileService(
|
||||
|
||||
var isValidGameVersion = await gameVersionRepository.IsValidAsync(command.AppVersion, ct);
|
||||
if (!isValidGameVersion)
|
||||
return LoginProfileResult.Fail("Invalid app version.");
|
||||
return LoginProfileResult.Fail("A new update is available! Go to https://recroom.baby to download the latest update.");
|
||||
|
||||
// 2. Validate Platform Authentication
|
||||
var validator = validators.FirstOrDefault(x => x.PlatformType == command.PlatformType);
|
||||
@@ -166,9 +172,29 @@ public class ProfileService(
|
||||
var token = tokenService.GenerateProfileToken(profile);
|
||||
|
||||
return LoginProfileResult.Success(
|
||||
profile: mapper.Map<ProfileDTO>(profile),
|
||||
profile: await MapProfileAsync(profile, ct),
|
||||
accessToken: token.AccessToken,
|
||||
expiresIn: token.ExpiresIn
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ProfileDTO> MapProfileAsync(ProfileEntity profile, CancellationToken ct)
|
||||
{
|
||||
var showPlatformPreference = profile.Platform == PlatformType.Steamworks &&
|
||||
await profileRepository.GetSettingByProfileId<bool>(
|
||||
profile.ProfileId,
|
||||
ShowPlatformPreferenceKey,
|
||||
ct);
|
||||
|
||||
return new ProfileDTO
|
||||
{
|
||||
ProfileId = profile.ProfileId,
|
||||
Name = profile.Name,
|
||||
IsDeveloper = profile.IsDeveloper,
|
||||
Platform = profile.Platform,
|
||||
PlatformId = profile.Platform == PlatformType.Steamworks && showPlatformPreference
|
||||
? profile.PlatformId
|
||||
: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user