mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
Refactor: migrate Core -> Domain and reorganize projects
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.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Govor.Application.Interfaces.UserSession;
|
||||
using Govor.Application.Users.UserSessions;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Contracts.Responses;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -13,7 +13,7 @@ public class RefreshController : Controller
|
||||
{
|
||||
private readonly ILogger<RefreshController> _logger;
|
||||
private readonly IUserSessionRefresher _userSession;
|
||||
|
||||
|
||||
public RefreshController(
|
||||
ILogger<RefreshController> logger,
|
||||
IUserSessionRefresher userSession)
|
||||
@@ -21,41 +21,35 @@ public class RefreshController : Controller
|
||||
_logger = logger;
|
||||
_userSession = userSession;
|
||||
}
|
||||
|
||||
|
||||
//[RequireHttps]
|
||||
[HttpPost("refresh")] // api/auth/token/refresh
|
||||
public async Task<IActionResult> Refresh([FromBody] RefreshTokenRequest refreshRequest)
|
||||
{
|
||||
try
|
||||
if (string.IsNullOrWhiteSpace(refreshRequest.RefreshToken))
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
if (string.IsNullOrEmpty(refreshRequest.RefreshToken))
|
||||
throw new InvalidOperationException("Refresh token cant be empty.");
|
||||
|
||||
var result = await _userSession.RefreshTokenAsync(refreshRequest.RefreshToken);
|
||||
_logger.LogWarning("Refresh request failed: token is empty.");
|
||||
return BadRequest("Refresh token can't be empty.");
|
||||
}
|
||||
|
||||
var result = await _userSession.RefreshTokenAsync(refreshRequest.RefreshToken);
|
||||
|
||||
return Ok(new RefreshTokenResponse()
|
||||
{
|
||||
AccessToken = result.accessToken,
|
||||
RefreshToken = result.refreshToken
|
||||
});
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
if (result.IsFailure)
|
||||
{
|
||||
_logger.LogWarning(ex, "Invalid refresh token.");
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogWarning("Refresh token failed. Error Code: {Code}", result.Error.Code);
|
||||
|
||||
return result.Error.Code switch
|
||||
{
|
||||
"Auth.EmptyToken" => BadRequest(result.Error.Message),
|
||||
"Auth.InvalidToken" => Unauthorized(result.Error.Message),
|
||||
_ => BadRequest($"Refresh failed: {result.Error.Message}")
|
||||
};
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
|
||||
return Ok(new RefreshTokenResponse
|
||||
{
|
||||
_logger.LogWarning(ex, "Refresh token failed.");
|
||||
return Unauthorized("Invalid refresh token");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return StatusCode(500, "An unexpected error occurred.");
|
||||
}
|
||||
AccessToken = result.Value.accessToken,
|
||||
RefreshToken = result.Value.refreshToken
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user