Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis committed Jun 8, 2024
1 parent 7dc66d4 commit 041a89c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace DragaliaAPI.Shared.Definitions.Enums;
/// </summary>
public enum VariationTypes
{
None = 0,
Normal = 1,
Hard = 2,
VeryHard = 3,
Expand Down
12 changes: 8 additions & 4 deletions DragaliaAPI/DragaliaAPI/Extensions/DistributedCacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ public static class DistributedCacheExtensions
{
public static async Task<TObject?> GetJsonAsync<TObject>(
this IDistributedCache cache,
string key
string key,
CancellationToken cancellationToken = default
)
where TObject : class
{
string? json = await cache.GetStringAsync(key);
string? json = await cache.GetStringAsync(key, cancellationToken);
if (json == null)
{
return default;
}

return JsonSerializer.Deserialize<TObject>(json);
}
Expand All @@ -21,6 +24,7 @@ public static Task SetJsonAsync(
this IDistributedCache cache,
string key,
object entry,
DistributedCacheEntryOptions options
) => cache.SetStringAsync(key, JsonSerializer.Serialize(entry), options);
DistributedCacheEntryOptions options,
CancellationToken cancellationToken = default
) => cache.SetStringAsync(key, JsonSerializer.Serialize(entry), options, cancellationToken);
}
12 changes: 4 additions & 8 deletions DragaliaAPI/DragaliaAPI/Features/Dungeon/DungeonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ public async Task<DungeonSession> GetSession(
CancellationToken cancellationToken
)
{
string json =
await cache.GetStringAsync(
DungeonSession session =
await cache.GetJsonAsync<DungeonSession>(
Schema.DungeonKey_DungeonData(playerIdentityService.ViewerId, dungeonKey),
cancellationToken
) ?? throw new DungeonException(dungeonKey);

DungeonSession session =
JsonSerializer.Deserialize<DungeonSession>(json)
?? throw new JsonException("Could not deserialize dungeon session.");

this.currentSession = session;
this.currentKey = dungeonKey;

Expand All @@ -69,9 +65,9 @@ public async Task SaveSession(CancellationToken cancellationToken)
);
}

await cache.SetStringAsync(
await cache.SetJsonAsync(
Schema.DungeonKey_DungeonData(playerIdentityService.ViewerId, this.currentKey),
JsonSerializer.Serialize(this.currentSession),
this.currentSession,
CacheOptions,
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using DragaliaAPI.Shared.Definitions.Enums;
using DragaliaAPI.Shared.MasterAsset.Models;

namespace DragaliaAPI.Models;
namespace DragaliaAPI.Features.Dungeon;

public record DungeonSession
public class DungeonSession
{
public required IEnumerable<PartySettingList> Party { get; init; }

Expand All @@ -26,9 +26,9 @@ public record DungeonSession

public int WallLevel { get; init; }

public int QuestId => QuestData?.Id ?? 0;
public int QuestId => this.QuestData?.Id ?? 0;

public int QuestGid => QuestData?.Gid ?? 0;
public int QuestGid => this.QuestData?.Gid ?? 0;

public VariationTypes QuestVariation => QuestData?.VariationType ?? VariationTypes.Normal;
public VariationTypes QuestVariation => this.QuestData?.VariationType ?? VariationTypes.None;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Task<IngameData> GetWallIngameData(
ulong? supportViewerId
);

Task SaveSession(CancellationToken cancellationToken = default);
Task SaveSession(CancellationToken cancellationToken);
}
3 changes: 2 additions & 1 deletion DragaliaAPI/DragaliaAPI/Features/Quest/IQuestService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DragaliaAPI.Features.Player;
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Features.Player;
using DragaliaAPI.Models;
using DragaliaAPI.Models.Generated;

Expand Down
1 change: 1 addition & 0 deletions DragaliaAPI/DragaliaAPI/Features/Quest/QuestService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DragaliaAPI.Database.Entities;
using DragaliaAPI.Database.Repositories;
using DragaliaAPI.Features.Dungeon;
using DragaliaAPI.Features.Missions;
using DragaliaAPI.Features.Player;
using DragaliaAPI.Features.Reward;
Expand Down

0 comments on commit 041a89c

Please sign in to comment.