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,8 +1,3 @@
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Models.Users;
|
||||
using Govor.Core.Repositories.Friendships;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -14,14 +9,8 @@ namespace Govor.API.Controllers.AdminStuff;
|
||||
public class FriendshipsController : Controller
|
||||
{
|
||||
private readonly ILogger<FriendshipsController> _logger;
|
||||
private readonly IFriendshipsRepository _friendshipsRepository;
|
||||
|
||||
public FriendshipsController(ILogger<FriendshipsController> logger, IFriendshipsRepository friendshipsRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_friendshipsRepository = friendshipsRepository;
|
||||
}
|
||||
|
||||
/*
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
@@ -88,5 +77,5 @@ public class FriendshipsController : Controller
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return StatusCode(500, new { error = "Internal server error." });
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Infrastructure.AdminsStuff;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Repositories.Invaites;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers.AdminStuff;
|
||||
@@ -12,17 +10,17 @@ namespace Govor.API.Controllers.AdminStuff;
|
||||
//[Authorize(Roles = "Admin")]
|
||||
public class InviteUserController : Controller
|
||||
{
|
||||
private readonly IInvitesRepository _repository;
|
||||
private readonly IInvitationGetter _invitationGetter;
|
||||
private readonly IInvitationGenerator _invitationGenerator;
|
||||
private readonly ILogger<InviteUserController> _logger;
|
||||
|
||||
public InviteUserController(IInvitationGenerator invitationGenerator,
|
||||
IInvitesRepository repository,
|
||||
IInvitationGetter invitationGetter,
|
||||
ILogger<InviteUserController> logger)
|
||||
{
|
||||
_invitationGenerator = invitationGenerator;
|
||||
_logger = logger;
|
||||
_repository = repository;
|
||||
_invitationGetter = invitationGetter;
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
@@ -51,7 +49,7 @@ public class InviteUserController : Controller
|
||||
{
|
||||
_logger.LogInformation("Getting all active invitations by administrator");
|
||||
|
||||
var read = await _repository.GetAllAsync();
|
||||
var read = await _invitationGetter.GetAllAsync();
|
||||
var result = read.Where(x => x.IsActive).ToList();
|
||||
|
||||
List<InvitationResponses> dtos = new List<InvitationResponses>();
|
||||
@@ -86,7 +84,7 @@ public class InviteUserController : Controller
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Getting all invitations by administrator");
|
||||
var read = await _repository.GetAllAsync();
|
||||
var read = await _invitationGetter.GetAllAsync();
|
||||
|
||||
List<InvitationResponses> dtos = new List<InvitationResponses>();
|
||||
|
||||
@@ -120,18 +118,22 @@ public class InviteUserController : Controller
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Getting invitations {id} by administrator");
|
||||
var read = await _repository.FindByIdAsync(id);
|
||||
var read = await _invitationGetter.FindByIdAsync(id);
|
||||
|
||||
if(read.IsFailure)
|
||||
return NotFound(read.Error);
|
||||
var dto = read.Value;
|
||||
|
||||
var response = new InvitationResponses(){
|
||||
Id = read.Id,
|
||||
Description = read.Description,
|
||||
IsAdmin = read.IsAdmin,
|
||||
MaxParticipants = read.MaxParticipants,
|
||||
Code = read.Code,
|
||||
CreatedAt = read.DateCreated,
|
||||
EndAt = read.EndDate,
|
||||
IsActive = read.IsActive,
|
||||
ParticipantCount = read.Users.Count,
|
||||
Id = dto.Id,
|
||||
Description = dto.Description,
|
||||
IsAdmin = dto.IsAdmin,
|
||||
MaxParticipants = dto.MaxParticipants,
|
||||
Code = dto.Code,
|
||||
CreatedAt = dto.DateCreated,
|
||||
EndAt = dto.EndDate,
|
||||
IsActive = dto.IsActive,
|
||||
ParticipantCount = dto.Users.Count,
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Infrastructure.AdminsStuff;
|
||||
using Govor.Contracts.Responses.Admins;
|
||||
using Govor.Core.Infrastructure.Extensions;
|
||||
using Govor.Core.Models.Users;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Govor.Domain.Models.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers.AdminStuff;
|
||||
@@ -54,11 +51,6 @@ public class UsersController : Controller
|
||||
var read = await _users.GetUserById(id);
|
||||
return Ok(BuildUserDtos([read]).First());
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Govor.Application.Exceptions.AuthService;
|
||||
using Govor.Application.Exceptions.InvitesService;
|
||||
using Govor.Application.Interfaces.Authentication;
|
||||
using Govor.Application.Interfaces.UserSession;
|
||||
using Govor.Application.Authentication;
|
||||
using Govor.Application.Authentication.Exceptions;
|
||||
using Govor.Application.Users.UserSessions;
|
||||
using Govor.Contracts.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -29,83 +28,84 @@ public class AuthController : Controller
|
||||
_invitesService = invitesService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
//[RequireHttps]
|
||||
[HttpPost("register")]// api/auth/register
|
||||
|
||||
[HttpPost("register")] // api/auth/register
|
||||
public async Task<IActionResult> Register([FromBody] RegistrationRequest registrationRequest)
|
||||
{
|
||||
try
|
||||
|
||||
var inviteResult = await _invitesService.ValidateAsync(registrationRequest.InviteLink);
|
||||
if (!inviteResult.IsSuccess)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
_logger.LogWarning("Invite link invalid: {InviteLink}. Error: {Error}", registrationRequest.InviteLink,
|
||||
inviteResult.Error);
|
||||
return BadRequest($"Invite link invalid: {inviteResult.Error.Message}");
|
||||
}
|
||||
|
||||
var userResult = await _accountService.RegistrationAsync(
|
||||
registrationRequest.Name,
|
||||
registrationRequest.Password,
|
||||
inviteResult.Value);
|
||||
|
||||
var invite = await _invitesService.ValidateAsync(registrationRequest.InviteLink);
|
||||
if (userResult.IsFailure)
|
||||
{
|
||||
_logger.LogWarning("Registration failed for user {Name}. Error: {Error}", registrationRequest.Name,
|
||||
userResult.Error);
|
||||
|
||||
return userResult.Error.Code switch
|
||||
{
|
||||
nameof(UserAlreadyExistException) => BadRequest($"Registration failed: {userResult.Error.Message}"),
|
||||
nameof(InvalidUsernameException) => BadRequest($"Invalid username: {userResult.Error.Message}"),
|
||||
_ => BadRequest($"Registration failed: {userResult.Error.Message}")
|
||||
};
|
||||
}
|
||||
|
||||
var user = await _accountService.RegistrationAsync(registrationRequest.Name, registrationRequest.Password,
|
||||
invite);
|
||||
|
||||
_logger.LogInformation($"Register request for {user.Username} with id {user.Id} processed successfully");
|
||||
var user = userResult.Value;
|
||||
_logger.LogInformation("Register request for {Username} with id {Id} processed successfully", user.Username,
|
||||
user.Id);
|
||||
|
||||
var sessionResult = await _userSession.OpenSessionAsync(user, registrationRequest.DeviceInfo);
|
||||
if (sessionResult.IsFailure)
|
||||
{
|
||||
_logger.LogError("Failed to open session for user {Username}. Error: {Error}", user.Username,
|
||||
sessionResult.Error.Message);
|
||||
return StatusCode(500, "An error occurred while creating the session.");
|
||||
}
|
||||
|
||||
var tokens = await _userSession.OpenSessionAsync(user, registrationRequest.DeviceInfo);
|
||||
|
||||
_logger.LogInformation($"Session for user {user.Username} with id {user.Id} has been opened");
|
||||
|
||||
return Ok(tokens);
|
||||
}
|
||||
catch (UserAlreadyExistException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Registration failed for user {registrationRequest.Name}");
|
||||
return BadRequest("Registration failed: user already exists.");
|
||||
}
|
||||
catch (InviteLinkInvalidException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Invite link invalid: {registrationRequest.InviteLink}");
|
||||
return BadRequest("Invite link invalid.");
|
||||
}
|
||||
catch (InvalidUsernameException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Invalid username: {registrationRequest.Name}");
|
||||
return BadRequest($"Invalid username: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error during registration for user {Name}", registrationRequest.Name);
|
||||
return StatusCode(500, "An unexpected error occurred. Please try again later.");
|
||||
}
|
||||
_logger.LogInformation("Session for user {Username} with id {Id} has been opened", user.Username, user.Id);
|
||||
return Ok(sessionResult.Value);
|
||||
}
|
||||
|
||||
|
||||
//[RequireHttps]
|
||||
[HttpPost("login")]// api/auth/login
|
||||
[HttpPost("login")] // api/auth/login
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
|
||||
{
|
||||
try
|
||||
var userResult = await _accountService.LoginAsync(loginRequest.Name, loginRequest.Password);
|
||||
|
||||
if (userResult.IsFailure)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var user = await _accountService.LoginAsync(loginRequest.Name, loginRequest.Password);
|
||||
_logger.LogInformation($"Login request for {user.Username} with id {user.Id} processed successfully");
|
||||
_logger.LogWarning("Login failed for user {Name}. Error: {Code}", loginRequest.Name, userResult.Error);
|
||||
|
||||
var tokens = await _userSession.OpenSessionAsync(user, loginRequest.DeviceInfo);
|
||||
|
||||
_logger.LogInformation($"Session for user {user.Username} with id {user.Id} has been opened");
|
||||
|
||||
return Ok(tokens);
|
||||
return userResult.Error.Code switch
|
||||
{
|
||||
nameof(UserNotRegisteredException) => BadRequest("Login failed: user does not exist."),
|
||||
nameof(InvalidOperationException) => BadRequest("Login failed: username or password is incorrect."),
|
||||
_ => BadRequest($"Login failed: {userResult.Error.Message}")
|
||||
};
|
||||
}
|
||||
catch (UserNotRegisteredException ex)
|
||||
|
||||
var user = userResult.Value;
|
||||
_logger.LogInformation("Login request for {Username} with id {Id} processed successfully", user.Username, user.Id);
|
||||
|
||||
var sessionResult = await _userSession.OpenSessionAsync(user, loginRequest.DeviceInfo);
|
||||
|
||||
if (sessionResult.IsFailure)
|
||||
{
|
||||
_logger.LogWarning(ex, "Login failed for user {Name}", loginRequest.Name);
|
||||
return BadRequest("Login failed: user does not exist.");
|
||||
}
|
||||
catch (LoginUserException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Login failed for user {Name}", loginRequest.Name);
|
||||
return BadRequest("Login failed: username or password is incorrect.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error during login for user {Name}", loginRequest.Name);
|
||||
return StatusCode(500, "An unexpected error occurred. Please try again later.");
|
||||
_logger.LogError("Failed to open session for user {Username}. Error: {Error}", user.Username, sessionResult.Error);
|
||||
return StatusCode(500, "An error occurred while creating the session.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Session for user {Username} with id {Id} has been opened", user.Username, user.Id);
|
||||
|
||||
return Ok(sessionResult.Value);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using Govor.Application.Interfaces.Friends;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.UserSession;
|
||||
using Govor.Application.Interfaces.UserSession.Crypto;
|
||||
using Govor.Application.Friends;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Users.UserSessions.Crypto;
|
||||
using Govor.Contracts.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using AutoMapper;
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Messages;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Contracts.Responses;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -52,16 +51,6 @@ public class ChatLoadController : Controller
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
@@ -95,21 +84,6 @@ public class ChatLoadController : Controller
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using AutoMapper;
|
||||
using Govor.Application.Interfaces.Friends;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Friends;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Core.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -41,16 +40,6 @@ public class FriendsRequestQueryController : Controller
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Ok(new List<FriendshipDto>());
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
@@ -72,16 +61,6 @@ public class FriendsRequestQueryController : Controller
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Ok(new List<FriendshipDto>());
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using AutoMapper;
|
||||
using Govor.Application.Exceptions.FriendsService;
|
||||
using Govor.Application.Interfaces.Friends;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Friends;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Core.Models.Users;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers.Friends;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Groups;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.Medias;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Medias;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.UserOnlineStatus;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.PingHandler;
|
||||
using Govor.Application.Users.UserOnlineStatus;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -40,16 +40,6 @@ public class OnlinePingingController : Controller
|
||||
_logger.LogInformation($"Ping from user {id} processed successfully");
|
||||
return Ok();
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
return BadRequest("User can't be found in our database.");
|
||||
}
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
return Forbid(e.Message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Exceptions.VerifyFriendship;
|
||||
using Govor.Application.Friends;
|
||||
using Govor.Application.Infrastructure.AdminsStuff;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.PrivateUserChats;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Repositories.PrivateChats;
|
||||
using Govor.Core.Repositories.Users;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -16,7 +15,6 @@ namespace Govor.API.Controllers;
|
||||
public class PrivateChatController : Controller
|
||||
{
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
private readonly IUsersRepository _usersRepository;
|
||||
private readonly IVerifyFriendship _verifyFriendship;
|
||||
private readonly IUserPrivateChatsCreator _userPrivateChatsCreator;
|
||||
private readonly IUserPrivateChatsGetterService _privateChatsGetter;
|
||||
@@ -24,15 +22,12 @@ public class PrivateChatController : Controller
|
||||
|
||||
public PrivateChatController(
|
||||
ICurrentUserService currentUser,
|
||||
IUsersRepository usersRepository,
|
||||
IVerifyFriendship verifyFriendship,
|
||||
IPrivateChatsRepository privateChats,
|
||||
IUserPrivateChatsCreator userPrivateChatsCreator,
|
||||
IUserPrivateChatsGetterService userPrivateChatsGetterService,
|
||||
ILogger<ChatLoadController> logger)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_usersRepository = usersRepository;
|
||||
_verifyFriendship = verifyFriendship;
|
||||
_userPrivateChatsCreator = userPrivateChatsCreator;
|
||||
_privateChatsGetter = userPrivateChatsGetterService;
|
||||
@@ -46,14 +41,8 @@ public class PrivateChatController : Controller
|
||||
{
|
||||
var currentId = _currentUser.GetCurrentUserId();
|
||||
|
||||
if (!await _usersRepository.ExistsByIdAsync(friendId))
|
||||
{
|
||||
_logger.LogWarning("User not exist {0}", friendId);
|
||||
return NotFound("User not exist.");
|
||||
}
|
||||
|
||||
await _verifyFriendship.VerifyAsync(currentId, friendId);
|
||||
|
||||
|
||||
var chat = await _userPrivateChatsCreator.CreateAsync(currentId, friendId);
|
||||
return Ok(chat.Id);
|
||||
}
|
||||
@@ -62,16 +51,16 @@ public class PrivateChatController : Controller
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (FriendshipException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using AutoMapper;
|
||||
using Govor.API.Hubs;
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.Medias;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Medias;
|
||||
using Govor.Application.Profiles;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
@@ -91,8 +90,12 @@ public class ProfileController : ControllerBase
|
||||
try
|
||||
{
|
||||
var userId = _currentUserService.GetCurrentUserId();
|
||||
var user = await _profileService.GetUserProfileAsync(userId);
|
||||
var result = await _profileService.GetUserProfileAsync(userId);
|
||||
|
||||
if(result.IsFailure)
|
||||
return NotFound(result.Error);
|
||||
|
||||
var user = result.Value;
|
||||
var dto = _mapper.Map<UserProfileDto>(user);
|
||||
return Ok(dto);
|
||||
}
|
||||
@@ -101,11 +104,6 @@ public class ProfileController : ControllerBase
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound("Profile not found");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
@@ -128,11 +126,6 @@ public class ProfileController : ControllerBase
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound("Profile not found");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.PushNotifications;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Repositories.PushTokens;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -13,15 +13,15 @@ public class PushTokensController : Controller
|
||||
{
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
private readonly ICurrentUserSessionService _currentSession;
|
||||
private readonly IPushTokenRepository _pushTokenRepo;
|
||||
private readonly IPushTokenService _pushTokenService;
|
||||
|
||||
public PushTokensController(
|
||||
IPushTokenService pushTokenService,
|
||||
ICurrentUserService currentUser,
|
||||
ICurrentUserSessionService currentSession,
|
||||
IPushTokenRepository pushTokenRepository)
|
||||
ICurrentUserSessionService currentSession)
|
||||
{
|
||||
_pushTokenService = pushTokenService;
|
||||
_currentUser = currentUser;
|
||||
_pushTokenRepo = pushTokenRepository;
|
||||
_currentSession = currentSession;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PushTokensController : Controller
|
||||
var currentId = _currentUser.GetCurrentUserId();
|
||||
var currentSessionId = _currentSession.GetUserSessionId();
|
||||
|
||||
await _pushTokenRepo.AddOrUpdateTokenAsync(
|
||||
await _pushTokenService.AddOrUpdateTokenAsync(
|
||||
userId: currentId,
|
||||
sessionId: currentSessionId,
|
||||
token: req.Token,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using AutoMapper;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.UserSession;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Users.UserSessions;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Core.Repositories.PushTokens;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -43,7 +41,11 @@ public class SessionController : Controller
|
||||
try
|
||||
{
|
||||
var sessions = await _userSessionReader.GetAllSessionsAsync(_currentUserService.GetCurrentUserId());
|
||||
return Ok(_mapper.Map<List<SessionDto>>(sessions));
|
||||
|
||||
if(sessions.IsFailure)
|
||||
return NotFound(sessions.Error);
|
||||
|
||||
return Ok(_mapper.Map<List<SessionDto>>(sessions.Value));
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
@@ -65,8 +67,12 @@ public class SessionController : Controller
|
||||
if (sessionId == Guid.Empty)
|
||||
return BadRequest("Invalid sessionId.");
|
||||
|
||||
await _userSessionRevoker.CloseSessionByIdAsync(sessionId,
|
||||
var res = await _userSessionRevoker.CloseSessionByIdAsync(sessionId,
|
||||
_currentUserService.GetCurrentUserId());
|
||||
|
||||
if (res.IsFailure)
|
||||
return BadRequest(res.Error);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
@@ -79,11 +85,6 @@ public class SessionController : Controller
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
@@ -96,11 +97,14 @@ public class SessionController : Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
await _userSessionRevoker.CloseSessionByIdAsync(
|
||||
var res = await _userSessionRevoker.CloseSessionByIdAsync(
|
||||
_currentUserSessionService.GetUserSessionId(),
|
||||
_currentUserService.GetCurrentUserId());
|
||||
|
||||
return Ok();
|
||||
|
||||
if(res.IsFailure)
|
||||
return NotFound(res.Error);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
@@ -112,11 +116,6 @@ public class SessionController : Controller
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
@@ -129,7 +128,11 @@ public class SessionController : Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
await _userSessionRevoker.CloseAllSessionsAsync(_currentUserService.GetCurrentUserId());
|
||||
var res = await _userSessionRevoker.CloseAllSessionsAsync(_currentUserService.GetCurrentUserId());
|
||||
|
||||
if(res.IsFailure)
|
||||
return NotFound(res.Error);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
|
||||
Reference in New Issue
Block a user