diff --git a/Govor.API.Tests/Controllers/SessionControllerTests.cs b/Govor.API.Tests/Controllers/SessionControllerTests.cs
index f3190db..c7d22d5 100644
--- a/Govor.API.Tests/Controllers/SessionControllerTests.cs
+++ b/Govor.API.Tests/Controllers/SessionControllerTests.cs
@@ -3,7 +3,7 @@ using Govor.API.Controllers;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Application.Interfaces.UserSession;
using Govor.Contracts.DTOs;
-using Govor.Core.Models.Users;
+using Govor.Domain.Models.Users;
using Govor.Data.Repositories.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
diff --git a/Govor.API.Tests/Govor.API.Tests.csproj b/Govor.API.Tests/Govor.API.Tests.csproj
index 26fdd64..da8779c 100644
--- a/Govor.API.Tests/Govor.API.Tests.csproj
+++ b/Govor.API.Tests/Govor.API.Tests.csproj
@@ -27,6 +27,5 @@
-
diff --git a/Govor.API.Tests/Hubs/PresenceHubTests.cs b/Govor.API.Tests/Hubs/PresenceHubTests.cs
index 8318c70..99ddc91 100644
--- a/Govor.API.Tests/Hubs/PresenceHubTests.cs
+++ b/Govor.API.Tests/Hubs/PresenceHubTests.cs
@@ -2,8 +2,8 @@ using AutoFixture;
using Govor.API.Common.SignalR.Helpers;
using Govor.API.Hubs;
using Govor.Application.Interfaces.UserOnlineStatus;
-using Govor.Core.Models.Users;
-using Govor.Core.Repositories.Users;
+using Govor.Domain.Models.Users;
+using Govor.Domain.Repositories.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs
index d216655..54f4953 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs
@@ -1,12 +1,12 @@
using AutoFixture;
using Govor.API.Controllers.Authentication;
-using Govor.Application.Exceptions.AuthService;
+using Govor.Application.Authentication.Exceptions;
using Govor.Application.Exceptions.InvitesService;
using Govor.Application.Interfaces.Authentication;
using Govor.Application.Interfaces.UserSession;
using Govor.Contracts.Requests;
-using Govor.Core.Models;
-using Govor.Core.Models.Users;
+using Govor.Domain.Models;
+using Govor.Domain.Models.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/ChatLoadControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/ChatLoadControllerTests.cs
index bc5fb08..cfaf2bd 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/ChatLoadControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/ChatLoadControllerTests.cs
@@ -3,9 +3,10 @@ using AutoMapper;
using Govor.API.Controllers;
using Govor.Application.Interfaces;
using Govor.Application.Interfaces.Infrastructure.Extensions;
+using Govor.Application.Messages;
using Govor.Contracts.Requests;
using Govor.Contracts.Responses;
-using Govor.Core.Models.Messages;
+using Govor.Domain.Models.Messages;
using Govor.Data.Repositories.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/FriendsRequestQueryControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/FriendsRequestQueryControllerTests.cs
index 1d2b6c1..2f9b8a1 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/FriendsRequestQueryControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/FriendsRequestQueryControllerTests.cs
@@ -4,7 +4,7 @@ using Govor.API.Controllers.Friends;
using Govor.Application.Interfaces.Friends;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Contracts.DTOs;
-using Govor.Core.Models;
+using Govor.Domain.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/FriendshipControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/FriendshipControllerTests.cs
index 6d712fb..98eb09e 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/FriendshipControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/FriendshipControllerTests.cs
@@ -5,7 +5,7 @@ using Govor.Application.Exceptions.FriendsService;
using Govor.Application.Interfaces.Friends;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Contracts.DTOs;
-using Govor.Core.Models.Users;
+using Govor.Domain.Models.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/MediaControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/MediaControllerTests.cs
index 0cf8f7e..3e74058 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/MediaControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/MediaControllerTests.cs
@@ -4,7 +4,7 @@ using Govor.API.Controllers;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Application.Interfaces.Medias;
using Govor.Contracts.Requests;
-using Govor.Core.Models.Messages;
+using Govor.Domain.Models.Messages;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/OnlinePingingControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/OnlinePingingControllerTests.cs
index 0133572..d99c066 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/OnlinePingingControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/OnlinePingingControllerTests.cs
@@ -1,6 +1,7 @@
using Govor.API.Controllers;
using Govor.Application.Interfaces;
using Govor.Application.Interfaces.Infrastructure.Extensions;
+using Govor.Application.PingHandler;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
diff --git a/Govor.API.Tests/IntegrationTests/Controllers/ProfileControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/ProfileControllerTests.cs
index 1e73e2d..83653e8 100644
--- a/Govor.API.Tests/IntegrationTests/Controllers/ProfileControllerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Controllers/ProfileControllerTests.cs
@@ -8,8 +8,8 @@ using Govor.Application.Interfaces.Medias;
using Govor.Application.Profiles;
using Govor.Contracts.DTOs;
using Govor.Contracts.Requests;
-using Govor.Core.Models;
-using Govor.Core.Models.Messages;
+using Govor.Domain.Models;
+using Govor.Domain.Models.Messages;
using Govor.Data.Repositories.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
diff --git a/Govor.API.Tests/IntegrationTests/Hubs/FriendsHubTests.cs b/Govor.API.Tests/IntegrationTests/Hubs/FriendsHubTests.cs
index e0ee94d..c5a2bd0 100644
--- a/Govor.API.Tests/IntegrationTests/Hubs/FriendsHubTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Hubs/FriendsHubTests.cs
@@ -7,7 +7,7 @@ using Govor.Application.Interfaces.Friends;
using Govor.Application.Interfaces.Infrastructure.Extensions;
using Govor.Contracts.DTOs;
using Govor.Contracts.Responses.SignalR;
-using Govor.Core.Models;
+using Govor.Domain.Models;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Moq;
diff --git a/Govor.API.Tests/IntegrationTests/Hubs/Infrastructure/PrivateChatGroupManagerTests.cs b/Govor.API.Tests/IntegrationTests/Hubs/Infrastructure/PrivateChatGroupManagerTests.cs
index bf931f4..57c69cc 100644
--- a/Govor.API.Tests/IntegrationTests/Hubs/Infrastructure/PrivateChatGroupManagerTests.cs
+++ b/Govor.API.Tests/IntegrationTests/Hubs/Infrastructure/PrivateChatGroupManagerTests.cs
@@ -1,7 +1,8 @@
using Govor.API.Hubs;
using Govor.API.Hubs.Infrastructure;
+using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Interfaces;
-using Govor.Core.Models;
+using Govor.Domain.Models;
using Microsoft.AspNetCore.SignalR;
using Moq;
diff --git a/Govor.API.Tests/LocalStorageServiceTests.cs b/Govor.API.Tests/LocalStorageServiceTests.cs
index aff7ac8..f6be86e 100644
--- a/Govor.API.Tests/LocalStorageServiceTests.cs
+++ b/Govor.API.Tests/LocalStorageServiceTests.cs
@@ -1,6 +1,5 @@
using AutoFixture;
using Govor.Application.Interfaces;
-using Govor.Application.Services;
using Microsoft.AspNetCore.Hosting;
using Moq;
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/ChatGroupValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/ChatGroupValidatorTests.cs
index 42986c0..57a0afe 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/ChatGroupValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/ChatGroupValidatorTests.cs
@@ -1,6 +1,6 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/FriendshipValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/FriendshipValidatorTests.cs
index 2b49311..5d8bf0a 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/FriendshipValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/FriendshipValidatorTests.cs
@@ -1,6 +1,6 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationConstantsTests.cs
similarity index 94%
rename from Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationValidatorTests.cs
rename to Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationConstantsTests.cs
index 38a7775..bb787f7 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/InvitationConstantsTests.cs
@@ -1,18 +1,18 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
[TestFixture]
-public class InvitationValidatorTests
+public class InvitationConstantsTests
{
private IObjectValidator _messageValidator;
private Fixture _fixture;
- public InvitationValidatorTests()
+ public InvitationConstantsTests()
{
- _messageValidator = new InvitationValidator();
+ _messageValidator = new InvitationConstants();
_fixture = new Fixture();
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/MessageValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/MessageValidatorTests.cs
index 8472243..aa9fb94 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/MessageValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/MessageValidatorTests.cs
@@ -1,7 +1,7 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
-using Govor.Core.Models.Messages;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
+using Govor.Domain.Models.Messages;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/PrivateChatValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/PrivateChatValidatorTests.cs
index 43d54d1..f38c98e 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/PrivateChatValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/PrivateChatValidatorTests.cs
@@ -1,6 +1,6 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
diff --git a/Govor.API.Tests/UnitTests/Infrastructure/Validators/UserValidatorTests.cs b/Govor.API.Tests/UnitTests/Infrastructure/Validators/UserConstantsTests.cs
similarity index 96%
rename from Govor.API.Tests/UnitTests/Infrastructure/Validators/UserValidatorTests.cs
rename to Govor.API.Tests/UnitTests/Infrastructure/Validators/UserConstantsTests.cs
index c7d9162..487d1ec 100644
--- a/Govor.API.Tests/UnitTests/Infrastructure/Validators/UserValidatorTests.cs
+++ b/Govor.API.Tests/UnitTests/Infrastructure/Validators/UserConstantsTests.cs
@@ -1,12 +1,12 @@
using AutoFixture;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
-using Govor.Core.Models.Users;
+using Govor.Domain.Common.Constants;
+using Govor.Domain.Models;
+using Govor.Domain.Models.Users;
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
[TestFixture]
-public class UserValidatorTests
+public class UserConstantsTests
{
private IObjectValidator _userValidator;
private Fixture _fixture;
@@ -14,7 +14,7 @@ public class UserValidatorTests
[SetUp]
public void SetUp()
{
- _userValidator = new UserValidator();
+ _userValidator = new UserConstants();
_fixture = new Fixture();
diff --git a/Govor.API/Common/Extensions/AddOptionExtensions.cs b/Govor.API/Common/Extensions/AddOptionExtensions.cs
index 060de2b..b31b5cf 100644
--- a/Govor.API/Common/Extensions/AddOptionExtensions.cs
+++ b/Govor.API/Common/Extensions/AddOptionExtensions.cs
@@ -1,4 +1,4 @@
-using Govor.Application.Services.Authentication;
+using Govor.Application.Authentication.JWT;
namespace Govor.API.Common.Extensions;
diff --git a/Govor.API/Common/Extensions/ConfigurationProgramExtensions.cs b/Govor.API/Common/Extensions/ConfigurationProgramExtensions.cs
index 6de6259..f79650d 100644
--- a/Govor.API/Common/Extensions/ConfigurationProgramExtensions.cs
+++ b/Govor.API/Common/Extensions/ConfigurationProgramExtensions.cs
@@ -1,46 +1,27 @@
using Govor.API.Common.Mapping;
using Govor.API.Common.SignalR.Helpers;
using Govor.API.Hubs.Infrastructure;
+using Govor.Application.Authentication;
+using Govor.Application.Authentication.JWT;
+using Govor.Application.Friends;
+using Govor.Application.Groups;
using Govor.Application.Infrastructure.AdminsStuff;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Infrastructure.Validators;
-using Govor.Application.Interfaces;
-using Govor.Application.Interfaces.Authentication;
-using Govor.Application.Interfaces.Friends;
-using Govor.Application.Interfaces.Infrastructure.Extensions;
-using Govor.Application.Interfaces.Medias;
-using Govor.Application.Interfaces.Messages;
-using Govor.Application.Interfaces.PushNotifications;
-using Govor.Application.Interfaces.UserOnlineStatus;
-using Govor.Application.Interfaces.UserSession;
-using Govor.Application.Interfaces.UserSession.Crypto;
-using Govor.Application.Services;
-using Govor.Application.Services.Authentication;
-using Govor.Application.Services.Friends;
-using Govor.Application.Services.Medias;
-using Govor.Application.Services.Messages;
-using Govor.Application.Services.PushNotifications;
-using Govor.Application.Services.PushNotifications.Providers;
-using Govor.Application.Services.UserOnlineStatus;
-using Govor.Application.Services.UserSessions;
-using Govor.Application.Services.UserSessions.Crypto;
-using Govor.Core.Infrastructure.Extensions;
-using Govor.Core.Infrastructure.Validators;
-using Govor.Core.Models;
-using Govor.Core.Models.Messages;
-using Govor.Core.Models.Users;
-using Govor.Core.Repositories.Admins;
-using Govor.Core.Repositories.Friendships;
-using Govor.Core.Repositories.Groups;
-using Govor.Core.Repositories.Invaites;
-using Govor.Core.Repositories.MediasAttachments;
-using Govor.Core.Repositories.Messages;
-using Govor.Core.Repositories.PrivateChats;
-using Govor.Core.Repositories.PushTokens;
-using Govor.Core.Repositories.Users;
-using Govor.Core.Repositories.UserSessionsRepository;
-using Govor.Data;
-using Govor.Data.Repositories;
+using Govor.Application.Medias;
+using Govor.Application.Messages;
+using Govor.Application.PingHandler;
+using Govor.Application.PrivateUserChats;
+using Govor.Application.Profiles;
+using Govor.Application.PushNotifications;
+using Govor.Application.PushNotifications.Providers;
+using Govor.Application.Storage;
+using Govor.Application.Synching;
+using Govor.Application.Users;
+using Govor.Application.Users.UserOnlineStatus;
+using Govor.Application.Users.UserSessions;
+using Govor.Application.Users.UserSessions.Crypto;
+using Govor.Domain;
using Microsoft.EntityFrameworkCore;
namespace Govor.API.Common.Extensions;
@@ -56,6 +37,7 @@ public static class ConfigurationProgramExtensions
services.AddScoped();
services.AddScoped();
services.AddScoped();
+ services.AddScoped();
services.AddScoped();
services.AddScoped();
@@ -80,7 +62,10 @@ public static class ConfigurationProgramExtensions
services.AddScoped();
- services.AddScoped();
+ //services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
@@ -88,6 +73,9 @@ public static class ConfigurationProgramExtensions
services.AddScoped();
services.AddScoped();
+ // User
+ services.AddScoped();
+
// UserSession
services.AddScoped();
services.AddScoped();
@@ -104,6 +92,7 @@ public static class ConfigurationProgramExtensions
services.AddSingleton();
// Pushs
+ services.AddScoped();
services.AddScoped();
services.AddSingleton();
@@ -122,34 +111,7 @@ public static class ConfigurationProgramExtensions
services.AddScoped();
}
-
- public static void AddRepositories(this IServiceCollection services)
- {
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- services.AddScoped();
- // other
- }
-
- public static void AddValidators(this IServiceCollection services)
- {
- services.AddScoped, UserValidator>();
- services.AddScoped, MessageValidator>();
- services.AddScoped, MediaAttachmentsValidator>();
- services.AddScoped, AdminValidator>();
- services.AddScoped, InvitationValidator>();
- services.AddScoped, FriendshipValidator>();
- services.AddScoped, PrivateChatValidator>();
- services.AddScoped, ChatGroupValidator>();
- }
-
+
public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration)
{
var useMySql = configuration.GetValue("UseMySql");
diff --git a/Govor.API/Common/Mapping/MappingProfile.cs b/Govor.API/Common/Mapping/MappingProfile.cs
index 4ad619d..0921426 100644
--- a/Govor.API/Common/Mapping/MappingProfile.cs
+++ b/Govor.API/Common/Mapping/MappingProfile.cs
@@ -1,11 +1,10 @@
using AutoMapper;
-using Govor.API.Extensions.Mapping;
using Govor.Application.Profiles;
using Govor.Contracts.DTOs;
using Govor.Contracts.Responses;
-using Govor.Core.Models;
-using Govor.Core.Models.Messages;
-using Govor.Core.Models.Users;
+using Govor.Domain.Models;
+using Govor.Domain.Models.Messages;
+using Govor.Domain.Models.Users;
namespace Govor.API.Common.Mapping;
diff --git a/Govor.API/Common/Mapping/UserProfileToUserProfileDtoMappingAction.cs b/Govor.API/Common/Mapping/UserProfileToUserProfileDtoMappingAction.cs
index 2a7be87..01d57e1 100644
--- a/Govor.API/Common/Mapping/UserProfileToUserProfileDtoMappingAction.cs
+++ b/Govor.API/Common/Mapping/UserProfileToUserProfileDtoMappingAction.cs
@@ -1,8 +1,7 @@
using AutoMapper;
-using Govor.Application.Interfaces.UserOnlineStatus;
using Govor.Application.Profiles;
+using Govor.Application.Users.UserOnlineStatus;
using Govor.Contracts.DTOs;
-using Govor.Core.Models.Users;
namespace Govor.API.Common.Mapping;
diff --git a/Govor.API/Common/Mapping/UserToUserDtoMappingAction.cs b/Govor.API/Common/Mapping/UserToUserDtoMappingAction.cs
index c915fb3..c90ee9b 100644
--- a/Govor.API/Common/Mapping/UserToUserDtoMappingAction.cs
+++ b/Govor.API/Common/Mapping/UserToUserDtoMappingAction.cs
@@ -1,9 +1,9 @@
using AutoMapper;
-using Govor.Application.Interfaces.UserOnlineStatus;
+using Govor.Application.Users.UserOnlineStatus;
using Govor.Contracts.DTOs;
-using Govor.Core.Models.Users;
+using Govor.Domain.Models.Users;
-namespace Govor.API.Extensions.Mapping;
+namespace Govor.API.Common.Mapping;
public class UserToUserDtoMappingAction : IMappingAction
{
diff --git a/Govor.API/Controllers/AdminStuff/FriendshipsController.cs b/Govor.API/Controllers/AdminStuff/FriendshipsController.cs
index 94b5225..2a0e85b 100644
--- a/Govor.API/Controllers/AdminStuff/FriendshipsController.cs
+++ b/Govor.API/Controllers/AdminStuff/FriendshipsController.cs
@@ -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 _logger;
- private readonly IFriendshipsRepository _friendshipsRepository;
- public FriendshipsController(ILogger logger, IFriendshipsRepository friendshipsRepository)
- {
- _logger = logger;
- _friendshipsRepository = friendshipsRepository;
- }
-
+ /*
[HttpGet]
public async Task Get()
{
@@ -88,5 +77,5 @@ public class FriendshipsController : Controller
_logger.LogError(ex, ex.Message);
return StatusCode(500, new { error = "Internal server error." });
}
- }
+ }*/
}
\ No newline at end of file
diff --git a/Govor.API/Controllers/AdminStuff/InviteUserController.cs b/Govor.API/Controllers/AdminStuff/InviteUserController.cs
index 204ae79..d55043f 100644
--- a/Govor.API/Controllers/AdminStuff/InviteUserController.cs
+++ b/Govor.API/Controllers/AdminStuff/InviteUserController.cs
@@ -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 _logger;
public InviteUserController(IInvitationGenerator invitationGenerator,
- IInvitesRepository repository,
+ IInvitationGetter invitationGetter,
ILogger 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 dtos = new List();
@@ -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 dtos = new List();
@@ -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);
diff --git a/Govor.API/Controllers/AdminStuff/UsersController.cs b/Govor.API/Controllers/AdminStuff/UsersController.cs
index 7440264..0a60b3d 100644
--- a/Govor.API/Controllers/AdminStuff/UsersController.cs
+++ b/Govor.API/Controllers/AdminStuff/UsersController.cs
@@ -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 ex)
- {
- _logger.LogWarning(ex, ex.Message);
- return NotFound(ex.Message);
- }
catch (Exception e)
{
_logger.LogError(e, e.Message);
diff --git a/Govor.API/Controllers/Authentication/AuthController.cs b/Govor.API/Controllers/Authentication/AuthController.cs
index 897803f..f1c7fa8 100644
--- a/Govor.API/Controllers/Authentication/AuthController.cs
+++ b/Govor.API/Controllers/Authentication/AuthController.cs
@@ -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 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 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);
}
}
\ No newline at end of file
diff --git a/Govor.API/Controllers/Authentication/RefreshController.cs b/Govor.API/Controllers/Authentication/RefreshController.cs
index ebf95c1..68e81fd 100644
--- a/Govor.API/Controllers/Authentication/RefreshController.cs
+++ b/Govor.API/Controllers/Authentication/RefreshController.cs
@@ -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 _logger;
private readonly IUserSessionRefresher _userSession;
-
+
public RefreshController(
ILogger 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 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
+ });
}
}
\ No newline at end of file
diff --git a/Govor.API/Controllers/Authentication/SessionKeysController.cs b/Govor.API/Controllers/Authentication/SessionKeysController.cs
index 77929ec..4f6558e 100644
--- a/Govor.API/Controllers/Authentication/SessionKeysController.cs
+++ b/Govor.API/Controllers/Authentication/SessionKeysController.cs
@@ -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;
diff --git a/Govor.API/Controllers/ChatLoadController.cs b/Govor.API/Controllers/ChatLoadController.cs
index e4be8b9..550a8ce 100644
--- a/Govor.API/Controllers/ChatLoadController.cs
+++ b/Govor.API/Controllers/ChatLoadController.cs
@@ -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);
diff --git a/Govor.API/Controllers/Friends/FriendsRequestQueryController.cs b/Govor.API/Controllers/Friends/FriendsRequestQueryController.cs
index 542ee89..2d1d367 100644
--- a/Govor.API/Controllers/Friends/FriendsRequestQueryController.cs
+++ b/Govor.API/Controllers/Friends/FriendsRequestQueryController.cs
@@ -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());
- }
- 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());
- }
- catch (UnauthorizedAccessException ex)
- {
- _logger.LogWarning(ex, ex.Message);
- return Forbid(ex.Message);
- }
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
diff --git a/Govor.API/Controllers/Friends/FriendshipController.cs b/Govor.API/Controllers/Friends/FriendshipController.cs
index 25c0065..d375717 100644
--- a/Govor.API/Controllers/Friends/FriendshipController.cs
+++ b/Govor.API/Controllers/Friends/FriendshipController.cs
@@ -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;
diff --git a/Govor.API/Controllers/InviteController.cs b/Govor.API/Controllers/InviteController.cs
index 26ff900..e7de645 100644
--- a/Govor.API/Controllers/InviteController.cs
+++ b/Govor.API/Controllers/InviteController.cs
@@ -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;
diff --git a/Govor.API/Controllers/MediaController.cs b/Govor.API/Controllers/MediaController.cs
index 6c0a870..d6ab259 100644
--- a/Govor.API/Controllers/MediaController.cs
+++ b/Govor.API/Controllers/MediaController.cs
@@ -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;
diff --git a/Govor.API/Controllers/OnlinePingingController.cs b/Govor.API/Controllers/OnlinePingingController.cs
index 0a58dfc..001ce34 100644
--- a/Govor.API/Controllers/OnlinePingingController.cs
+++ b/Govor.API/Controllers/OnlinePingingController.cs
@@ -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);
diff --git a/Govor.API/Controllers/PrivateChatController.cs b/Govor.API/Controllers/PrivateChatController.cs
index 7efc26f..da3873f 100644
--- a/Govor.API/Controllers/PrivateChatController.cs
+++ b/Govor.API/Controllers/PrivateChatController.cs
@@ -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 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);
diff --git a/Govor.API/Controllers/ProfileController.cs b/Govor.API/Controllers/ProfileController.cs
index a58f72e..0f45836 100644
--- a/Govor.API/Controllers/ProfileController.cs
+++ b/Govor.API/Controllers/ProfileController.cs
@@ -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(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);
diff --git a/Govor.API/Controllers/PushTokensController.cs b/Govor.API/Controllers/PushTokensController.cs
index 9577d29..2b53ae4 100644
--- a/Govor.API/Controllers/PushTokensController.cs
+++ b/Govor.API/Controllers/PushTokensController.cs
@@ -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,
diff --git a/Govor.API/Controllers/SessionController.cs b/Govor.API/Controllers/SessionController.cs
index f68b91b..7aacee4 100644
--- a/Govor.API/Controllers/SessionController.cs
+++ b/Govor.API/Controllers/SessionController.cs
@@ -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>(sessions));
+
+ if(sessions.IsFailure)
+ return NotFound(sessions.Error);
+
+ return Ok(_mapper.Map>(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)
diff --git a/Govor.API/Filters/HubExceptionFilter.cs b/Govor.API/Filters/HubExceptionFilter.cs
index fa814fb..f11b6ef 100644
--- a/Govor.API/Filters/HubExceptionFilter.cs
+++ b/Govor.API/Filters/HubExceptionFilter.cs
@@ -70,7 +70,6 @@ public class HubExceptionFilter : IHubFilter
}
}
- // Ничего не возвращаем, если не поддерживается
return null;
}
}
\ No newline at end of file
diff --git a/Govor.API/Govor.API.csproj b/Govor.API/Govor.API.csproj
index 76f5525..c109986 100644
--- a/Govor.API/Govor.API.csproj
+++ b/Govor.API/Govor.API.csproj
@@ -24,10 +24,7 @@
-
-
-
-
+
diff --git a/Govor.API/Hubs/ChatsHub.cs b/Govor.API/Hubs/ChatsHub.cs
index e9136fa..02bb92c 100644
--- a/Govor.API/Hubs/ChatsHub.cs
+++ b/Govor.API/Hubs/ChatsHub.cs
@@ -1,11 +1,11 @@
using Govor.API.Common.SignalR.Helpers;
using Govor.API.Hubs.Infrastructure;
using Govor.Application.Exceptions.VerifyFriendship;
-using Govor.Application.Interfaces.Messages;
-using Govor.Application.Interfaces.Messages.Parameters;
+using Govor.Application.Messages;
+using Govor.Application.Messages.Parameters;
using Govor.Contracts.Requests.SignalR;
using Govor.Contracts.Responses.SignalR;
-using Govor.Core.Models.Messages;
+using Govor.Domain.Models.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
@@ -15,20 +15,24 @@ namespace Govor.API.Hubs;
public class ChatsHub : Hub
{
private readonly ILogger _logger;
- private readonly IMessageCommandService _commandService;
+ private readonly IMessageSendingService _messageSendingService;
+ private readonly IMessageEditingService _messageEditingService;
+ private readonly IMessageRemovingService _messageRemovingService;
private readonly IHubUserAccessor _userAccessor;
private readonly IChatNotificationService _notifier;
private readonly IConnectionManager _connectionManager;
- public ChatsHub(
- ILogger logger,
- IMessageCommandService commandService,
+
+ public ChatsHub(ILogger logger,
+ IMessageSendingService messageSendingService,
+ IMessageEditingService messageEditingService,
IHubUserAccessor userAccessor,
IChatNotificationService notifier,
IConnectionManager connectionManager)
{
_logger = logger;
- _commandService = commandService;
+ _messageSendingService = messageSendingService;
+ _messageEditingService = messageEditingService;
_userAccessor = userAccessor;
_notifier = notifier;
_connectionManager = connectionManager;
@@ -69,7 +73,7 @@ public class ChatsHub : Hub
ValidateMessageRequest(request);
var sendParams = MapToSendMessage(request, userId);
- var result = await _commandService.SendMessageAsync(sendParams);
+ var result = await _messageSendingService.SendMessageAsync(sendParams);
if (!result.IsSuccess)
throw new InvalidOperationException(result.Exception.Message ?? "Failed to send message");
@@ -87,7 +91,7 @@ public class ChatsHub : Hub
{
return await SafeExecute(async (userId) =>
{
- var result = await _commandService.DeleteMessageAsync(new DeleteMessage(userId, request.MessageId));
+ var result = await _messageRemovingService.DeleteMessageAsync(new DeleteMessage(userId, request.MessageId));
if (!result.IsSuccess || result.OriginalMessage == null)
throw new InvalidOperationException("Message deletion failed");
@@ -112,7 +116,7 @@ public class ChatsHub : Hub
return await SafeExecute(async (userId) =>
{
var editParams = new EditMessage(userId, request.MessageId, request.NewEncryptedContent, DateTime.UtcNow);
- var result = await _commandService.EditMessageAsync(editParams);
+ var result = await _messageEditingService.EditMessageAsync(editParams);
if (!result.IsSuccess || result.OriginalMessage == null)
throw new InvalidOperationException("Edit message error");
diff --git a/Govor.API/Hubs/FriendsHub.cs b/Govor.API/Hubs/FriendsHub.cs
index 87b1a36..9871926 100644
--- a/Govor.API/Hubs/FriendsHub.cs
+++ b/Govor.API/Hubs/FriendsHub.cs
@@ -1,7 +1,7 @@
using AutoMapper;
using Govor.API.Common.SignalR.Helpers;
using Govor.Application.Exceptions.FriendsService;
-using Govor.Application.Interfaces.Friends;
+using Govor.Application.Friends;
using Govor.Contracts.DTOs;
using Govor.Contracts.Responses.SignalR;
using Microsoft.AspNetCore.SignalR;
@@ -76,7 +76,12 @@ public class FriendsHub : Hub
try
{
var userId = _userAccessor.GetUserId(Context);
- var friendship = await _friendRequestService.SendAsync(userId, targetUserId);
+ var result = await _friendRequestService.SendAsync(userId, targetUserId);
+
+ if(result.IsFailure)
+ return HubResult