Speeding up visible location call
Deploy Promiscuity Auth API / deploy (push) Successful in 46s
Deploy Promiscuity Character API / deploy (push) Successful in 57s
Deploy Promiscuity Inventory API / deploy (push) Successful in 59s
Deploy Promiscuity Locations API / deploy (push) Successful in 58s
k8s smoke test / test (push) Successful in 8s
Deploy Promiscuity Auth API / deploy (push) Successful in 46s
Deploy Promiscuity Character API / deploy (push) Successful in 57s
Deploy Promiscuity Inventory API / deploy (push) Successful in 59s
Deploy Promiscuity Locations API / deploy (push) Successful in 58s
k8s smoke test / test (push) Successful in 8s
This commit is contained in:
@@ -17,6 +17,37 @@ public class InventoryController : ControllerBase
|
||||
_inventory = inventory;
|
||||
}
|
||||
|
||||
[HttpPost("internal/by-owner/{ownerType}")]
|
||||
public async Task<IActionResult> GetByOwnersInternal(string ownerType, [FromBody] InternalOwnerInventoryBatchRequest 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();
|
||||
|
||||
var normalizedOwnerType = ownerType.Trim().ToLowerInvariant();
|
||||
if (normalizedOwnerType is not ("character" or "location"))
|
||||
return BadRequest("Unsupported ownerType");
|
||||
|
||||
var groupedItems = await _inventory.GetByOwnersAsync(normalizedOwnerType, req.OwnerIds);
|
||||
var ownerIds = req.OwnerIds
|
||||
.Where(id => !string.IsNullOrWhiteSpace(id))
|
||||
.Select(id => id.Trim())
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToList();
|
||||
|
||||
var response = ownerIds.Select(ownerId => new OwnerInventorySummaryResponse
|
||||
{
|
||||
OwnerType = normalizedOwnerType,
|
||||
OwnerId = ownerId,
|
||||
Items = groupedItems.GetValueOrDefault(ownerId, []).Select(InventoryItemResponse.FromModel).ToList()
|
||||
}).ToList();
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("item-definitions")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> ListItemDefinitions()
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace InventoryApi.Models;
|
||||
|
||||
public class InternalOwnerInventoryBatchRequest
|
||||
{
|
||||
public List<string> OwnerIds { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace InventoryApi.Models;
|
||||
|
||||
public class OwnerInventorySummaryResponse
|
||||
{
|
||||
public string OwnerType { get; set; } = string.Empty;
|
||||
|
||||
public string OwnerId { get; set; } = string.Empty;
|
||||
|
||||
public List<InventoryItemResponse> Items { get; set; } = [];
|
||||
}
|
||||
@@ -88,6 +88,32 @@ public class InventoryStore
|
||||
.ThenBy(i => i.ItemKey)
|
||||
.ToListAsync();
|
||||
|
||||
public async Task<Dictionary<string, List<InventoryItem>>> GetByOwnersAsync(string ownerType, IEnumerable<string> ownerIds)
|
||||
{
|
||||
var normalizedOwnerType = NormalizeOwnerType(ownerType);
|
||||
if (normalizedOwnerType is null)
|
||||
return [];
|
||||
|
||||
var ids = ownerIds
|
||||
.Where(id => !string.IsNullOrWhiteSpace(id))
|
||||
.Select(id => id.Trim())
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToList();
|
||||
if (ids.Count == 0)
|
||||
return [];
|
||||
|
||||
var items = await _items.Find(i => i.OwnerType == normalizedOwnerType && ids.Contains(i.OwnerId))
|
||||
.SortBy(i => i.OwnerId)
|
||||
.ThenBy(i => i.EquippedSlot)
|
||||
.ThenBy(i => i.Slot)
|
||||
.ThenBy(i => i.ItemKey)
|
||||
.ToListAsync();
|
||||
|
||||
return items
|
||||
.GroupBy(item => item.OwnerId, StringComparer.Ordinal)
|
||||
.ToDictionary(group => group.Key, group => group.ToList(), StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public Task<List<ItemDefinition>> ListItemDefinitionsAsync() =>
|
||||
_definitions.Find(Builders<ItemDefinition>.Filter.Empty).SortBy(d => d.ItemKey).ToListAsync();
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"InternalApi": {
|
||||
"Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5003" } } },
|
||||
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
|
||||
"InternalApi": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!" },
|
||||
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
|
||||
"Logging": { "LogLevel": { "Default": "Information" } },
|
||||
"AllowedHosts": "*"
|
||||
|
||||
Reference in New Issue
Block a user