Tuitio refactoring

master
Tudor Stanciu 2023-03-07 20:36:12 +02:00
parent 476481f808
commit 8b5d693201
7 changed files with 18 additions and 17 deletions

View File

@ -31,7 +31,7 @@ namespace Tuitio.Application.CommandHandlers
if (loginResult == null) if (loginResult == null)
{ {
_logger.LogDebug($"Login failed for user '{command.UserName}'."); _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}'."); _logger.LogDebug($"Login succeeded for user '{command.UserName}'.");

View File

@ -34,7 +34,7 @@ namespace Tuitio.Application.CommandHandlers
if (logoutResult == null) if (logoutResult == null)
{ {
_logger.LogDebug($"Logout failed for token '{command.Token}'."); _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}'."); _logger.LogDebug($"Logout succeeded for user '{logoutResult.UserName}'.");

View File

@ -34,7 +34,7 @@ namespace Tuitio.Application.CommandHandlers
if (token == null) if (token == null)
{ {
_logger.LogDebug($"Authorization failed for token '{command.Token}'."); _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); return Task.FromResult(result);
} }

View File

@ -2,7 +2,7 @@
namespace Tuitio.PublishedLanguage.Constants namespace Tuitio.PublishedLanguage.Constants
{ {
public struct EnvelopeStatus public struct EnvelopeError
{ {
public const string public const string
BAD_CREDENTIALS = "BAD_CREDENTIALS", BAD_CREDENTIALS = "BAD_CREDENTIALS",

View File

@ -5,12 +5,12 @@ namespace Tuitio.PublishedLanguage.Dto
public class Envelope<T> where T : class public class Envelope<T> where T : class
{ {
public T Result { get; } 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; Result=result;
Status=status; Error=error;
} }
public static Envelope<T> Success(T result) public static Envelope<T> Success(T result)
@ -18,7 +18,7 @@ namespace Tuitio.PublishedLanguage.Dto
return new Envelope<T>(result, null); 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); return new Envelope<T>(null, message);
} }

View File

@ -7,7 +7,8 @@ namespace Tuitio.Wrapper.Services
{ {
public interface ITuitioService public interface ITuitioService
{ {
Task<AccountLoginResult> Login(string userName, string password); Task<Envelope<AccountLoginResult>> Login(string userName, string password);
Task<AuthorizationResult> Authorize(string token); Task<Envelope<AccountLogoutResult>> Logout(string token);
Task<Envelope<AuthorizationResult>> Authorize(string token);
} }
} }

View File

@ -24,24 +24,24 @@ namespace Tuitio.Wrapper.Services
_httpClient = httpClient; _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 route = string.Format(ApiRoutes.AccountLogin, userName, password);
var result = await _httpClient.ExecutePostRequest<AccountLoginResult>(route); var result = await _httpClient.ExecutePostRequest<Envelope<AccountLoginResult>>(route);
return result; 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 route = string.Format(ApiRoutes.AccountLogout, token);
var result = await _httpClient.ExecutePostRequest<AccountLogoutResult>(route); var result = await _httpClient.ExecutePostRequest<Envelope<AccountLogoutResult>>(route);
return result; 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 route = string.Format(ApiRoutes.Authorization, token);
var result = await _httpClient.ExecutePostRequest<AuthorizationResult>(route); var result = await _httpClient.ExecutePostRequest<Envelope<AuthorizationResult>>(route);
return result; return result;
} }
} }