diff --git a/Src/ManiaAPI.NadeoAPI/ClubActivityEdition.cs b/Src/ManiaAPI.NadeoAPI/ClubActivityEdition.cs new file mode 100644 index 0000000..147a4b6 --- /dev/null +++ b/Src/ManiaAPI.NadeoAPI/ClubActivityEdition.cs @@ -0,0 +1,18 @@ +using ManiaAPI.NadeoAPI.Converters; +using System.Text.Json.Serialization; + +namespace ManiaAPI.NadeoAPI; + +public sealed record ClubActivityEdition +{ + [JsonConverter(typeof(BoolNumberConverter))] + public bool Featured { get; init; } + + [JsonConverter(typeof(BoolNumberConverter))] + public bool Public { get; init; } + + [JsonConverter(typeof(BoolNumberConverter))] + public bool Active { get; init; } + + public int Position { get; init; } +} diff --git a/Src/ManiaAPI.NadeoAPI/Converters/BoolNumberConverter.cs b/Src/ManiaAPI.NadeoAPI/Converters/BoolNumberConverter.cs new file mode 100644 index 0000000..6d3edf2 --- /dev/null +++ b/Src/ManiaAPI.NadeoAPI/Converters/BoolNumberConverter.cs @@ -0,0 +1,19 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace ManiaAPI.NadeoAPI.Converters; + +internal sealed class BoolNumberConverter : JsonConverter +{ + public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var number = reader.GetInt32(); + + return number == 1; + } + + public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) + { + writer.WriteNumberValue(value ? 1 : 0); + } +} \ No newline at end of file diff --git a/Src/ManiaAPI.NadeoAPI/JsonContexts/NadeoAPIJsonContext.cs b/Src/ManiaAPI.NadeoAPI/JsonContexts/NadeoAPIJsonContext.cs index 2556ddb..3bc47fb 100644 --- a/Src/ManiaAPI.NadeoAPI/JsonContexts/NadeoAPIJsonContext.cs +++ b/Src/ManiaAPI.NadeoAPI/JsonContexts/NadeoAPIJsonContext.cs @@ -36,5 +36,6 @@ namespace ManiaAPI.NadeoAPI.JsonContexts; [JsonSerializable(typeof(ClubRoomCollection))] [JsonSerializable(typeof(ClubBucketCollection))] [JsonSerializable(typeof(ClubPlayerInfo))] -[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +[JsonSerializable(typeof(ClubActivityEdition))] +[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] internal sealed partial class NadeoAPIJsonContext : JsonSerializerContext { } diff --git a/Src/ManiaAPI.NadeoAPI/NadeoLiveServices.cs b/Src/ManiaAPI.NadeoAPI/NadeoLiveServices.cs index af223a0..ab11117 100644 --- a/Src/ManiaAPI.NadeoAPI/NadeoLiveServices.cs +++ b/Src/ManiaAPI.NadeoAPI/NadeoLiveServices.cs @@ -31,10 +31,12 @@ public interface INadeoLiveServices : INadeoAPI Task GetClubRoomAsync(int clubId, int roomId, CancellationToken cancellationToken = default); Task GetClubRoomsAsync(int length, int offset = 0, string? name = null, CancellationToken cancellationToken = default); Task GetClubBucketsAsync(ClubBucketType type, int length, int offset = 0, CancellationToken cancellationToken = default); + Task GetClubBucketsAsync(string type, int length, int offset = 0, CancellationToken cancellationToken = default); Task GetClubBucketAsync(int clubId, int bucketId, int length = 1, int offset = 0, CancellationToken cancellationToken = default); Task GetClubsAsync(int length, int offset = 0, string? name = null, CancellationToken cancellationToken = default); Task GetClubPlayerInfoAsync(CancellationToken cancellationToken = default); Task GetMyClubsAsync(int length, int offset = 0, CancellationToken cancellationToken = default); + Task EditClubActivityAsync(int clubId, int activityId, ClubActivityEdition edition, CancellationToken cancellationToken = default); /// /// Requests the daily channel join link. It can vary based on server occupancy. @@ -206,7 +208,12 @@ public virtual async Task GetClubBucketsAsync(ClubBucketTy _ => throw new ArgumentOutOfRangeException(nameof(type)) }; - return await GetJsonAsync($"token/club/bucket/{typeStr}/all?length={length}&offset={offset}", + return await GetClubBucketsAsync(typeStr, length, offset, cancellationToken); + } + + public virtual async Task GetClubBucketsAsync(string type, int length, int offset = 0, CancellationToken cancellationToken = default) + { + return await GetJsonAsync($"token/club/bucket/{type}/all?length={length}&offset={offset}", NadeoAPIJsonContext.Default.ClubBucketCollection, cancellationToken); } @@ -232,4 +239,10 @@ public virtual async Task GetMyClubsAsync(int length, int offset return await GetJsonAsync($"token/club/mine?length={length}&offset={offset}", NadeoAPIJsonContext.Default.ClubCollection, cancellationToken); } + + public virtual async Task EditClubActivityAsync(int clubId, int activityId, ClubActivityEdition edition, CancellationToken cancellationToken = default) + { + var jsonContent = JsonContent.Create(edition, NadeoAPIJsonContext.Default.ClubActivityEdition); + await SendAsync(HttpMethod.Post, $"token/club/{clubId}/activity/{activityId}/edit", jsonContent, cancellationToken); + } }