forked from AcaMate/AcaMate_API
102 lines
3.6 KiB
C#
102 lines
3.6 KiB
C#
using AcaMate.Common.Models;
|
|
using AcaMate.V1.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using AcaMate.V1.Services;
|
|
|
|
namespace AcaMate.V1.Controllers;
|
|
|
|
|
|
[ApiController]
|
|
[Route("/api/v1/in/push")]
|
|
[ApiExplorerSettings(GroupName = "공통")]
|
|
public class PushController : ControllerBase
|
|
{
|
|
|
|
private readonly IWebHostEnvironment _env;
|
|
private readonly ILogger<PushController> _logger;
|
|
private readonly IPushQueue _pushQueue;
|
|
public PushController(IWebHostEnvironment env, ILogger<PushController> logger, IPushQueue pushQueue)
|
|
{
|
|
_env = env;
|
|
_logger = logger;
|
|
_pushQueue = pushQueue;
|
|
}
|
|
|
|
[HttpGet()]
|
|
[CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다..", "푸시")]
|
|
public IActionResult GetPushData()
|
|
{
|
|
return Ok("SEND");
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Sends a push notification to the specified device token with the provided payload.
|
|
/// </summary>
|
|
/// <param name="deviceToken">The device token to send the notification to.</param>
|
|
/// <param name="payload">The payload of the push notification.</param>
|
|
/// <returns>An IActionResult indicating the result of the operation.</returns>
|
|
/// <response code="200">Push notification sent successfully.</response>
|
|
/// <response code="400">Invalid input parameters.</response>
|
|
/// <response code="500">Internal server error occurred.</response>
|
|
/// <response code="999">Service unavailable.</response>
|
|
[HttpPost("send")]
|
|
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.(로컬 테스트 불가)", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> SendPush(string deviceToken, [FromBody] Payload payload)
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(deviceToken) || payload == null)
|
|
return BadRequest(APIResponse.InvalidInputError());
|
|
|
|
var pushRequest = new PushRequest
|
|
{
|
|
deviceToken = deviceToken,
|
|
payload = payload
|
|
};
|
|
_pushQueue.Enqueue(pushRequest);
|
|
return Ok("[푸시] 접수 완료");
|
|
|
|
//
|
|
//
|
|
// var isDev = _env.IsDevelopment();
|
|
//
|
|
// var pushFileSetting = new PushFileSetting()
|
|
// {
|
|
// uri = isDev ? "https://api.sandbox.push.apple.com/" : "https://api.push.apple.com/",
|
|
// p12Path = isDev ? "/src/private/AM_Push_Sandbox.p12" : "/src/private/AM_Push.p12",
|
|
// p12PWPath = "/src/private/appleKeys.json",
|
|
// apnsTopic = "me.myds.ipstein.acamate.AcaMate"
|
|
// };
|
|
//
|
|
// try
|
|
// {
|
|
// if (await new ApnsPushService().SendPushNotificationAsync(deviceToken, pushFileSetting, payload))
|
|
// {
|
|
// return Ok(APIResponse.Send("000", "정상", Empty));
|
|
// }
|
|
// else
|
|
// {
|
|
// return StatusCode(500, APIResponse.UnknownError());
|
|
// }
|
|
//
|
|
// }
|
|
// catch (ServiceConnectionFailedException failEx)
|
|
// {
|
|
// _logger.LogError($"[푸시][에러] : {failEx}");
|
|
// return StatusCode(300, APIResponse.InternalSeverError());
|
|
// }
|
|
// catch (HttpRequestException httpEx)
|
|
// {
|
|
// _logger.LogError($"[푸시][에러] : {httpEx}");
|
|
// return StatusCode(300, APIResponse.InternalSeverError());
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError($"[푸시][에러] : {ex}");
|
|
// return StatusCode(500, APIResponse.UnknownError());
|
|
// }
|
|
}
|
|
} |