Inventory enhancements
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Character API / deploy (push) Successful in 46s
Deploy Promiscuity Inventory API / deploy (push) Successful in 58s
Deploy Promiscuity Locations API / deploy (push) Successful in 44s
k8s smoke test / test (push) Successful in 7s
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Character API / deploy (push) Successful in 46s
Deploy Promiscuity Inventory API / deploy (push) Successful in 58s
Deploy Promiscuity Locations API / deploy (push) Successful in 44s
k8s smoke test / test (push) Successful in 7s
This commit is contained in:
@@ -17,6 +17,63 @@ public class InventoryController : ControllerBase
|
||||
_inventory = inventory;
|
||||
}
|
||||
|
||||
[HttpGet("item-definitions")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> ListItemDefinitions()
|
||||
{
|
||||
var definitions = await _inventory.ListItemDefinitionsAsync();
|
||||
return Ok(definitions.Select(ItemDefinitionResponse.FromModel).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("item-definitions/{itemKey}")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> GetItemDefinition(string itemKey)
|
||||
{
|
||||
var definition = await _inventory.GetItemDefinitionAsync(itemKey);
|
||||
if (definition is null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(ItemDefinitionResponse.FromModel(definition));
|
||||
}
|
||||
|
||||
[HttpPost("item-definitions")]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> CreateItemDefinition([FromBody] CreateItemDefinitionRequest req)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(req.ItemKey))
|
||||
return BadRequest("itemKey required");
|
||||
if (string.IsNullOrWhiteSpace(req.DisplayName))
|
||||
return BadRequest("displayName required");
|
||||
if (req.MaxStackSize <= 0)
|
||||
return BadRequest("maxStackSize must be greater than 0");
|
||||
if (!req.Stackable && req.MaxStackSize != 1)
|
||||
return BadRequest("Non-stackable items must have maxStackSize of 1");
|
||||
|
||||
var created = await _inventory.CreateItemDefinitionAsync(req);
|
||||
if (created is null)
|
||||
return Conflict("Item definition already exists");
|
||||
|
||||
return Ok(ItemDefinitionResponse.FromModel(created));
|
||||
}
|
||||
|
||||
[HttpPut("item-definitions/{itemKey}")]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> UpdateItemDefinition(string itemKey, [FromBody] UpdateItemDefinitionRequest req)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(req.DisplayName))
|
||||
return BadRequest("displayName required");
|
||||
if (req.MaxStackSize <= 0)
|
||||
return BadRequest("maxStackSize must be greater than 0");
|
||||
if (!req.Stackable && req.MaxStackSize != 1)
|
||||
return BadRequest("Non-stackable items must have maxStackSize of 1");
|
||||
|
||||
var updated = await _inventory.UpdateItemDefinitionAsync(itemKey, req);
|
||||
if (updated is null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(ItemDefinitionResponse.FromModel(updated));
|
||||
}
|
||||
|
||||
[HttpGet("by-owner/{ownerType}/{ownerId}")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> GetByOwner(string ownerType, string ownerId)
|
||||
@@ -63,7 +120,11 @@ public class InventoryController : ControllerBase
|
||||
if (!access.IsAuthorized)
|
||||
return Forbid();
|
||||
|
||||
var items = await _inventory.GrantAsync(access, req);
|
||||
var definition = await _inventory.GetItemDefinitionAsync(req.ItemKey);
|
||||
if (definition is null)
|
||||
return BadRequest("Unknown itemKey");
|
||||
|
||||
var items = await _inventory.GrantAsync(access, req, definition);
|
||||
return Ok(new InventoryOwnerResponse
|
||||
{
|
||||
OwnerType = access.OwnerType,
|
||||
|
||||
Reference in New Issue
Block a user