Add player settings feature and settings API

This commit is contained in:
Holden
2026-06-20 22:58:33 -05:00
parent f4887c3f93
commit e77e479493
17 changed files with 405 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
namespace RecNet.Application.Profiles;
public interface IProfileService
@@ -5,6 +6,8 @@ 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<PlayerSettingDTO>> GetPlayerSettingsAsync(Guid profileId, CancellationToken ct = default);
Task<bool> UpdatePlayerSettingAsync(Guid profileId, UpdatePlayerSettingCommand command, CancellationToken ct = default);
Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(List<Guid> profileIds, CancellationToken ct = default);
Task<LoginProfileResult> LoginAsync(LoginProfileCommand command, CancellationToken ct = default);
}

View File

@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace RecNet.Application.Profiles;
public class PlayerSettingDTO
{
[JsonPropertyName("Key")]
public required string Key { get; set; }
[JsonPropertyName("Value")]
public required string Value { get; set; }
}

View File

@@ -55,6 +55,31 @@ public class ProfileService(
return mapper.Map<AvatarDTO>(profile.Avatar);
}
public async Task<IReadOnlyList<PlayerSettingDTO>> GetPlayerSettingsAsync(
Guid profileId,
CancellationToken ct = default)
{
var settings = await profileRepository.GetSettingsByProfileIdAsync(profileId, ct);
return mapper.Map<List<PlayerSettingDTO>>(settings);
}
public async Task<bool> UpdatePlayerSettingAsync(
Guid profileId,
UpdatePlayerSettingCommand command,
CancellationToken ct = default)
{
var profile = await profileRepository.GetByIdWithSettingsAsync(profileId, ct);
if (profile is null)
return false;
profile.SetSetting(command.Key, command.Value);
await profileRepository.SaveChangesAsync(ct);
return true;
}
public async Task<IReadOnlyList<ProfileDTO>> GetProfilesAsync(
List<Guid> profileIds,
CancellationToken ct = default)
@@ -123,4 +148,4 @@ public class ProfileService(
expiresIn: token.ExpiresIn
);
}
}
}

View File

@@ -0,0 +1,5 @@
namespace RecNet.Application.Profiles;
public sealed record UpdatePlayerSettingCommand(
string Key,
string Value);