[♻️] 푸시 로직을 아카데미와 연계시켜 bid를 사용하게 변경

This commit is contained in:
김선규 2025-03-06 13:42:49 +09:00
parent 289fe748a9
commit 8cb4207ef6
2 changed files with 64 additions and 25 deletions

View File

@ -31,8 +31,29 @@ public class PushController : ControllerBase
[HttpGet()] [HttpGet()]
[CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다..", "푸시")] [CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다..", "푸시")]
public IActionResult GetPushData() public async Task<IActionResult> GetPush(string? pid)
{ {
if (pid != null)
{
var pushData = await _dbContext.DBPayload
.Where(p => p.pid == pid)
.FirstOrDefaultAsync();
}
else
{
}
try
{
}
catch (Exception ex)
{
_logger.LogError($"[푸시] {ex.Message}");
return StatusCode(500, APIResponse.UnknownError());
}
return Ok("SEND"); return Ok("SEND");
} }
@ -57,7 +78,7 @@ public class PushController : ControllerBase
try try
{ {
var payload = await _dbContext.DBPayload var payload = await _dbContext.DBPayload
.Where(p => p.pid == pushRequest.pid) .Where(p => p.pid == pushRequest.pid && p.bid == pushRequest.bid )
.Select(p => new Payload .Select(p => new Payload
{ {
aps = new Aps aps = new Aps
@ -66,6 +87,7 @@ public class PushController : ControllerBase
category = p.category category = p.category
}, },
pid = pushRequest.pid, pid = pushRequest.pid,
bid = pushRequest.bid,
content = p.content ?? "", content = p.content ?? "",
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@ -73,9 +95,18 @@ public class PushController : ControllerBase
await Task.Run(async () => await Task.Run(async () =>
{ {
foreach (var uid in pushRequest.uids) foreach (var uid in pushRequest.uids)
{
if (
await _dbContext.UserAcademy
.Where(ua => ua.uid == uid && ua.bid == pushRequest.bid)
.AnyAsync()
)
{ {
var badge = await _dbContext.PushCabinet var badge = await _dbContext.PushCabinet
.Where(c => c.uid == uid && c.check_yn == false && c.pid != pushRequest.pid) .Where(c => c.uid == uid
&& c.bid == pushRequest.bid
&& c.pid != pushRequest.pid
&& c.check_yn == false )
.CountAsync(); .CountAsync();
var pushToken = await _dbContext.User var pushToken = await _dbContext.User
@ -86,6 +117,7 @@ public class PushController : ControllerBase
var pushCabinet = new PushCabinet var pushCabinet = new PushCabinet
{ {
uid = uid, uid = uid,
bid = pushRequest.bid,
pid = pushRequest.pid, pid = pushRequest.pid,
send_date = DateTime.Now, send_date = DateTime.Now,
}; };
@ -101,6 +133,8 @@ public class PushController : ControllerBase
_pushQueue.Enqueue(pushData); _pushQueue.Enqueue(pushData);
} }
}
}); });
return Ok(APIResponse.Send("000", "정상", Empty)); return Ok(APIResponse.Send("000", "정상", Empty));
@ -130,7 +164,7 @@ public class PushController : ControllerBase
try try
{ {
var dbPayload = await _dbContext.DBPayload var dbPayload = await _dbContext.DBPayload
.FirstOrDefaultAsync(p => p.pid == request.pid); .FirstOrDefaultAsync(p => p.pid == request.pid && p.bid == request.bid);
if (dbPayload != null) if (dbPayload != null)
{ {
@ -143,7 +177,8 @@ public class PushController : ControllerBase
if (await _repositoryService.SaveData<DBPayload, string>(dbPayload, p => p.pid)) if (await _repositoryService.SaveData<DBPayload, string>(dbPayload, p => p.pid))
return Ok(APIResponse.Send("000", "PUSH 정보 변경 완료", Empty)); return Ok(APIResponse.Send("000", "PUSH 정보 변경 완료", Empty));
} }
return Ok(APIResponse.Send("100", "PID 또는 Cabinet 오류", Empty));
return Ok(APIResponse.Send("100", "PID, BID 또는 Cabinet 오류", Empty));
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -78,6 +78,7 @@ public class DBPayload
[Key] [Key]
[MaxLength(22)] [MaxLength(22)]
public string pid { get; set; } public string pid { get; set; }
public string bid { get; set; }
public string title {get; set;} public string title {get; set;}
public string? subtitle {get; set;} public string? subtitle {get; set;}
public string body {get; set;} public string body {get; set;}
@ -91,12 +92,14 @@ public class PushCabinet
{ {
public string uid { get; set; } public string uid { get; set; }
public string pid { get; set; } public string pid { get; set; }
public string bid { get; set; }
public DateTime send_date { get; set; } public DateTime send_date { get; set; }
public bool check_yn { get; set; } public bool check_yn { get; set; }
} }
public class PushRequest public class PushRequest
{ {
public string bid { get; set; }
public List<string> uids { get; set; } public List<string> uids { get; set; }
public string pid { get; set; } public string pid { get; set; }
} }
@ -106,6 +109,7 @@ public class Payload
{ {
public Aps aps { get; set; } public Aps aps { get; set; }
public string pid { get; set; } public string pid { get; set; }
public string bid { get; set; }
public string content { get; set; } public string content { get; set; }
// public string customKey { get; set; } 이런식으로 추가도 가능 // public string customKey { get; set; } 이런식으로 추가도 가능