forked from AcaMate/AcaMate_API
[✨] PUSH 삭제 API 작성
This commit is contained in:
parent
968bd33b9d
commit
aec03b9df7
|
@ -1,13 +1,15 @@
|
||||||
using AcaMate.Common.Models;
|
|
||||||
using AcaMate.V1.Models;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Update.Internal;
|
using Microsoft.EntityFrameworkCore.Update.Internal;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
|
||||||
|
|
||||||
using AcaMate.Common.Data;
|
using AcaMate.Common.Data;
|
||||||
using AcaMate.V1.Services;
|
using AcaMate.V1.Services;
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using AcaMate.Common.Models;
|
||||||
|
using AcaMate.V1.Models;
|
||||||
|
|
||||||
|
|
||||||
namespace AcaMate.V1.Controllers;
|
namespace AcaMate.V1.Controllers;
|
||||||
|
|
||||||
|
@ -79,6 +81,9 @@ public class PushController : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a push notification to the specified device token with the provided payload.
|
/// Sends a push notification to the specified device token with the provided payload.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -89,14 +94,16 @@ public class PushController : ControllerBase
|
||||||
/// <response code="500">Internal server error occurred.</response>
|
/// <response code="500">Internal server error occurred.</response>
|
||||||
/// <response code="999">Service unavailable.</response>
|
/// <response code="999">Service unavailable.</response>
|
||||||
[HttpPost("send")]
|
[HttpPost("send")]
|
||||||
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.", "푸시")]
|
[CustomOperation("푸시 발송", "저장된 양식으로, 사용자에게 푸시를 송신한다.", "푸시")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||||
public async Task<IActionResult> SendPush([FromBody] PushRequest pushRequest)
|
public async Task<IActionResult> SendPush([FromBody] PushRequest pushRequest)
|
||||||
{
|
{
|
||||||
|
string summary = String.Empty;
|
||||||
|
try {
|
||||||
|
summary = _repositoryService.ReadSummary(typeof(PushController), "SendPush");
|
||||||
|
|
||||||
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var payload = await _dbContext.DBPayload
|
var payload = await _dbContext.DBPayload
|
||||||
.Where(p => p.pid == pushRequest.pid && p.bid == pushRequest.bid)
|
.Where(p => p.pid == pushRequest.pid && p.bid == pushRequest.bid)
|
||||||
.Select(p => new Payload
|
.Select(p => new Payload
|
||||||
|
@ -149,7 +156,7 @@ public class PushController : ControllerBase
|
||||||
pushToken = pushToken,
|
pushToken = pushToken,
|
||||||
payload = payload ?? throw new PushInvalidException("payload is NULL")
|
payload = payload ?? throw new PushInvalidException("payload is NULL")
|
||||||
};
|
};
|
||||||
await _repositoryService.SaveDataFK<PushCabinet>(pushCabinet);
|
await _repositoryService.SaveData<PushCabinet>(pushCabinet);
|
||||||
|
|
||||||
_pushQueue.Enqueue(pushData);
|
_pushQueue.Enqueue(pushData);
|
||||||
}
|
}
|
||||||
|
@ -163,8 +170,7 @@ public class PushController : ControllerBase
|
||||||
catch (PushInvalidException ex)
|
catch (PushInvalidException ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex.Message);
|
_logger.LogError(ex.Message);
|
||||||
return Ok(APIResponse.Send("001", "푸시 송신: 푸시 전송 중 문제 발생",Empty));
|
return Ok(APIResponse.Send("001", $"[{summary}]: 푸시 송신 중 문제 발생",Empty));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -173,12 +179,13 @@ public class PushController : ControllerBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost("set")]
|
[HttpPost("set")]
|
||||||
[CustomOperation("푸시내용 변경", "저장된 양식을 변경한다.", "푸시")]
|
[CustomOperation("[푸시 변경]", "저장된 양식을 변경한다.", "푸시")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||||
public async Task<IActionResult> SetPush([FromBody] DBPayload request)
|
public async Task<IActionResult> SetPush([FromBody] DBPayload request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -195,8 +202,8 @@ public class PushController : ControllerBase
|
||||||
if (dbPayload.category != request.category && request.category != "") dbPayload.category = request.category;
|
if (dbPayload.category != request.category && request.category != "") dbPayload.category = request.category;
|
||||||
if (dbPayload.content != request.content) dbPayload.content = request.content;
|
if (dbPayload.content != request.content) dbPayload.content = request.content;
|
||||||
// if (await _repositoryService.SaveData<DBPayload, string>(dbPayload, p => p.pid))
|
// if (await _repositoryService.SaveData<DBPayload, string>(dbPayload, p => p.pid))
|
||||||
if (await _repositoryService.SaveDataFK<DBPayload>(dbPayload))
|
if (await _repositoryService.SaveData<DBPayload>(dbPayload))
|
||||||
return Ok(APIResponse.Send("000", "PUSH 정보 변경 완료", Empty));
|
return Ok(APIResponse.Send("000", "[푸시 변경] : PUSH 정보 변경 완료", Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(APIResponse.Send("100", "PID, BID 또는 Cabinet 오류", Empty));
|
return Ok(APIResponse.Send("100", "PID, BID 또는 Cabinet 오류", Empty));
|
||||||
|
@ -227,8 +234,10 @@ public class PushController : ControllerBase
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try
|
string summary = String.Empty;
|
||||||
{
|
try {
|
||||||
|
summary = _repositoryService.ReadSummary(typeof(PushController), "CreatePush");
|
||||||
|
|
||||||
if (await _dbContext.Academy.AnyAsync(a => a.bid == createPush.bid))
|
if (await _dbContext.Academy.AnyAsync(a => a.bid == createPush.bid))
|
||||||
{
|
{
|
||||||
DBPayload payload = new DBPayload
|
DBPayload payload = new DBPayload
|
||||||
|
@ -242,7 +251,8 @@ public class PushController : ControllerBase
|
||||||
category = createPush.category,
|
category = createPush.category,
|
||||||
content = createPush.content,
|
content = createPush.content,
|
||||||
};
|
};
|
||||||
if (await _repositoryService.SaveDataFK<DBPayload>(payload))
|
|
||||||
|
if (await _repositoryService.SaveData<DBPayload>(payload))
|
||||||
{
|
{
|
||||||
var logPush = new LogPush
|
var logPush = new LogPush
|
||||||
{
|
{
|
||||||
|
@ -250,12 +260,12 @@ public class PushController : ControllerBase
|
||||||
pid = payload.pid,
|
pid = payload.pid,
|
||||||
create_uid = uid,
|
create_uid = uid,
|
||||||
create_date = DateTime.Now,
|
create_date = DateTime.Now,
|
||||||
log = $"[CREATE] {payload.pid} 최초 생성 - {uid}"
|
log = $"[{summary}] {payload.pid} 최초 생성 - {uid}"
|
||||||
};
|
};
|
||||||
|
|
||||||
// 로그를 이제 만들어서 추가를 해야 합니다.
|
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||||
_dbContext.Set<LogPush>().Add(logPush);
|
if (await _repositoryService.SaveData<LogPush>(logPush))
|
||||||
await _dbContext.SaveChangesAsync();
|
_logger.LogInformation("[푸시 생성] 로그 추가");
|
||||||
|
|
||||||
return Ok(APIResponse.Send("000", "정상, push 저장 완료", Empty));
|
return Ok(APIResponse.Send("000", "정상, push 저장 완료", Empty));
|
||||||
}
|
}
|
||||||
|
@ -285,9 +295,48 @@ public class PushController : ControllerBase
|
||||||
[HttpDelete("delete")]
|
[HttpDelete("delete")]
|
||||||
[CustomOperation("푸시 삭제", "저장된 푸시 양식을 삭제 한다.", "푸시")]
|
[CustomOperation("푸시 삭제", "저장된 푸시 양식을 삭제 한다.", "푸시")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||||
public async Task<IActionResult> DeletePush(string bid, string pid)
|
public async Task<IActionResult> DeletePush(string token, string refresh, string bid, string pid)
|
||||||
{
|
{
|
||||||
return Ok("good");
|
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(refresh)) return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
if(!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
|
||||||
|
var validateToken = await _repositoryService.ValidateToken(token, refresh);
|
||||||
|
var uid = validateToken.uid;
|
||||||
|
|
||||||
|
string summary = String.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
summary = _repositoryService.ReadSummary(typeof(PushController), "DeletePush");
|
||||||
|
|
||||||
|
|
||||||
|
var payload = await _dbContext.DBPayload.FirstOrDefaultAsync(p => p.bid == bid && p.pid == pid);
|
||||||
|
if (await _repositoryService.DeleteData<DBPayload>(payload))
|
||||||
|
{
|
||||||
|
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||||
|
var logPush = new LogPush
|
||||||
|
{
|
||||||
|
bid = bid,
|
||||||
|
pid = pid,
|
||||||
|
create_uid = uid,
|
||||||
|
create_date = DateTime.Now,
|
||||||
|
log = $"[{summary}] {pid} 삭제 - {uid}"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||||
|
if (await _repositoryService.SaveData<LogPush>(logPush))
|
||||||
|
_logger.LogInformation($"[{summary}] 로그 추가");
|
||||||
|
|
||||||
|
return Ok(APIResponse.Send("000", "정상, push 삭제 완료", Empty));
|
||||||
|
}
|
||||||
|
return Ok(APIResponse.Send("001", "push 삭제 실패", Empty));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"{ex}");
|
||||||
|
return BadRequest(APIResponse.UnknownError());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}// END PUSH CONTROLLER
|
}// END PUSH CONTROLLER
|
||||||
|
|
Loading…
Reference in New Issue
Block a user