mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
6d1c53beeb
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Govor.Application.Infrastructure.Extensions;
|
|
using Govor.Application.PushNotifications;
|
|
using Govor.Contracts.Requests;
|
|
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 IPushTokenService _pushTokenService;
|
|
|
|
public PushTokensController(
|
|
IPushTokenService pushTokenService,
|
|
ICurrentUserService currentUser,
|
|
ICurrentUserSessionService currentSession)
|
|
{
|
|
_pushTokenService = pushTokenService;
|
|
_currentUser = currentUser;
|
|
_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 _pushTokenService.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.");
|
|
}
|
|
}
|
|
} |