134 lines
6.2 KiB
C#
134 lines
6.2 KiB
C#
using System.Security.Claims;
|
|
using Back.Program.Common.Auth;
|
|
using Back.Program.Common.Data;
|
|
using Back.Program.Common.Model;
|
|
using Back.Program.Models.Entities;
|
|
using Back.Program.Services.V1;
|
|
using Back.Program.Services.V1.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Back.Program.Controllers.V1
|
|
{
|
|
[ApiController]
|
|
[Route("/api/v1/in/push")]
|
|
[ApiExplorerSettings(GroupName = "공통")]
|
|
public class PushController : ControllerBase
|
|
{
|
|
private readonly ILogger<PushController> _logger;
|
|
private readonly IRepositoryService _repositoryService;
|
|
private readonly IPushQueue _pushQueue;
|
|
private readonly IPushService _pushService;
|
|
|
|
public PushController(ILogger<PushController> logger, IRepositoryService repositoryService,
|
|
IPushQueue pushQueue, IPushService pushService)
|
|
{
|
|
_logger = logger;
|
|
_repositoryService = repositoryService;
|
|
_pushQueue = pushQueue;
|
|
_pushService = pushService;
|
|
}
|
|
|
|
// 추가 사항
|
|
// 카테고리 별 조회 하는 부분도 추가를 할 지 고민을 해야 할 것 같음
|
|
|
|
[HttpGet()]
|
|
[CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> GetPush(string bid, string? pid, string? category)
|
|
{
|
|
if (string.IsNullOrEmpty(bid)) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "GetPush");
|
|
var result = await _pushService.GetPush(summary, bid, pid, category);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
[HttpPost("send")]
|
|
[CustomOperation("푸시 발송", "저장된 양식으로, 사용자에게 푸시를 송신한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> SendPush([FromBody] PushRequest pushRequest)
|
|
{
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "SendPush");
|
|
|
|
var result = await _pushService.SendPush(summary, pushRequest);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPost("set")]
|
|
[CustomOperation("푸시 변경", "저장된 양식을 변경한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> SetPush(string token, [FromBody] DBPayload request)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "SetPush");
|
|
|
|
var result = await _pushService.SetPush(summary, token, request);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPost("create")]
|
|
[CustomOperation("푸시 생성", "새로운 푸시 양식을 생성한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> CreatePush(string token, [FromBody] CreatePush request)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "CreatePush");
|
|
var result = await _pushService.CreatePush(summary, token, request);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
|
|
[HttpDelete("delete")]
|
|
[CustomOperation("푸시 삭제", "저장된 푸시 양식을 삭제 한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> DeletePush(string token, string bid, string pid)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "DeletePush");
|
|
var result = await _pushService.DeletePush(summary,token,bid,pid);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
[HttpDelete("delete/list")]
|
|
[CustomOperation("사용자 푸시 목록 삭제", "사용자가 받은 푸시목록에서 푸시를 삭제한다..", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> DeleteListPush(string token, int id)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "DeleteListPush");
|
|
var result = await _pushService.DeleteListPush(summary, token, id);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("list")]
|
|
[CustomOperation("사용자 푸시 목록 조회", "해당 사용자가 받은 푸시의 정보를 조회한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> SearchToUserPush(string token, int size, [FromBody] PushCabinet? request)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(PushController), "SearchToUserPush");
|
|
|
|
var result = await _pushService.SearchToUserPush(summary, token, size, request);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
}
|
|
} // END PUSH CONTROLLER
|
|
|
|
|
|
|
|
|
|
|