Add platform info to profile DTO with setting-based visibility
This commit is contained in:
@@ -3,6 +3,7 @@ using RecNet.Application.Profiles;
|
|||||||
using RecNet.Application.Profiles.Avatar;
|
using RecNet.Application.Profiles.Avatar;
|
||||||
using RecNet.Application.Profiles.Relationships;
|
using RecNet.Application.Profiles.Relationships;
|
||||||
using RecNet.Application.Profiles.Settings;
|
using RecNet.Application.Profiles.Settings;
|
||||||
|
using RecNet.Domain.Common;
|
||||||
|
|
||||||
namespace RecNet.Application.Common.Mapping;
|
namespace RecNet.Application.Common.Mapping;
|
||||||
|
|
||||||
@@ -10,7 +11,10 @@ public class ApplicationMappingProfile : Profile
|
|||||||
{
|
{
|
||||||
public ApplicationMappingProfile()
|
public ApplicationMappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Domain.Profiles.Profile, ProfileDTO>();
|
CreateMap<Domain.Profiles.Profile, ProfileDTO>()
|
||||||
|
.ForMember(
|
||||||
|
x => x.PlatformId,
|
||||||
|
opt => opt.MapFrom(x => x.Platform == PlatformType.Steamworks ? x.PlatformId : null));
|
||||||
CreateMap<Domain.Profiles.Avatar, AvatarDTO>();
|
CreateMap<Domain.Profiles.Avatar, AvatarDTO>();
|
||||||
CreateMap<Domain.Profiles.Relationship, RelationshipDTO>();
|
CreateMap<Domain.Profiles.Relationship, RelationshipDTO>();
|
||||||
CreateMap<Domain.Profiles.PlayerSetting, PlayerSettingDTO>();
|
CreateMap<Domain.Profiles.PlayerSetting, PlayerSettingDTO>();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using RecNet.Domain.Common;
|
||||||
|
|
||||||
namespace RecNet.Application.Profiles;
|
namespace RecNet.Application.Profiles;
|
||||||
|
|
||||||
@@ -12,4 +13,11 @@ public class ProfileDTO
|
|||||||
|
|
||||||
[JsonPropertyName("Developer")]
|
[JsonPropertyName("Developer")]
|
||||||
public bool IsDeveloper { get; init; }
|
public bool IsDeveloper { get; init; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Platform")]
|
||||||
|
public PlatformType Platform { get; init; }
|
||||||
|
|
||||||
|
[JsonPropertyName("PlatformId")]
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
public string? PlatformId { get; init; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ public class ProfileService(
|
|||||||
ITokenService tokenService,
|
ITokenService tokenService,
|
||||||
IMapper mapper) : IProfileService
|
IMapper mapper) : IProfileService
|
||||||
{
|
{
|
||||||
|
private const string ShowPlatformPreferenceKey = "SHOW_PLATFORM_PREF";
|
||||||
|
|
||||||
public async Task<ProfileDTO?> GetProfileAsync(Guid profileId, CancellationToken ct = default)
|
public async Task<ProfileDTO?> GetProfileAsync(Guid profileId, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var profile = await profileRepository.GetByIdAsync(profileId, ct);
|
var profile = await profileRepository.GetByIdAsync(profileId, ct);
|
||||||
|
|
||||||
return profile is null
|
return profile is null
|
||||||
? null
|
? null
|
||||||
: mapper.Map<ProfileDTO>(profile);
|
: await MapProfileAsync(profile, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(
|
public async Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(
|
||||||
@@ -36,7 +38,11 @@ public class ProfileService(
|
|||||||
{
|
{
|
||||||
var profiles = await profileRepository.GetByIdsAsync(profileIds, ct);
|
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)
|
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);
|
var isValidGameVersion = await gameVersionRepository.IsValidAsync(command.AppVersion, ct);
|
||||||
if (!isValidGameVersion)
|
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
|
// 2. Validate Platform Authentication
|
||||||
var validator = validators.FirstOrDefault(x => x.PlatformType == command.PlatformType);
|
var validator = validators.FirstOrDefault(x => x.PlatformType == command.PlatformType);
|
||||||
@@ -166,9 +172,29 @@ public class ProfileService(
|
|||||||
var token = tokenService.GenerateProfileToken(profile);
|
var token = tokenService.GenerateProfileToken(profile);
|
||||||
|
|
||||||
return LoginProfileResult.Success(
|
return LoginProfileResult.Success(
|
||||||
profile: mapper.Map<ProfileDTO>(profile),
|
profile: await MapProfileAsync(profile, ct),
|
||||||
accessToken: token.AccessToken,
|
accessToken: token.AccessToken,
|
||||||
expiresIn: token.ExpiresIn
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ public interface IProfileRepository
|
|||||||
Task<Profile?> GetByIdAsync(Guid profileId, CancellationToken ct = default);
|
Task<Profile?> GetByIdAsync(Guid profileId, CancellationToken ct = default);
|
||||||
Task<Profile?> GetByIdWithSettingsAsync(Guid profileId, CancellationToken ct = default);
|
Task<Profile?> GetByIdWithSettingsAsync(Guid profileId, CancellationToken ct = default);
|
||||||
Task<Avatar?> GetAvatarByProfileIdAsync(Guid profileId, CancellationToken ct = default);
|
Task<Avatar?> GetAvatarByProfileIdAsync(Guid profileId, CancellationToken ct = default);
|
||||||
|
Task<T?> GetSettingByProfileId<T>(Guid profileId, string key, CancellationToken ct = default);
|
||||||
Task<IReadOnlyList<PlayerSetting>> GetSettingsByProfileIdAsync(Guid profileId, CancellationToken ct = default);
|
Task<IReadOnlyList<PlayerSetting>> GetSettingsByProfileIdAsync(Guid profileId, CancellationToken ct = default);
|
||||||
Task<IReadOnlyList<Profile>> GetByIdsAsync(List<Guid> profileIds, CancellationToken ct = default);
|
Task<IReadOnlyList<Profile>> GetByIdsAsync(List<Guid> profileIds, CancellationToken ct = default);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Text.Json;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using RecNet.Domain.Common;
|
using RecNet.Domain.Common;
|
||||||
using RecNet.Domain.Profiles;
|
using RecNet.Domain.Profiles;
|
||||||
@@ -28,6 +29,20 @@ public class ProfileRepository(DatabaseContext dbContext) : IProfileRepository
|
|||||||
.Select(x => x.Avatar)
|
.Select(x => x.Avatar)
|
||||||
.FirstOrDefaultAsync(ct);
|
.FirstOrDefaultAsync(ct);
|
||||||
|
|
||||||
|
public async Task<T?> GetSettingByProfileId<T>(Guid profileId, string key, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
var setting = await dbContext.PlayerSettings
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(x =>
|
||||||
|
x.UserId == profileId &&
|
||||||
|
x.Key == key)
|
||||||
|
.FirstOrDefaultAsync(ct);
|
||||||
|
if (setting == null)
|
||||||
|
return default;
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<T>(setting.Value);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyList<PlayerSetting>> GetSettingsByProfileIdAsync(
|
public async Task<IReadOnlyList<PlayerSetting>> GetSettingsByProfileIdAsync(
|
||||||
Guid profileId,
|
Guid profileId,
|
||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
@@ -49,8 +64,8 @@ public class ProfileRepository(DatabaseContext dbContext) : IProfileRepository
|
|||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
=> dbContext.Profiles
|
=> dbContext.Profiles
|
||||||
.FirstOrDefaultAsync(x =>
|
.FirstOrDefaultAsync(x =>
|
||||||
x.Platform == platform &&
|
x.Platform == platform &&
|
||||||
x.PlatformId == platformId,
|
x.PlatformId == platformId,
|
||||||
ct);
|
ct);
|
||||||
|
|
||||||
public Task<Guid> GetProfileTokenVersion(
|
public Task<Guid> GetProfileTokenVersion(
|
||||||
|
|||||||
Reference in New Issue
Block a user