forked from AcaMate/AcaMate_API
[✨] 푸시 리스트 확인 및 푸시 리스트내 아이템 삭제, 그외 로직 변경
This commit is contained in:
parent
012e7231db
commit
e6672ed630
|
@ -40,8 +40,8 @@ public class AppDbContext: DbContext
|
|||
modelBuilder.Entity<User_Academy>()
|
||||
.HasKey(ua => new { ua.uid, ua.bid });
|
||||
|
||||
modelBuilder.Entity<PushCabinet>()
|
||||
.HasKey(c => new { c.uid, c.bid, c.pid });
|
||||
// modelBuilder.Entity<PushCabinet>()
|
||||
// .HasKey(c => new { c.uid, c.bid, c.pid });
|
||||
|
||||
modelBuilder.Entity<DBPayload>()
|
||||
.HasKey(p => new { p.bid, p.pid });
|
||||
|
|
|
@ -95,6 +95,9 @@ public class PushController : ControllerBase
|
|||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (payload == null)
|
||||
throw new PushInvalidException("payload is NULL");
|
||||
|
||||
foreach (var uid in pushRequest.uids)
|
||||
{
|
||||
// 학원 내부에 해당 uid의 일원이 존재하는지 확인
|
||||
|
@ -109,6 +112,7 @@ public class PushController : ControllerBase
|
|||
.Where(c => c.uid == uid
|
||||
&& c.check_yn == false)
|
||||
.CountAsync();
|
||||
payload.aps.badge = badge + 1;
|
||||
|
||||
// 푸시를 보내야 하니 푸시 토큰 확인
|
||||
var pushToken = await _dbContext.User
|
||||
|
@ -122,15 +126,13 @@ public class PushController : ControllerBase
|
|||
bid = pushRequest.bid,
|
||||
pid = pushRequest.pid,
|
||||
send_date = DateTime.Now,
|
||||
content = pushRequest.content ?? null,
|
||||
content = payload.content != "" ? payload.content : null,
|
||||
};
|
||||
|
||||
if (payload != null) payload.aps.badge = badge + 1;
|
||||
|
||||
var pushData = new PushData
|
||||
{
|
||||
pushToken = pushToken,
|
||||
payload = payload ?? throw new PushInvalidException("payload is NULL")
|
||||
payload = payload
|
||||
};
|
||||
|
||||
if (await _repositoryService.SaveData<PushCabinet>(pushCabinet))
|
||||
|
@ -183,9 +185,17 @@ public class PushController : ControllerBase
|
|||
[HttpPost("set")]
|
||||
[CustomOperation("푸시 변경", "저장된 양식을 변경한다.", "푸시")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> SetPush([FromBody] DBPayload request)
|
||||
public async Task<IActionResult> SetPush(string token, string refresh, [FromBody] DBPayload request)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
||||
string uid = "";
|
||||
if (token == "System") uid = "System";
|
||||
else {
|
||||
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);
|
||||
uid = validateToken.uid;
|
||||
}
|
||||
|
||||
string summary = String.Empty;
|
||||
try {
|
||||
|
@ -193,8 +203,17 @@ public class PushController : ControllerBase
|
|||
var dbPayload = await _dbContext.DBPayload
|
||||
.FirstOrDefaultAsync(p => p.pid == request.pid && p.bid == request.bid);
|
||||
|
||||
|
||||
if (dbPayload != null)
|
||||
{
|
||||
var logPush = new LogPush
|
||||
{
|
||||
bid = dbPayload.bid,
|
||||
pid = dbPayload.pid,
|
||||
create_uid = uid,
|
||||
create_date = DateTime.Now,
|
||||
};
|
||||
|
||||
if (dbPayload.title != request.title && request.title != "") dbPayload.title = request.title;
|
||||
if (dbPayload.body != request.body && request.body != "") dbPayload.body = request.body;
|
||||
if (dbPayload.subtitle != request.subtitle) dbPayload.subtitle = request.subtitle;
|
||||
|
@ -202,8 +221,14 @@ public class PushController : ControllerBase
|
|||
if (dbPayload.category != request.category && request.category != "") dbPayload.category = request.category;
|
||||
if (dbPayload.content != request.content) dbPayload.content = request.content;
|
||||
if (await _repositoryService.SaveData<DBPayload>(dbPayload))
|
||||
{
|
||||
logPush.log = $"[{summary} : 정상 변경";
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", Empty));
|
||||
// TODO - 로그 추가
|
||||
}
|
||||
|
||||
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||
if (await _repositoryService.SaveData<LogPush>(logPush))
|
||||
_logger.LogInformation($"[{summary}] : 로그 추가");
|
||||
}
|
||||
|
||||
return Ok(APIResponse.Send("100", $"[{summary}], PID, BID 또는 Cabinet 오류", Empty));
|
||||
|
@ -220,11 +245,15 @@ public class PushController : ControllerBase
|
|||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> CreatePush(string token, string refresh, [FromBody] CreatePush createPush)
|
||||
{
|
||||
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 uid = "";
|
||||
if (token == "System") uid = "System";
|
||||
else {
|
||||
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);
|
||||
uid = validateToken.uid;
|
||||
}
|
||||
|
||||
Func<string, int, string> randomLetter = (letters, count) => new string(Enumerable.Range(0, count).Select(_ => letters[new Random().Next(letters.Length)]).ToArray());
|
||||
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
@ -260,7 +289,7 @@ public class PushController : ControllerBase
|
|||
pid = payload.pid,
|
||||
create_uid = uid,
|
||||
create_date = DateTime.Now,
|
||||
log = $"[{summary}] : {payload.pid} 최초 생성 - {uid}"
|
||||
log = $"[{summary}] : 정상 생성"
|
||||
};
|
||||
|
||||
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||
|
@ -297,12 +326,15 @@ public class PushController : ControllerBase
|
|||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> DeletePush(string token, string refresh, string bid, string pid)
|
||||
{
|
||||
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 uid = "";
|
||||
if (token == "System") uid = "System";
|
||||
else {
|
||||
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);
|
||||
uid = validateToken.uid;
|
||||
}
|
||||
|
||||
string summary = String.Empty;
|
||||
|
||||
|
@ -311,11 +343,8 @@ public class PushController : ControllerBase
|
|||
summary = _repositoryService.ReadSummary(typeof(PushController), "DeletePush");
|
||||
|
||||
var payload = await _dbContext.DBPayload.FirstOrDefaultAsync(p => p.bid == bid && p.pid == pid);
|
||||
if (payload == null)
|
||||
return Ok(APIResponse.Send("001", $"[{summary}], 삭제 할 PUSH 없음", Empty));
|
||||
|
||||
if (!await _repositoryService.DeleteData<DBPayload>(payload))
|
||||
return Ok(APIResponse.Send("002", $"[{summary}], PUSH 삭제 실패", Empty));
|
||||
if (payload == null) return Ok(APIResponse.Send("001", $"[{summary}], 삭제 할 PUSH 없음", Empty));
|
||||
if (!await _repositoryService.DeleteData<DBPayload>(payload)) return Ok(APIResponse.Send("002", $"[{summary}], PUSH 삭제 실패", Empty));
|
||||
|
||||
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||
var logPush = new LogPush
|
||||
|
@ -331,11 +360,53 @@ public class PushController : ControllerBase
|
|||
if (await _repositoryService.SaveData<LogPush>(logPush)) _logger.LogInformation($"[{summary}] : 로그 추가");
|
||||
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", Empty));
|
||||
|
||||
}
|
||||
/*
|
||||
*/
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"[{summary}] : {ex.Message}");
|
||||
return BadRequest(APIResponse.UnknownError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("delete/list")]
|
||||
[CustomOperation("사용자 푸시 목록 삭제", "사용자가 받은 푸시목록에서 푸시를 삭제한다..", "푸시")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> DeleteListPush(string token, string refresh, int id)
|
||||
{
|
||||
string uid = "";
|
||||
if (token == "System") uid = "System";
|
||||
else {
|
||||
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);
|
||||
uid = validateToken.uid;
|
||||
}
|
||||
|
||||
string summary = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
summary = _repositoryService.ReadSummary(typeof(PushController), "DeleteListPush");
|
||||
var cabinetPush = await _dbContext.PushCabinet.FirstOrDefaultAsync(c => c.id == id);
|
||||
if (cabinetPush == null) return Ok(APIResponse.Send("001", $"[{summary}], 삭제 할 PUSH 없음", Empty));
|
||||
if (!await _repositoryService.DeleteData<PushCabinet>(cabinetPush))
|
||||
return Ok(APIResponse.Send("002", $"[{summary}], PUSH 삭제 실패", Empty));
|
||||
|
||||
// // 로그를 이제 만들어서 추가를 해야 합니다.
|
||||
var logPush = new LogPush
|
||||
{
|
||||
bid = cabinetPush.bid,
|
||||
pid = cabinetPush.pid,
|
||||
create_uid = uid,
|
||||
create_date = DateTime.Now,
|
||||
log = $"[{summary}] : {cabinetPush.pid} 삭제 - {uid}"
|
||||
};
|
||||
if (await _repositoryService.SaveData<LogPush>(logPush)) _logger.LogInformation($"[{summary}] : 로그 추가");
|
||||
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", Empty));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"[{summary}] : {ex.Message}");
|
||||
|
@ -343,44 +414,46 @@ public class PushController : ControllerBase
|
|||
}
|
||||
}
|
||||
|
||||
[HttpGet("list")]
|
||||
|
||||
|
||||
[HttpPost("list")]
|
||||
[CustomOperation("사용자 푸시 목록 조회", "해당 사용자가 받은 푸시의 정보를 조회한다.", "푸시")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> SearchToUserPush(string token, string refresh, string? pid)
|
||||
public async Task<IActionResult> SearchToUserPush(string token, string refresh, int size, [FromBody] PushCabinet? pushData)
|
||||
{
|
||||
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 uid = "";
|
||||
if (token == "System") uid = "System";
|
||||
else {
|
||||
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);
|
||||
uid = validateToken.uid;
|
||||
}
|
||||
|
||||
string summary = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
summary = _repositoryService.ReadSummary(typeof(PushController), "SearchToUserPush");
|
||||
if (pid == null)
|
||||
if (pushData == null)
|
||||
{
|
||||
var cabinet = await _dbContext.PushCabinet.Where(c => c.uid == uid).ToListAsync();
|
||||
var pagedData = await _dbContext.PushCabinet.Where(c => c.uid == uid)
|
||||
.OrderBy(c=> c.send_date)
|
||||
.Take(size)
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", pagedData));
|
||||
}
|
||||
else
|
||||
{
|
||||
int pageSize = 5;
|
||||
var sort = await _dbContext.PushCabinet.Where(p=> p.pid == pid).Select(p => p.send_date).FirstOrDefaultAsync();
|
||||
var sort = await _dbContext.PushCabinet.Where(p=> p.id == pushData.id)
|
||||
.Select(p => p.send_date).FirstOrDefaultAsync();
|
||||
var query = _dbContext.PushCabinet.OrderBy(c => c.send_date).AsQueryable();
|
||||
query = query.Where(c => c.send_date > sort);
|
||||
var pagedData = await query.Take(pageSize).ToListAsync();
|
||||
|
||||
foreach (var p in pagedData)
|
||||
{
|
||||
_logger.LogInformation($"[{summary}] : {p.pid}");
|
||||
}
|
||||
var pagedData = await query.Take(size).ToListAsync();
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", pagedData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", Empty));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -14,8 +14,6 @@ public class LogPush
|
|||
public string bid {get; set;}
|
||||
public string pid {get; set;}
|
||||
public DateTime create_date {get; set;}
|
||||
public DateTime? update_date {get; set;}
|
||||
public string create_uid {get; set;}
|
||||
public string? update_uid {get; set;}
|
||||
public string log { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user