Add player settings feature and settings API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
12
src/RecNet.Application/Profiles/PlayerSettingDto.cs
Normal file
12
src/RecNet.Application/Profiles/PlayerSettingDto.cs
Normal 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; }
|
||||
}
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace RecNet.Application.Profiles;
|
||||
|
||||
public sealed record UpdatePlayerSettingCommand(
|
||||
string Key,
|
||||
string Value);
|
||||
Reference in New Issue
Block a user