Tuitio refactoring
parent
476481f808
commit
8b5d693201
|
@ -31,7 +31,7 @@ namespace Tuitio.Application.CommandHandlers
|
|||
if (loginResult == null)
|
||||
{
|
||||
_logger.LogDebug($"Login failed for user '{command.UserName}'.");
|
||||
return Envelope<AccountLoginResult>.Error(EnvelopeStatus.BAD_CREDENTIALS);
|
||||
return Envelope<AccountLoginResult>.Fail(EnvelopeError.BAD_CREDENTIALS);
|
||||
}
|
||||
|
||||
_logger.LogDebug($"Login succeeded for user '{command.UserName}'.");
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Tuitio.Application.CommandHandlers
|
|||
if (logoutResult == null)
|
||||
{
|
||||
_logger.LogDebug($"Logout failed for token '{command.Token}'.");
|
||||
return Envelope<AccountLogoutResult>.Error(EnvelopeStatus.UNAUTHENTICATED);
|
||||
return Envelope<AccountLogoutResult>.Fail(EnvelopeError.UNAUTHENTICATED);
|
||||
}
|
||||
|
||||
_logger.LogDebug($"Logout succeeded for user '{logoutResult.UserName}'.");
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Tuitio.Application.CommandHandlers
|
|||
if (token == null)
|
||||
{
|
||||
_logger.LogDebug($"Authorization failed for token '{command.Token}'.");
|
||||
var result = Envelope<AuthorizationResult>.Error(EnvelopeStatus.UNAUTHORIZED);
|
||||
var result = Envelope<AuthorizationResult>.Fail(EnvelopeError.UNAUTHORIZED);
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Tuitio.PublishedLanguage.Constants
|
||||
{
|
||||
public struct EnvelopeStatus
|
||||
public struct EnvelopeError
|
||||
{
|
||||
public const string
|
||||
BAD_CREDENTIALS = "BAD_CREDENTIALS",
|
|
@ -5,12 +5,12 @@ namespace Tuitio.PublishedLanguage.Dto
|
|||
public class Envelope<T> where T : class
|
||||
{
|
||||
public T Result { get; }
|
||||
public string Status { get; }
|
||||
public string Error { get; }
|
||||
|
||||
public Envelope(T result, string status)
|
||||
public Envelope(T result, string error)
|
||||
{
|
||||
Result=result;
|
||||
Status=status;
|
||||
Error=error;
|
||||
}
|
||||
|
||||
public static Envelope<T> Success(T result)
|
||||
|
@ -18,7 +18,7 @@ namespace Tuitio.PublishedLanguage.Dto
|
|||
return new Envelope<T>(result, null);
|
||||
}
|
||||
|
||||
public static Envelope<T> Error(string message)
|
||||
public static Envelope<T> Fail(string message)
|
||||
{
|
||||
return new Envelope<T>(null, message);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ namespace Tuitio.Wrapper.Services
|
|||
{
|
||||
public interface ITuitioService
|
||||
{
|
||||
Task<AccountLoginResult> Login(string userName, string password);
|
||||
Task<AuthorizationResult> Authorize(string token);
|
||||
Task<Envelope<AccountLoginResult>> Login(string userName, string password);
|
||||
Task<Envelope<AccountLogoutResult>> Logout(string token);
|
||||
Task<Envelope<AuthorizationResult>> Authorize(string token);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,24 +24,24 @@ namespace Tuitio.Wrapper.Services
|
|||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<AccountLoginResult> Login(string userName, string password)
|
||||
public async Task<Envelope<AccountLoginResult>> Login(string userName, string password)
|
||||
{
|
||||
var route = string.Format(ApiRoutes.AccountLogin, userName, password);
|
||||
var result = await _httpClient.ExecutePostRequest<AccountLoginResult>(route);
|
||||
var result = await _httpClient.ExecutePostRequest<Envelope<AccountLoginResult>>(route);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<AccountLogoutResult> Logout(string token)
|
||||
public async Task<Envelope<AccountLogoutResult>> Logout(string token)
|
||||
{
|
||||
var route = string.Format(ApiRoutes.AccountLogout, token);
|
||||
var result = await _httpClient.ExecutePostRequest<AccountLogoutResult>(route);
|
||||
var result = await _httpClient.ExecutePostRequest<Envelope<AccountLogoutResult>>(route);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<AuthorizationResult> Authorize(string token)
|
||||
public async Task<Envelope<AuthorizationResult>> Authorize(string token)
|
||||
{
|
||||
var route = string.Format(ApiRoutes.Authorization, token);
|
||||
var result = await _httpClient.ExecutePostRequest<AuthorizationResult>(route);
|
||||
var result = await _httpClient.ExecutePostRequest<Envelope<AuthorizationResult>>(route);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue