Skip to content

Commit

Permalink
Update BaseCallerService.cs (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 authored Feb 18, 2024
1 parent fa50e5d commit e50ae53
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ protected ServiceBase(ICaller caller)

protected async Task<TResponse> GetAsync<TResponse>(string methodName, Dictionary<string, string>? paramters = null)
{
return await Caller.GetAsync<TResponse>(BuildAdress(methodName), paramters ?? new()) ?? throw new UserFriendlyException("The service is abnormal, please contact the administrator!");
return await Caller.GetAsync<TResponse>(BuildAddress(methodName), paramters ?? new()) ?? throw new UserFriendlyException("The service is abnormal, please contact the administrator!");
}

protected async Task<TResponse> GetAsync<TRequest, TResponse>(string methodName, TRequest data) where TRequest : class
{
return await Caller.GetAsync<TRequest, TResponse>(BuildAdress(methodName), data) ?? throw new UserFriendlyException("The service is abnormal, please contact the administrator!");
return await Caller.GetAsync<TRequest, TResponse>(BuildAddress(methodName), data) ?? throw new UserFriendlyException("The service is abnormal, please contact the administrator!");
}

protected async Task PutAsync<TRequest>(string methodName, TRequest data)
{
await Caller.PutAsync(BuildAdress(methodName), data);
await Caller.PutAsync(BuildAddress(methodName), data);
}

protected async Task PostAsync<TRequest>(string methodName, TRequest data)
{
await Caller.PostAsync(BuildAdress(methodName), data);
await Caller.PostAsync(BuildAddress(methodName), data);
}

protected async Task DeleteAsync<TRequest>(string methodName, TRequest? data = default)
{
await Caller.DeleteAsync(BuildAdress(methodName), data);
await Caller.DeleteAsync(BuildAddress(methodName), data);
}

protected async Task DeleteAsync(string methodName)
{
await Caller.DeleteAsync(BuildAdress(methodName), null);
await Caller.DeleteAsync(BuildAddress(methodName), null);
}

protected async Task SendAsync<TRequest>(string methodName, TRequest? data = default)
Expand All @@ -59,10 +59,10 @@ protected async Task SendAsync<TRequest>(string methodName, TRequest? data = def

protected async Task<TResponse> SendAsync<TRequest, TResponse>(string methodName, TRequest data) where TRequest : class
{
return await Caller.GetAsync<TRequest, TResponse>(BuildAdress(methodName), data) ?? throw new Exception("The service is abnormal, please contact the administrator!");
return await Caller.GetAsync<TRequest, TResponse>(BuildAddress(methodName), data) ?? throw new Exception("The service is abnormal, please contact the administrator!");
}

private string BuildAdress(string methodName)
private string BuildAddress(string methodName)
{
return Path.Combine(BaseUrl, methodName.Replace("Async", ""));
}
Expand Down

0 comments on commit e50ae53

Please sign in to comment.