mirror of
https://github.com/mekael/WFClassic.git
synced 2025-12-30 18:19:33 -06:00
feat: allow for the current loadout to be correctly saved (saveLoadout) and then returned in the getInventory call.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs
Normal file
39
src/WFClassic.Web/Logic/Shared/PlayerLoadout.cs
Normal 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; }
|
||||
}
|
||||
Reference in New Issue
Block a user