초기커밋
This commit is contained in:
125
BrokerApiServer/Controllers/AdminController.cs
Normal file
125
BrokerApiServer/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServerCommon;
|
||||
using BrokerCore.ApiModels;
|
||||
using BrokerCore.Services;
|
||||
|
||||
namespace BrokerApiServer.Controllers;
|
||||
|
||||
using BrokerCore.Common;
|
||||
using BrokerCore.DbEntity;
|
||||
|
||||
using Common;
|
||||
using ServerBase;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
[Route("api/v1/admin")]
|
||||
[ApiController]
|
||||
// 운영자만 접근 가능한 컨트롤러
|
||||
public class AdminController : ControllerBase
|
||||
{
|
||||
private readonly PlanetItemExchangeService m_exchange_service;
|
||||
private readonly UserAuthService m_user_auth_service;
|
||||
|
||||
public AdminController(PlanetItemExchangeService exchangeService, UserAuthService userAuthService)
|
||||
{
|
||||
m_exchange_service = exchangeService;
|
||||
m_user_auth_service = userAuthService;
|
||||
}
|
||||
|
||||
[SwaggerIgnore]
|
||||
[HttpPost("sapphire_change"), RequireAdminAuth]
|
||||
public async Task<IActionResult> userSapphireChange(AdminSapphireChangeRequest request)
|
||||
{
|
||||
Guard.Against.isTrue(
|
||||
string.IsNullOrEmpty(request.UserGuid) && string.IsNullOrEmpty(request.Email) &&
|
||||
string.IsNullOrEmpty(request.AccountId),
|
||||
ServerErrorCode.InvalidRequest, ()=>"email 과 userguid의 값이 모두 비어 있음");
|
||||
|
||||
var user_guid = request.UserGuid;
|
||||
if (string.IsNullOrEmpty(user_guid))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(request.Email))
|
||||
{
|
||||
await m_user_auth_service.authFromEmail(request.Email);
|
||||
user_guid = m_user_auth_service.UserGuid;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(request.AccountId))
|
||||
{
|
||||
await m_user_auth_service.authByAccount(request.AccountId);
|
||||
user_guid = m_user_auth_service.UserGuid;
|
||||
}
|
||||
else
|
||||
{
|
||||
Guard.Against.throwException(ServerErrorCode.InvalidRequest, ()=>"요청에 오류가 있음");
|
||||
}
|
||||
}
|
||||
|
||||
var dynamo_db_client = m_user_auth_service.ServerLogic.getDynamoDbClient();
|
||||
CurrencyControlHelper.setDbConnector(dynamo_db_client);
|
||||
var (result, sapphire_current_amount_double) =
|
||||
await CurrencyControlHelper.earnMoneyByUserGuid(user_guid, CurrencyType.Sapphire, request.SapphireDelta);
|
||||
Guard.Against.resultFail(result);
|
||||
return Ok(new AdminSapphireChangeResponse
|
||||
{
|
||||
AccountId = request.AccountId,
|
||||
Email = request.Email,
|
||||
UserGuid = request.UserGuid,
|
||||
SapphireDelta = request.SapphireDelta,
|
||||
SapphireCurrentAmount = Convert.ToInt64(sapphire_current_amount_double)
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("exchange/order/list"), RequireAdminAuth]
|
||||
[Produces("application/json")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PlanetItemExchangeOrderListResponse))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ApiErrorResponse))]
|
||||
[SwaggerOperation(Summary = "교환 주문 목록 조회 [Bearer 인증 필요]")]
|
||||
public async Task<IActionResult> getOrders(
|
||||
[SwaggerRequestBody] AdminItemExchangeOrderListRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// var user_guid = request.UserGuid;
|
||||
// var account_id = request.SsoAccountId;
|
||||
// await m_exchange_service.validateAndGetUser(account_id, user_guid, planet_id);
|
||||
// user_guid = m_exchange_service.PlanetUser.UserGuid;
|
||||
// account_id = m_exchange_service.PlanetUser.AccountId;
|
||||
|
||||
ExchangeOrderStatus? order_status = request switch
|
||||
{
|
||||
{ Option: FindOption.Completed } => ExchangeOrderStatus.Completed,
|
||||
{ Option: FindOption.Pending } => ExchangeOrderStatus.Pending,
|
||||
_ => null // 전체 조회
|
||||
};
|
||||
var account_id = request.SsoAccountId ?? string.Empty;
|
||||
var user_guid = request.UserGuid ?? string.Empty;
|
||||
var planet_id = request.PlanetId ?? string.Empty;
|
||||
var season_id = request.SeasonId ?? string.Empty;
|
||||
var exchange_meta_id = request.ExchangeMetaId ?? string.Empty;
|
||||
var page_index = request.PageIndex <= 0 ? 1 : request.PageIndex;
|
||||
var page_size = request.PageSize <= 0 ? 20 : request.PageSize;
|
||||
var (orders, total_count) =
|
||||
await m_exchange_service.findOrderList(planet_id, exchange_meta_id, season_id, user_guid, order_status, page_index,
|
||||
page_size, "desc", cancellationToken);
|
||||
|
||||
var order_dtos = orders.Select(x => new PlanetItemExchangeOrderDto
|
||||
{
|
||||
OrderId = x.OrderId,
|
||||
OrderStatus = x.OrderStatus,
|
||||
SeasonId = x.SeasonId,
|
||||
ExchangeMetaId = x.ExchangeMetaId,
|
||||
ExchangeMetaAmount = x.ExchangeMetaAmount,
|
||||
AccountId = x.AccountId,
|
||||
UserGuid = x.UserGuid,
|
||||
PlanetId = x.PlanetId,
|
||||
CaliverseItemType = x.CaliverseItemType,
|
||||
CaliverseItemId = x.CaliverseItemId,
|
||||
CaliverseItemDeltaAmount = x.CaliverseItemDeltaAmount,
|
||||
PlanetItemType = x.PlanetItemType,
|
||||
PlanetItemId = x.PlanetItemId,
|
||||
PlanetItemDeltaAmount = x.PlanetItemDeltaAmount,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CompletedAt = x.CompletedAt,
|
||||
});
|
||||
return Ok(new PlanetItemExchangeOrderListResponse { Orders = order_dtos, TotalCount = total_count });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user