Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Sep 9, 2024
1 parent 16f1958 commit 6a07c95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
20 changes: 5 additions & 15 deletions src/EthernaSSO/Areas/Api/Controllers/IdentityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

/// <summary>
Expand All @@ -48,7 +38,7 @@ public IdentityController(
[SimpleExceptionFilter]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<PrivateUserDto> GetCurrentUserAsync() =>
await controllerService.TryGetPrivateUserInfoByClaimsAsync(User) ?? throw new InvalidOperationException();
await service.TryGetPrivateUserInfoByClaimsAsync(User) ?? throw new InvalidOperationException();

/// <summary>
/// Get information about user by its ethereum address.
Expand All @@ -62,7 +52,7 @@ public async Task<PrivateUserDto> GetCurrentUserAsync() =>
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Task<UserDto> GetUserByEtherAddressAsync(string etherAddress) =>
controllerService.GetUserByEtherAddressAsync(etherAddress);
service.GetUserByEtherAddressAsync(etherAddress);

/// <summary>
/// Verify if an email is registered.
Expand All @@ -75,7 +65,7 @@ public Task<UserDto> GetUserByEtherAddressAsync(string etherAddress) =>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public Task<bool> IsEmailRegistered(string email) =>
controllerService.IsEmailRegisteredAsync(email);
service.IsEmailRegisteredAsync(email);

/// <summary>
/// Get information about user by its username.
Expand All @@ -88,6 +78,6 @@ public Task<bool> IsEmailRegistered(string email) =>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Task<UserDto> GetUserByUsernameAsync(string username) =>
controllerService.GetUserByUsernameAsync(username);
service.GetUserByUsernameAsync(username);
}
}
13 changes: 2 additions & 11 deletions src/EthernaSSO/Areas/Api/Controllers/ServiceInteractController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// Get contact information about an user.
/// </summary>
Expand All @@ -49,6 +40,6 @@ public ServiceInteractController(IServiceInteractControllerService controllerSer
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Task<UserContactInfoDto> GetUserContactInfoAsync(string etherAddress) =>
controllerService.GetUserContactInfoAsync(etherAddress);
service.GetUserContactInfoAsync(etherAddress);
}
}

0 comments on commit 6a07c95

Please sign in to comment.