Skip to content

Commit

Permalink
Fix complex BaseUrl not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Aug 31, 2023
1 parent 2e0f6bf commit f973868
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using BitzArt.Pagination;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Web;

Expand All @@ -22,8 +20,8 @@ internal virtual CommunicatorRestEntityOptions<TEntity> EntityOptions
}

internal string GetFullPath(string path)
=> HttpClient.BaseAddress is not null ?
Path.Combine(HttpClient.BaseAddress.ToString(), path) :
=> ServiceOptions.BaseUrl is not null ?
Path.Combine(ServiceOptions.BaseUrl.ToString(), path) :
path;

internal async Task<TResult> HandleRequestAsync<TResult>(HttpRequestMessage message) where TResult : class
Expand Down Expand Up @@ -54,7 +52,7 @@ public CommunicatorRestEntityContext(HttpClient httpClient, CommunicatorRestServ
HttpClient = httpClient;
ServiceOptions = serviceOptions;
_logger = logger;
EntityOptions = entityOptions;
_entityOptions = entityOptions;
}

public virtual async Task<IEnumerable<TEntity>> GetAllAsync()
Expand All @@ -64,7 +62,7 @@ public virtual async Task<IEnumerable<TEntity>> GetAllAsync()

_logger.LogInformation("GetAll {type}: {path}", typeof(TEntity).Name, GetFullPath(path));

var message = new HttpRequestMessage(HttpMethod.Get, path);
var message = new HttpRequestMessage(HttpMethod.Get, GetFullPath(path));
var result = await HandleRequestAsync<IEnumerable<TEntity>>(message);

return result;
Expand All @@ -89,7 +87,7 @@ public virtual async Task<PageResult<TEntity>> GetPageAsync(PageRequest pageRequ

_logger.LogInformation("GetPage {type}: {path}", typeof(TEntity).Name, GetFullPath(path));

var message = new HttpRequestMessage(HttpMethod.Get, path);
var message = new HttpRequestMessage(HttpMethod.Get, GetFullPath(path));
var result = await HandleRequestAsync<PageResult<TEntity>>(message);

return result;
Expand All @@ -102,7 +100,7 @@ public virtual async Task<TEntity> GetAsync(object id)
var idEndpoint = EntityOptions.GetIdEndpointAction(id);
_logger.LogInformation("Get {type}[{id}]: {path}", typeof(TEntity).Name, id.ToString(), GetFullPath(idEndpoint));

var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint);
var message = new HttpRequestMessage(HttpMethod.Get, GetFullPath(idEndpoint));
var result = await HandleRequestAsync<TEntity>(message);

return result;
Expand Down Expand Up @@ -138,7 +136,7 @@ public async Task<TEntity> GetAsync(TKey id)

_logger.LogInformation("Get {type}[{id}]: {path}", typeof(TEntity).Name, id!.ToString(), GetFullPath(idEndpoint));

var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint);
var message = new HttpRequestMessage(HttpMethod.Get, GetFullPath(idEndpoint));
var result = await HandleRequestAsync<TEntity>(message);

return result;
Expand Down

0 comments on commit f973868

Please sign in to comment.