mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-04-22 03:59:36 +08:00
完善 Web API 控制器
This commit is contained in:
parent
db474673fb
commit
e6c110f555
@ -13,6 +13,306 @@ namespace Milimoe.FunGame.WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ILogger<InventoryController> _logger = logger;
|
private readonly ILogger<InventoryController> _logger = logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取商店内容
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("getstore")]
|
||||||
|
public async Task<IActionResult> GetStore(long[] ids)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_getstore",
|
||||||
|
RequestType = DataRequestType.Inventory_GetStore
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> data = new()
|
||||||
|
{
|
||||||
|
{ "ids", ids }
|
||||||
|
};
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_GetStore, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取市场内容
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("getmarket")]
|
||||||
|
public async Task<IActionResult> GetMarket(long[]? users = null, MarketItemState state = MarketItemState.Listed, long[]? items = null)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_getmarket",
|
||||||
|
RequestType = DataRequestType.Inventory_GetMarket
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> data = new()
|
||||||
|
{
|
||||||
|
{ "users", users ?? [] },
|
||||||
|
{ "state", state },
|
||||||
|
{ "items", items ?? [] }
|
||||||
|
};
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_GetMarket, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商店购买物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("storebuy")]
|
||||||
|
public async Task<IActionResult> StoreBuy([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_storebuy",
|
||||||
|
RequestType = DataRequestType.Inventory_StoreBuy
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_StoreBuy, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 市场购买物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("marketbuy")]
|
||||||
|
public async Task<IActionResult> MarketBuy([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_marketbuy",
|
||||||
|
RequestType = DataRequestType.Inventory_MarketBuy
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_MarketBuy, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新库存
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("updateinventory")]
|
||||||
|
public async Task<IActionResult> UpdateInventory([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_updateinventory",
|
||||||
|
RequestType = DataRequestType.Inventory_UpdateInventory
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_UpdateInventory, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用库存物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("useitem")]
|
||||||
|
public async Task<IActionResult> Use([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_use",
|
||||||
|
RequestType = DataRequestType.Inventory_Use
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_Use, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商店出售物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("storesell")]
|
||||||
|
public async Task<IActionResult> StoreSell([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_storesell",
|
||||||
|
RequestType = DataRequestType.Inventory_StoreSell
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_StoreSell, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 市场出售物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("marketsell")]
|
||||||
|
public async Task<IActionResult> MarketSell([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_marketsell",
|
||||||
|
RequestType = DataRequestType.Inventory_MarketSell
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_MarketSell, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下架市场物品
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("marketdelist")]
|
||||||
|
public async Task<IActionResult> MarketDelist([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_marketdelist",
|
||||||
|
RequestType = DataRequestType.Inventory_MarketDelist
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_MarketDelist, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新市场价格
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("updatemarketprice")]
|
||||||
|
public async Task<IActionResult> UpdateMarketPrice([FromBody] Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "inventory_updatemarketprice",
|
||||||
|
RequestType = DataRequestType.Inventory_UpdateMarketPrice
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Inventory_UpdateMarketPrice, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取交易报价
|
/// 获取交易报价
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
104
FunGame.WebAPI/Controllers/UserCenterController.cs
Normal file
104
FunGame.WebAPI/Controllers/UserCenterController.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||||
|
using Milimoe.FunGame.WebAPI.Models;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
|
namespace Milimoe.FunGame.WebAPI.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
public class UserCenterController(RESTfulAPIModel model, ILogger<UserCenterController> logger) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<UserCenterController> _logger = logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新用户
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut("updateuser")]
|
||||||
|
public async Task<IActionResult> UpdateUser(Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "user_update",
|
||||||
|
RequestType = DataRequestType.UserCenter_UpdateUser
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.UserCenter_UpdateUser, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新密码
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut("updatepassword")]
|
||||||
|
public async Task<IActionResult> UpdatePassword(Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "user_updatepassword",
|
||||||
|
RequestType = DataRequestType.UserCenter_UpdatePassword
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.UserCenter_UpdatePassword, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每日签到
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("dailysignin")]
|
||||||
|
public async Task<IActionResult> DailySignIn(Dictionary<string, object> data)
|
||||||
|
{
|
||||||
|
PayloadModel<DataRequestType> response = new()
|
||||||
|
{
|
||||||
|
Event = "user_dailysignin",
|
||||||
|
RequestType = DataRequestType.UserCenter_DailySignIn
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.UserCenter_DailySignIn, data);
|
||||||
|
response.StatusCode = 200;
|
||||||
|
response.Data = result;
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.StatusCode = 500;
|
||||||
|
response.Message = "服务器暂时无法处理此请求。";
|
||||||
|
return StatusCode(500, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user