feat: allow for the current loadout to be correctly saved (saveLoadout) and then returned in the getInventory call.

This commit is contained in:
Michael Hannigan
2025-11-10 17:51:33 -06:00
parent dc969c707b
commit 343e68364e
8 changed files with 85 additions and 7 deletions

View File

@@ -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<PlayerLoadout>(this.HttpContext);
var result = _updateLoadoutHandler.Handle(updateLoadout);
if (result.UpdateLoadoutResultStatus == UpdateLoadoutResultStatus.Success)
{

View File

@@ -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<PlayerLoadout>(player.CurrentLoadout) : null,
};
}

View File

@@ -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<GetInventoryResultJsonBoosterItem> Boosters { get; set; }
[JsonPropertyName("CurrentLoadout")]
public PlayerLoadout CurrentLoadout { get; set; }
}

View File

@@ -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; }
}
}

View File

@@ -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;

View File

@@ -11,4 +11,32 @@
DatabaseErrors,
Success
}
}
}
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; }
}

View File

@@ -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();
}
}
}

View File

@@ -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; }
}