Skip to content

Commit

Permalink
Merge pull request #87 from Tynab/develop
Browse files Browse the repository at this point in the history
remote ecommerce
  • Loading branch information
Tynab authored Feb 3, 2024
2 parents 2b9b33c + c7f2b07 commit 2414475
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ namespace YANLib.Responses;
public sealed record CertificateResponse
{
public string Id { get; set; }

public string Name { get; set; }

public double? GPA { get; set; }

public string DeveloperId { get; set; }

public DateTime CreatedAt { get; set; }

public DateTime? UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ namespace YANLib.Responses;
public sealed record DeveloperResponse
{
public string Id { get; set; }

public string Name { get; set; }

public string Phone { get; set; }

public string IdCard { get; set; }

public bool IsActive { get; set; }

public int Version { get; set; }

public DateTime CreatedAt { get; set; }

public DateTime? UpdatedAt { get; set; }

public DeveloperTypeResponse DeveloperType { get; set; }

public List<CertificateResponse> Certificates { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ namespace YANLib.Responses;
public sealed record DeveloperTypeResponse
{
public int Code { get; set; }

public string Name { get; set; }

public bool IsActive { get; set; }

public DateTime CreatedAt { get; set; }

public DateTime? UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace YANLib.Services;

public interface IEcommerceService : IApplicationService
{
public ValueTask<string> GetAccessToken(EcommerceLoginRequest request);
public ValueTask<object> GetAccessToken(EcommerceLoginRequest request);

public ValueTask<string> GetRefreshToken(string accessToken);
public ValueTask<object> GetRefreshToken(string accessToken);
}
13 changes: 9 additions & 4 deletions src/YANLib.Application/RemoteService/RemoteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ public async ValueTask<T> InvokeApi<T>(string remoteRoot, string path, Method me
if (headers.IsNotEmptyAndNull())
{
headers.ForEach(x => req.AddHeader(x.Key, x.Value));

if (jsonInput.IsNotWhiteSpaceAndNull())
{
_ = req.AddParameter(headers["Content-Type"], jsonInput, RequestBody);
}
}
else
{
_ = req.AddHeader("Accept", "*/*");
_ = req.AddHeader("Content-Type", "application/json");
}

if (jsonInput.IsNotWhiteSpaceAndNull())
{
_ = req.AddParameter("application/json", jsonInput, RequestBody);
if (jsonInput.IsNotWhiteSpaceAndNull())
{
_ = req.AddParameter("application/json", jsonInput, RequestBody);
}
}

if (queryParams.IsNotEmptyAndNull())
Expand Down
11 changes: 5 additions & 6 deletions src/YANLib.Application/Services/EcommerceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ IRemoteService remoteService
private readonly ILogger<EcommerceService> _logger = logger;
private readonly IRemoteService _remoteService = remoteService;

public async ValueTask<string> GetAccessToken(EcommerceLoginRequest request)
public async ValueTask<object> GetAccessToken(EcommerceLoginRequest request)
{
var json = request.Serialize();

try
{
var hdrs = new Dictionary<string, string>
return await _remoteService.InvokeApi<object>(EcommerceApi, Login, Post, headers: new Dictionary<string, string>
{
{ "Accept", "*/*" },
{ "Content-Type", "application/x-www-form-urlencoded" }
};
return await _remoteService.InvokeApi<string>(EcommerceApi, Login, Post, jsonInput: json);
}, queryParams: request.Serialize().Deserialize<Dictionary<string, object>>());
}
catch (Exception ex)
{
Expand All @@ -40,11 +39,11 @@ public async ValueTask<string> GetAccessToken(EcommerceLoginRequest request)
}
}

public async ValueTask<string> GetRefreshToken(string accessToken)
public async ValueTask<object> GetRefreshToken(string accessToken)
{
try
{
return await _remoteService.InvokeApi<string>(EcommerceApi, Refresh, Get, new Dictionary<string, string>
return await _remoteService.InvokeApi<object>(EcommerceApi, TokenRefresh, Get, new Dictionary<string, string>
{
{ "Authorization", $"Bearer {accessToken}" }
});
Expand Down
2 changes: 1 addition & 1 deletion src/YANLib.Domain/YANLibConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public readonly struct RemoteService
public readonly struct Path
{
public const string Login = "login";
public const string Refresh = "refresh";
public const string TokenRefresh = "token/refresh";
}
}
}

0 comments on commit 2414475

Please sign in to comment.