Add avatar support
This commit is contained in:
@@ -8,5 +8,6 @@ public class ApplicationMappingProfile : Profile
|
||||
public ApplicationMappingProfile()
|
||||
{
|
||||
CreateMap<Domain.Profiles.Profile, ProfileDTO>();
|
||||
CreateMap<Domain.Profiles.Avatar, AvatarDTO>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
src/RecNet.Application/Profiles/AvatarDto.cs
Normal file
15
src/RecNet.Application/Profiles/AvatarDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RecNet.Application.Profiles;
|
||||
|
||||
public class AvatarDTO
|
||||
{
|
||||
[JsonPropertyName("OutfitSelections")]
|
||||
public required string OutfitSelections { get; init; }
|
||||
|
||||
[JsonPropertyName("SkinColor")]
|
||||
public required string SkinColor { get; init; }
|
||||
|
||||
[JsonPropertyName("HairColor")]
|
||||
public required string HairColor { get; init; }
|
||||
}
|
||||
@@ -3,6 +3,8 @@ namespace RecNet.Application.Profiles;
|
||||
public interface IProfileService
|
||||
{
|
||||
Task<ProfileDTO?> GetProfileAsync(Guid profileId, CancellationToken ct = default);
|
||||
Task<AvatarDTO?> GetAvatarAsync(Guid profileId, CancellationToken ct = default);
|
||||
Task<AvatarDTO?> UpdateAvatarAsync(Guid profileId, UpdateAvatarCommand command, CancellationToken ct = default);
|
||||
Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(List<Guid> profileIds, CancellationToken ct = default);
|
||||
Task<LoginProfileResult> LoginAsync(LoginProfileCommand command, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
6
src/RecNet.Application/Profiles/UpdateAvatarCommand.cs
Normal file
6
src/RecNet.Application/Profiles/UpdateAvatarCommand.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace RecNet.Application.Profiles;
|
||||
|
||||
public sealed record UpdateAvatarCommand(
|
||||
string? OutfitSelections,
|
||||
string? SkinColor,
|
||||
string? HairColor);
|
||||
Reference in New Issue
Block a user