Add avatar support
This commit is contained in:
@@ -24,6 +24,37 @@ public class ProfileService(
|
||||
: mapper.Map<ProfileDTO>(profile);
|
||||
}
|
||||
|
||||
public async Task<AvatarDTO?> GetAvatarAsync(Guid profileId, CancellationToken ct = default)
|
||||
{
|
||||
var avatar = await profileRepository.GetAvatarByProfileIdAsync(profileId, ct);
|
||||
|
||||
return avatar is null
|
||||
? null
|
||||
: mapper.Map<AvatarDTO>(avatar);
|
||||
}
|
||||
|
||||
public async Task<AvatarDTO?> UpdateAvatarAsync(
|
||||
Guid profileId,
|
||||
UpdateAvatarCommand command,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var profile = await profileRepository.GetByIdAsync(profileId, ct);
|
||||
if (profile is null)
|
||||
return null;
|
||||
|
||||
profile.SetAvatar(
|
||||
Avatar.Create(
|
||||
command.OutfitSelections,
|
||||
command.SkinColor,
|
||||
command.HairColor
|
||||
)
|
||||
);
|
||||
|
||||
await profileRepository.SaveChangesAsync(ct);
|
||||
|
||||
return mapper.Map<AvatarDTO>(profile.Avatar);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(
|
||||
List<Guid> profileIds,
|
||||
CancellationToken ct = default)
|
||||
@@ -44,21 +75,21 @@ public class ProfileService(
|
||||
var isValidGameVersion = await gameVersionRepository.IsValidAsync(command.AppVersion, ct);
|
||||
if (!isValidGameVersion)
|
||||
return LoginProfileResult.Fail("Invalid app version.");
|
||||
|
||||
|
||||
// 2. Validate Platform Authentication
|
||||
var validator = validators.FirstOrDefault(x => x.PlatformType == command.PlatformType);
|
||||
if (validator is null)
|
||||
return LoginProfileResult.Fail("Invalid platform type");
|
||||
|
||||
|
||||
var ignoreAuthValidation = await configService.GetAsync("Profiles:IgnoreAuthValidation", true, ct);
|
||||
|
||||
|
||||
var auth = await validator.ValidateAsync(
|
||||
command.PlatformAuthentication,
|
||||
command.PlatformId,
|
||||
ct);
|
||||
if (!auth.Succeeded && !ignoreAuthValidation)
|
||||
return LoginProfileResult.Fail($"Platform Auth Failed: {auth.Message}");
|
||||
|
||||
|
||||
// 3. Get or Create Profile
|
||||
var profile = await profileRepository.GetByPlatform(
|
||||
command.PlatformType,
|
||||
@@ -68,7 +99,7 @@ public class ProfileService(
|
||||
if (profile is null)
|
||||
{
|
||||
var name = await nameGenerator.GenerateAsync(ct);
|
||||
|
||||
|
||||
profile = ProfileEntity.Create(
|
||||
name,
|
||||
command.PlatformType,
|
||||
@@ -76,7 +107,7 @@ public class ProfileService(
|
||||
|
||||
await profileRepository.AddAsync(profile, ct);
|
||||
}
|
||||
|
||||
|
||||
if (profile.IsBanned)
|
||||
return LoginProfileResult.Fail("Profile is banned");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user