forked from AcaMate/AcaMate_API
[✨] PUSH 확인, DELETE API 작성, 로그 기능 구현 위한 로직 추가 중
This commit is contained in:
parent
8cb4207ef6
commit
ccd880e7e0
|
@ -29,12 +29,23 @@ public class AppDbContext: DbContext
|
|||
public DbSet<DBPayload> DBPayload { get; set; }
|
||||
public DbSet<PushCabinet> PushCabinet { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
//MARK: LOG
|
||||
public DbSet<LogPush> LogPush { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<User_Academy>()
|
||||
.HasKey(ua => new { ua.uid, ua.bid });
|
||||
|
||||
modelBuilder.Entity<PushCabinet>()
|
||||
.HasKey(p => new { p.uid, p.pid });
|
||||
.HasKey(c => new { c.uid, c.bid, c.pid });
|
||||
|
||||
modelBuilder.Entity<DBPayload>()
|
||||
.HasKey(p => new { p.bid, p.pid });
|
||||
|
||||
// modelBuilder.Entity<LogPush>().HasNoKey();
|
||||
}
|
||||
}
|
|
@ -30,32 +30,52 @@ public class PushController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpGet()]
|
||||
[CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다..", "푸시")]
|
||||
public async Task<IActionResult> GetPush(string? pid)
|
||||
[CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다.", "푸시")]
|
||||
public async Task<IActionResult> GetPush(string bid, string? pid, string? category)
|
||||
{
|
||||
if (pid != null)
|
||||
{
|
||||
var pushData = await _dbContext.DBPayload
|
||||
.Where(p => p.pid == pid)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
if (!(await _dbContext.Academy.AnyAsync(a=>a.bid == bid)))
|
||||
return Ok(APIResponse.Send("100", "존재하지 않는 BID", Empty));
|
||||
|
||||
List<DBPayload> pushData = new List<DBPayload>();
|
||||
|
||||
if (pid == null && category == null)
|
||||
{
|
||||
pushData = await _dbContext.DBPayload
|
||||
.Where(p => p.bid == bid)
|
||||
.ToListAsync();
|
||||
}
|
||||
else if (pid != null && category == null)
|
||||
{
|
||||
pushData = await _dbContext.DBPayload
|
||||
.Where(p => p.bid == bid && p.pid == pid)
|
||||
.ToListAsync();
|
||||
}
|
||||
else if (pid == null && category != null)
|
||||
{
|
||||
pushData = await _dbContext.DBPayload
|
||||
.Where(p => p.bid == bid && p.category == category)
|
||||
.ToListAsync();
|
||||
}
|
||||
else //if (pid != null && category != null)
|
||||
{
|
||||
pushData = await _dbContext.DBPayload
|
||||
.Where(p => p.bid == bid && p.pid == pid && p.category == category)
|
||||
.ToListAsync();
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pushData.Count > 0)
|
||||
{
|
||||
return Ok(APIResponse.Send("000", "정상", pushData));
|
||||
}
|
||||
|
||||
return Ok(APIResponse.Send("001", "PUSH 데이터가 없음", Empty));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"[푸시] {ex.Message}");
|
||||
return StatusCode(500, APIResponse.UnknownError());
|
||||
}
|
||||
|
||||
return Ok("SEND");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,7 +194,8 @@ public class PushController : ControllerBase
|
|||
if (dbPayload.alert_yn != request.alert_yn) dbPayload.alert_yn = request.alert_yn;
|
||||
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, string>(dbPayload, p => p.pid))
|
||||
// if (await _repositoryService.SaveData<DBPayload, string>(dbPayload, p => p.pid))
|
||||
if (await _repositoryService.SaveDataFK<DBPayload>(dbPayload))
|
||||
return Ok(APIResponse.Send("000", "PUSH 정보 변경 완료", Empty));
|
||||
}
|
||||
|
||||
|
@ -186,7 +207,88 @@ public class PushController : ControllerBase
|
|||
return StatusCode(500, APIResponse.UnknownError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("create")]
|
||||
[CustomOperation("푸시생성", "새로운 푸시 양식을 생성한다.", "푸시")]
|
||||
[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;
|
||||
|
||||
Func<string, int, string> randomLetter = (letters, count) => new string(Enumerable.Range(0, count).Select(_ => letters[new Random().Next(letters.Length)]).ToArray());
|
||||
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
var digits = "0123456789";
|
||||
var frontLetters = $"{randomLetter(letters, 1)}{randomLetter(digits, 1)}{randomLetter(letters, 1)}";
|
||||
var afterLetters = $"{randomLetter(letters, 1)}{randomLetter(digits, 1)}{randomLetter(letters, 1)}";
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (await _dbContext.Academy.AnyAsync(a => a.bid == createPush.bid))
|
||||
{
|
||||
DBPayload payload = new DBPayload
|
||||
{
|
||||
bid = createPush.bid,
|
||||
pid = $"AP{DateTime.Now:yyyyMMdd}{frontLetters}{DateTime.Now:HHmmss}{afterLetters}",
|
||||
title = createPush.title,
|
||||
subtitle = createPush.subtitle,
|
||||
body = createPush.body,
|
||||
alert_yn = createPush.alert_yn,
|
||||
category = createPush.category,
|
||||
content = createPush.content,
|
||||
};
|
||||
if (await _repositoryService.SaveDataFK<DBPayload>(payload))
|
||||
{
|
||||
var logPush = new LogPush
|
||||
{
|
||||
bid = payload.bid,
|
||||
pid = payload.pid,
|
||||
create_uid = uid,
|
||||
create_date = DateTime.Now,
|
||||
log = $"[CREATE] {payload.pid} 최초 생성 - {uid}"
|
||||
};
|
||||
|
||||
// 로그를 이제 만들어서 추가를 해야 합니다.
|
||||
_dbContext.Set<LogPush>().Add(logPush);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
return Ok(APIResponse.Send("000", "정상, push 저장 완료", Empty));
|
||||
}
|
||||
|
||||
}
|
||||
return Ok(APIResponse.Send("100", "학원 정보(BID) 확인 불가", Empty));
|
||||
}
|
||||
catch (TokenException tokenEx)
|
||||
{
|
||||
_logger.LogInformation($"[푸시 생성] : {tokenEx}");
|
||||
return Ok(APIResponse.Send("001", "[푸시 생성] : 토큰에 문제가 있음",Empty));
|
||||
}
|
||||
catch (RefreshRevokeException refreshEx)
|
||||
{
|
||||
_logger.LogInformation($"[푸시 생성] : {refreshEx}");
|
||||
return Ok(APIResponse.Send("001", "[푸시 생성] : 폐기된 리프레시 토큰",Empty));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"[푸시] {ex.Message}");
|
||||
return StatusCode(500, APIResponse.UnknownError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpDelete("delete")]
|
||||
[CustomOperation("푸시삭제", "저장된 푸시 양식을 삭제 한다.", "푸시")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> DeletePush(string bid, string pid)
|
||||
{
|
||||
return Ok("good");
|
||||
}
|
||||
|
||||
}// END PUSH CONTROLLER
|
||||
|
||||
|
|
|
@ -172,12 +172,12 @@ public class UserController : ControllerBase
|
|||
catch (TokenException tokenEx)
|
||||
{
|
||||
_logger.LogInformation($"[로그인] : {tokenEx}");
|
||||
return Ok(APIResponse.Send("001", "로그인 진행: 토큰에 문제가 있음",Empty));
|
||||
return Ok(APIResponse.Send("001", "[로그인] : 토큰에 문제가 있음",Empty));
|
||||
}
|
||||
catch (RefreshRevokeException refreshEx)
|
||||
{
|
||||
_logger.LogInformation($"[로그인] : {refreshEx}");
|
||||
return Ok(APIResponse.Send("001", "로그인 진행: 리프레시 토큰 폐기",Empty));
|
||||
return Ok(APIResponse.Send("001", "[로그인] : 폐기된 리프레시 토큰",Empty));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
21
Program/V1/Models/Log.cs
Normal file
21
Program/V1/Models/Log.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace AcaMate.V1.Models;
|
||||
|
||||
[Table("log_push")]
|
||||
public class LogPush
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int lid { get; set; }
|
||||
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; }
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace AcaMate.V1.Models;
|
||||
|
||||
|
@ -75,10 +76,8 @@ namespace AcaMate.V1.Models;
|
|||
[Table("payload")]
|
||||
public class DBPayload
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(22)]
|
||||
public string pid { get; set; }
|
||||
public string bid { get; set; }
|
||||
public string pid { get; set; }
|
||||
public string title {get; set;}
|
||||
public string? subtitle {get; set;}
|
||||
public string body {get; set;}
|
||||
|
@ -146,7 +145,7 @@ public class Alert
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 푸시 등록하기 위한 여러 데이터 목록
|
||||
/// 푸시 등록하기 위한 apns 여러 데이터 목록
|
||||
/// </summary>
|
||||
public class PushFileSetting
|
||||
{
|
||||
|
@ -160,4 +159,15 @@ public class PushData
|
|||
{
|
||||
public string pushToken { get; set; }
|
||||
public Payload payload { get; set; }
|
||||
}
|
||||
|
||||
public class CreatePush
|
||||
{
|
||||
public string bid { get; set; }
|
||||
public string title { get; set; }
|
||||
public string? subtitle { get; set; }
|
||||
public string body { get; set; }
|
||||
public bool alert_yn { get; set; } = true;
|
||||
public string category { get; set; }
|
||||
public string? content { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user