From 343e68364e18105d005fe45c10158d13cf6be241 Mon Sep 17 00:00:00 2001 From: Michael Hannigan Date: Mon, 10 Nov 2025 17:51:33 -0600 Subject: [PATCH] feat: allow for the current loadout to be correctly saved (saveLoadout) and then returned in the getInventory call. --- .../Controllers/InventoryController.cs | 2 +- .../Logic/Inventory/Get/GetInventoryMapper.cs | 2 + .../Logic/Inventory/Get/GetInventoryResult.cs | 4 ++ .../Logic/Inventory/Loadout/UpdateLoadout.cs | 6 ++- .../Inventory/Loadout/UpdateLoadoutHandler.cs | 7 ++-- .../Inventory/Loadout/UpdateLoadoutResult.cs | 30 +++++++++++++- .../Loadout/UpdateLoadoutValidator.cs | 2 +- .../Logic/Shared/PlayerLoadout.cs | 39 +++++++++++++++++++ 8 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs diff --git a/src/WFClassic.Web/Controllers/InventoryController.cs b/src/WFClassic.Web/Controllers/InventoryController.cs index 774bafc..36a316e 100644 --- a/src/WFClassic.Web/Controllers/InventoryController.cs +++ b/src/WFClassic.Web/Controllers/InventoryController.cs @@ -78,7 +78,7 @@ namespace WFClassic.Web.Controllers [Route("/api/saveLoadout.php")] public ActionResult SaveCurrentLoadout([FromQuery] UpdateLoadout updateLoadout) { - updateLoadout.LoadoutState = Utils.GetRequestObjectAsString(this.HttpContext); + updateLoadout.PlayerLoadout = Utils.GetRequestObject(this.HttpContext); var result = _updateLoadoutHandler.Handle(updateLoadout); if (result.UpdateLoadoutResultStatus == UpdateLoadoutResultStatus.Success) { diff --git a/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryMapper.cs b/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryMapper.cs index 37a48c7..0aaf0f3 100644 --- a/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryMapper.cs +++ b/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryMapper.cs @@ -4,6 +4,7 @@ using System.Text.Json; using WFClassic.Web.Data.Enums; using WFClassic.Web.Data.Models; +using WFClassic.Web.Logic.Shared; using WFClassic.Web.Logic.Shared.Models; namespace WFClassic.Web.Logic.Inventory.Get @@ -65,6 +66,7 @@ namespace WFClassic.Web.Logic.Inventory.Get TauntHistory = player.TauntHistoryItems.Select(s => new GetInventoryResultJsonTauntHistoryItem() { node = s.Node, state= s.State }).ToList(), Upgrades = GetUpgrade(player.InventoryItems, attachments, InternalInventoryItemType.Upgrades), Keys = GetJsonTypeCount(InternalInventoryItemType.LevelKeys, player.InventoryItems), + CurrentLoadout = !string.IsNullOrWhiteSpace(player.CurrentLoadout) ? JsonSerializer.Deserialize(player.CurrentLoadout) : null, }; } diff --git a/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryResult.cs b/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryResult.cs index 97aacc7..dd1d711 100644 --- a/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryResult.cs +++ b/src/WFClassic.Web/Logic/Inventory/Get/GetInventoryResult.cs @@ -1,5 +1,6 @@ using System.Text.Json.Serialization; +using WFClassic.Web.Logic.Shared; using WFClassic.Web.Logic.Shared.Models; namespace WFClassic.Web.Logic.Inventory.Get @@ -127,6 +128,9 @@ namespace WFClassic.Web.Logic.Inventory.Get [JsonPropertyName("Boosters")] public List Boosters { get; set; } + [JsonPropertyName("CurrentLoadout")] + public PlayerLoadout CurrentLoadout { get; set; } + } diff --git a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadout.cs b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadout.cs index f3a0b0e..62e6c01 100644 --- a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadout.cs +++ b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadout.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +using WFClassic.Web.Logic.Shared; + namespace WFClassic.Web.Logic.Inventory.Loadout { public class UpdateLoadout @@ -10,7 +12,9 @@ namespace WFClassic.Web.Logic.Inventory.Loadout [JsonPropertyName("nonce")] public long Nonce { get; set; } + + [JsonIgnore] - public string LoadoutState { get; set; } + public PlayerLoadout PlayerLoadout { get; set; } } } \ No newline at end of file diff --git a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutHandler.cs b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutHandler.cs index bce956b..d76a8e5 100644 --- a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutHandler.cs +++ b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutHandler.cs @@ -1,4 +1,6 @@ -using Microsoft.EntityFrameworkCore; +using System.Text.Json; + +using Microsoft.EntityFrameworkCore; using WFClassic.Web.Data; using WFClassic.Web.Data.Models; @@ -35,7 +37,6 @@ namespace WFClassic.Web.Logic.Inventory.Get { _logger.LogInformation("UpdateLoadoutHandler => accountId {AccountID} nonce {Nonce} => Starting Query for player", updateLoadout.AccountId, updateLoadout.Nonce); player = _applicationDbContext.Players.First(w => w.ApplicationUserId == updateLoadout.AccountId); - result.UpdateLoadoutResultStatus = UpdateLoadoutResultStatus.Success; _logger.LogInformation("UpdateLoadoutHandler => accountId {AccountID} nonce {Nonce} => Query Complete for player ", updateLoadout.AccountId, updateLoadout.Nonce); } @@ -48,7 +49,7 @@ namespace WFClassic.Web.Logic.Inventory.Get try { - player.CurrentLoadout = updateLoadout.LoadoutState; + player.CurrentLoadout = JsonSerializer.Serialize(updateLoadout.PlayerLoadout); _applicationDbContext.Entry(player).State = EntityState.Modified; _applicationDbContext.SaveChanges(); result.UpdateLoadoutResultStatus = UpdateLoadoutResultStatus.Success; diff --git a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutResult.cs b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutResult.cs index d927b62..610f862 100644 --- a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutResult.cs +++ b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutResult.cs @@ -11,4 +11,32 @@ DatabaseErrors, Success } -} \ No newline at end of file +} + + + + +public class Rootobject +{ + public ItemId ItemId { get; set; } + public string Name { get; set; } + public Preset[] Presets { get; set; } +} + +public class ItemId +{ + public string id { get; set; } +} + +public class Preset +{ + public ItemId ItemId { get; set; } + public Customization Customization { get; set; } +} + +public class Customization +{ + public string Emblem { get; set; } + public int[] Colors { get; set; } + public string[] Skins { get; set; } +} diff --git a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutValidator.cs b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutValidator.cs index 74c3dad..17e774d 100644 --- a/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutValidator.cs +++ b/src/WFClassic.Web/Logic/Inventory/Loadout/UpdateLoadoutValidator.cs @@ -8,7 +8,7 @@ namespace WFClassic.Web.Logic.Inventory.Loadout { RuleFor(r => r.AccountId).NotEmpty(); RuleFor(r => r.Nonce).GreaterThan(0); - RuleFor(r => r.LoadoutState).NotEmpty(); + RuleFor(r => r.PlayerLoadout).NotEmpty(); } } } \ No newline at end of file diff --git a/src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs b/src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs new file mode 100644 index 0000000..9ecdbc0 --- /dev/null +++ b/src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs @@ -0,0 +1,39 @@ +using System.Text.Json.Serialization; + +namespace WFClassic.Web.Logic.Shared; + + + +public class PlayerLoadout +{ + [JsonPropertyName("ItemId")] + public ItemId ItemId { get; set; } + [JsonPropertyName("Name")] + public string Name { get; set; } + [JsonPropertyName("Presets")] + public Preset[] Presets { get; set; } +} + +public class ItemId +{ + [JsonPropertyName("$id")] + public string id { get; set; } +} + +public class Preset +{ + [JsonPropertyName("ItemId")] + public ItemId ItemId { get; set; } + [JsonPropertyName("Customization")] + public Customization Customization { get; set; } +} + +public class Customization +{ + [JsonPropertyName("Emblem")] + public string Emblem { get; set; } + [JsonPropertyName("Colors")] + public int[] Colors { get; set; } + [JsonPropertyName("Skins")] + public string[] Skins { get; set; } +}