mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
was added firebase nitifying
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Repositories.PushTokens;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Roles = "Admin, User")]
|
||||
[Route("api")]
|
||||
public class PushTokensController : Controller
|
||||
{
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
private readonly ICurrentUserSessionService _currentSession;
|
||||
private readonly IPushTokenRepository _pushTokenRepo;
|
||||
|
||||
public PushTokensController(
|
||||
ICurrentUserService currentUser,
|
||||
ICurrentUserSessionService currentSession,
|
||||
IPushTokenRepository pushTokenRepository)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_pushTokenRepo = pushTokenRepository;
|
||||
_currentSession = currentSession;
|
||||
}
|
||||
|
||||
[HttpPost("pushes/token/register")]
|
||||
public async Task<IActionResult> RegisterToken([FromBody] RegisterPushTokenRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
if (string.IsNullOrEmpty(req.Token) || string.IsNullOrWhiteSpace(req.Platform))
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var currentId = _currentUser.GetCurrentUserId();
|
||||
var currentSessionId = _currentSession.GetUserSessionId();
|
||||
|
||||
await _pushTokenRepo.AddOrUpdateTokenAsync(
|
||||
userId: currentId,
|
||||
sessionId: currentSessionId,
|
||||
token: req.Token,
|
||||
platform: req.Platform);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, "Unexpected Error! Please try again later.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user