mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RadicadeServer.API.Rooms;
|
|
using RadicadeServer.API.Rooms.V1;
|
|
using RadicadeServer.DB;
|
|
|
|
namespace RadicadeServer.API.Rooms
|
|
{
|
|
[Route("api/roomconsumables/v1")]
|
|
[Route("econ/api/roomconsumables/v1")]
|
|
public class RoomConsumablesAPI(RecDBContext db) : Controller
|
|
{
|
|
[HttpGet("roomConsumable/room/{roomId:long}")]
|
|
public async Task<IActionResult> GetRoomConsumablesInRoom(long roomId)
|
|
{
|
|
return Ok(await RoomAssetStore.GetDtosAsync(db, roomId, "consumable"));
|
|
}
|
|
|
|
[HttpGet("roomConsumable/room/{roomId:long}/me")]
|
|
public IActionResult GetOwnedRoomConsumablesInRoom(long roomId)
|
|
{
|
|
return Ok(Array.Empty<object>());
|
|
}
|
|
|
|
[HttpPut("roomConsumable")]
|
|
[HttpPost("roomConsumable")]
|
|
public async Task<IActionResult> CreateRoomConsumable()
|
|
{
|
|
var body = await RoomEconomyPayload.ReadBodyAsync(Request);
|
|
var roomId = await RoomEconomyPayload.RoomIdAsync(db, Request, body, "roomId", "RoomId");
|
|
if (roomId is not > 0) return BadRequest(new { Message = "roomId is required." });
|
|
var consumableId = RoomEconomyPayload.String(body, "consumableId", "ConsumableId") ?? RoomEconomyPayload.NewId();
|
|
|
|
var consumable = RoomEconomyPayload.Fields(body);
|
|
consumable["ConsumableId"] = consumableId;
|
|
consumable["RoomId"] = roomId.Value;
|
|
consumable["Name"] = RoomEconomyPayload.String(body, "name", "Name") ?? "Consumable";
|
|
consumable["Description"] = RoomEconomyPayload.String(body, "description", "Description") ?? string.Empty;
|
|
|
|
await RoomAssetStore.SaveAsync(db, new RoomAssetRecord
|
|
{
|
|
Id = consumableId,
|
|
RoomId = roomId.Value,
|
|
Kind = "consumable",
|
|
Fields = consumable
|
|
});
|
|
|
|
return Ok(consumable);
|
|
}
|
|
}
|
|
}
|