From 6a07c956c001fc75c419dd9a58fe30434b1b5a3e Mon Sep 17 00:00:00 2001 From: Mirko Da Corte Date: Mon, 9 Sep 2024 03:36:53 +0200 Subject: [PATCH] refactor --- .../Api/Controllers/IdentityController.cs | 20 +++++-------------- .../Controllers/ServiceInteractController.cs | 13 ++---------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs b/src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs index e678506..42775a2 100644 --- a/src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs +++ b/src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs @@ -26,18 +26,8 @@ namespace Etherna.SSOServer.Areas.Api.Controllers [ApiController] [ApiVersion("0.3")] [Route("api/v{api-version:apiVersion}/[controller]")] - public class IdentityController : Controller + public class IdentityController(IIdentityControllerService service) : Controller { - // Fields. - private readonly IIdentityControllerService controllerService; - - // Constructors. - public IdentityController( - IIdentityControllerService controllerService) - { - this.controllerService = controllerService; - } - // GET. /// @@ -48,7 +38,7 @@ public IdentityController( [SimpleExceptionFilter] [ProducesResponseType(StatusCodes.Status200OK)] public async Task GetCurrentUserAsync() => - await controllerService.TryGetPrivateUserInfoByClaimsAsync(User) ?? throw new InvalidOperationException(); + await service.TryGetPrivateUserInfoByClaimsAsync(User) ?? throw new InvalidOperationException(); /// /// Get information about user by its ethereum address. @@ -62,7 +52,7 @@ public async Task GetCurrentUserAsync() => [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetUserByEtherAddressAsync(string etherAddress) => - controllerService.GetUserByEtherAddressAsync(etherAddress); + service.GetUserByEtherAddressAsync(etherAddress); /// /// Verify if an email is registered. @@ -75,7 +65,7 @@ public Task GetUserByEtherAddressAsync(string etherAddress) => [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public Task IsEmailRegistered(string email) => - controllerService.IsEmailRegisteredAsync(email); + service.IsEmailRegisteredAsync(email); /// /// Get information about user by its username. @@ -88,6 +78,6 @@ public Task IsEmailRegistered(string email) => [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetUserByUsernameAsync(string username) => - controllerService.GetUserByUsernameAsync(username); + service.GetUserByUsernameAsync(username); } } diff --git a/src/EthernaSSO/Areas/Api/Controllers/ServiceInteractController.cs b/src/EthernaSSO/Areas/Api/Controllers/ServiceInteractController.cs index dda0949..dad36b8 100644 --- a/src/EthernaSSO/Areas/Api/Controllers/ServiceInteractController.cs +++ b/src/EthernaSSO/Areas/Api/Controllers/ServiceInteractController.cs @@ -27,17 +27,8 @@ namespace Etherna.SSOServer.Areas.Api.Controllers [ApiVersion("0.3")] [Route("api/v{api-version:apiVersion}/[controller]")] [Authorize(CommonConsts.ServiceInteractApiScopePolicy)] - public class ServiceInteractController : ControllerBase + public class ServiceInteractController(IServiceInteractControllerService service) : ControllerBase { - // Fields. - private readonly IServiceInteractControllerService controllerService; - - // Constructor. - public ServiceInteractController(IServiceInteractControllerService controllerService) - { - this.controllerService = controllerService; - } - /// /// Get contact information about an user. /// @@ -49,6 +40,6 @@ public ServiceInteractController(IServiceInteractControllerService controllerSer [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetUserContactInfoAsync(string etherAddress) => - controllerService.GetUserContactInfoAsync(etherAddress); + service.GetUserContactInfoAsync(etherAddress); } }