Kill switch
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Crafting API / deploy (push) Has been cancelled
Deploy Promiscuity Inventory API / deploy (push) Has been cancelled
Deploy Promiscuity Locations API / deploy (push) Has been cancelled
Deploy Promiscuity Mail API / deploy (push) Has been cancelled
Deploy Promiscuity World API / deploy (push) Has been cancelled
Deploy Promiscuity Character API / deploy (push) Has been cancelled
k8s smoke test / test (push) Has been cancelled

This commit is contained in:
Zeeshaun
2026-04-01 20:22:05 +00:00
parent bed8e91bc0
commit c718fb343d
14 changed files with 413 additions and 15 deletions
@@ -48,6 +48,28 @@ public class InventoryController : ControllerBase
return Ok(response);
}
[HttpPost("internal/location-owner/reassign")]
public async Task<IActionResult> ReassignLocationOwnerInventoryInternal([FromBody] InternalReassignLocationInventoryRequest req)
{
var configuredKey = (HttpContext.RequestServices.GetRequiredService<IConfiguration>()["InternalApi:Key"]
?? HttpContext.RequestServices.GetRequiredService<IConfiguration>()["Jwt:Key"]
?? string.Empty).Trim();
var requestKey = (Request.Headers["X-Internal-Api-Key"].FirstOrDefault() ?? string.Empty).Trim();
if (string.IsNullOrWhiteSpace(configuredKey) || !string.Equals(configuredKey, requestKey, StringComparison.Ordinal))
return Unauthorized();
if (string.IsNullOrWhiteSpace(req.ToOwnerId))
return BadRequest("toOwnerId required");
var result = await _inventory.ReassignLocationInventoryOwnersAsync(req.FromOwnerIds, req.ToOwnerId);
if (!result.TargetLocationExists)
return NotFound("Target location not found");
return Ok(new InternalReassignLocationInventoryResponse
{
ReassignedItemCount = result.ReassignedItemCount
});
}
[HttpGet("item-definitions")]
[Authorize(Roles = "USER,SUPER")]
public async Task<IActionResult> ListItemDefinitions()
@@ -0,0 +1,8 @@
namespace InventoryApi.Models;
public class InternalReassignLocationInventoryRequest
{
public List<string> FromOwnerIds { get; set; } = [];
public string ToOwnerId { get; set; } = string.Empty;
}
@@ -0,0 +1,6 @@
namespace InventoryApi.Models;
public class InternalReassignLocationInventoryResponse
{
public int ReassignedItemCount { get; set; }
}
@@ -22,6 +22,7 @@ public class InventoryStore
private readonly string _dbName;
public sealed record GrantResult(List<InventoryItem> Items, int RequestedQuantity, int GrantedQuantity, int OverflowQuantity);
public sealed record ReassignLocationInventoryResult(bool TargetLocationExists, int ReassignedItemCount);
public InventoryStore(IConfiguration cfg)
{
@@ -114,6 +115,35 @@ public class InventoryStore
.ToDictionary(group => group.Key, group => group.ToList(), StringComparer.Ordinal);
}
public async Task<ReassignLocationInventoryResult> ReassignLocationInventoryOwnersAsync(IEnumerable<string> fromOwnerIds, string toOwnerId)
{
var normalizedToOwnerId = toOwnerId.Trim();
var targetExists = await _locations.Find(location => location.Id == normalizedToOwnerId).AnyAsync();
if (!targetExists)
return new ReassignLocationInventoryResult(false, 0);
var sourceOwnerIds = fromOwnerIds
.Where(id => !string.IsNullOrWhiteSpace(id))
.Select(id => id.Trim())
.Where(id => !string.Equals(id, normalizedToOwnerId, StringComparison.Ordinal))
.Distinct(StringComparer.Ordinal)
.ToList();
if (sourceOwnerIds.Count == 0)
return new ReassignLocationInventoryResult(true, 0);
var filter = Builders<InventoryItem>.Filter.And(
Builders<InventoryItem>.Filter.Eq(item => item.OwnerType, LocationOwnerType),
Builders<InventoryItem>.Filter.In(item => item.OwnerId, sourceOwnerIds));
var update = Builders<InventoryItem>.Update
.Set(item => item.OwnerId, normalizedToOwnerId)
.Set(item => item.OwnerUserId, null)
.Unset(item => item.Slot)
.Unset(item => item.EquippedSlot)
.Set(item => item.UpdatedUtc, DateTime.UtcNow);
var result = await _items.UpdateManyAsync(filter, update);
return new ReassignLocationInventoryResult(true, (int)result.ModifiedCount);
}
public Task<List<ItemDefinition>> ListItemDefinitionsAsync() =>
_definitions.Find(Builders<ItemDefinition>.Filter.Empty).SortBy(d => d.ItemKey).ToListAsync();