mirror of https://github.com/abpframework/abp.git
15 changed files with 95 additions and 132 deletions
@ -0,0 +1,42 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.Http.Client |
|||
{ |
|||
public class RemoteServiceOptions |
|||
{ |
|||
public RemoteServiceDictionary RemoteServices { get; set; } |
|||
|
|||
public RemoteServiceOptions() |
|||
{ |
|||
RemoteServices = new RemoteServiceDictionary(); |
|||
} |
|||
} |
|||
|
|||
public class RemoteServiceDictionary : Dictionary<string, RemoteServiceConfiguration> |
|||
{ |
|||
public const string DefaultName = "Default"; |
|||
|
|||
public RemoteServiceConfiguration Default |
|||
{ |
|||
get { return this.GetOrDefault(DefaultName); } |
|||
set { this[DefaultName] = value; } |
|||
} |
|||
} |
|||
|
|||
public class RemoteServiceConfiguration |
|||
{ |
|||
public string BaseUrl { get; set; } |
|||
|
|||
public RemoteServiceConfiguration() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RemoteServiceConfiguration(string baseUrl) |
|||
{ |
|||
BaseUrl = baseUrl; |
|||
} |
|||
} |
|||
} |
|||
@ -1,14 +1,17 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Http.Client; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
[DependsOn(typeof(AbpIdentityApplicationContractsModule))] |
|||
[DependsOn(typeof(AbpIdentityApplicationContractsModule), typeof(AbpHttpClientModule))] |
|||
public class AbpIdentityHttpApiClientModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpIdentityHttpApiClientModule>(); |
|||
|
|||
services.AddHttpClientProxy<AbpIdentityApplicationContractsModule>("AbpIdentity"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class AbpIdentityHttpApiClientOptions |
|||
{ |
|||
public string ApiUrlBase { get; set; } |
|||
} |
|||
} |
|||
@ -1,62 +0,0 @@ |
|||
using System; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Options; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Serialization; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class HttpApiUserAppService : IUserAppService |
|||
{ |
|||
private readonly AbpIdentityHttpApiClientOptions _options; |
|||
|
|||
public HttpApiUserAppService(IOptionsSnapshot<AbpIdentityHttpApiClientOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
|
|||
public async Task<ListResultDto<IdentityUserDto>> Get() |
|||
{ |
|||
using (var client = new HttpClient()) |
|||
{ |
|||
var response = await client.GetAsync(_options.ApiUrlBase + "api/identity/users"); |
|||
if (!response.IsSuccessStatusCode) |
|||
{ |
|||
throw new AbpException("Remote service returns error!"); |
|||
} |
|||
|
|||
var content = await response.Content.ReadAsStringAsync(); |
|||
|
|||
return JsonConvert.DeserializeObject<ListResultDto<IdentityUserDto>>( |
|||
content, |
|||
new JsonSerializerSettings |
|||
{ |
|||
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|||
}); |
|||
} |
|||
} |
|||
|
|||
public async Task<IdentityUserDto> Get(Guid id) |
|||
{ |
|||
using (var client = new HttpClient()) |
|||
{ |
|||
var response = await client.GetAsync(_options.ApiUrlBase + "api/identity/users/" + id); |
|||
if (!response.IsSuccessStatusCode) |
|||
{ |
|||
throw new AbpException("Remote service returns error!"); |
|||
} |
|||
|
|||
var content = await response.Content.ReadAsStringAsync(); |
|||
|
|||
return JsonConvert.DeserializeObject<IdentityUserDto>( |
|||
content, |
|||
new JsonSerializerSettings |
|||
{ |
|||
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
[Route("api/identity/users")] |
|||
public class IdentityUsersController : AbpController |
|||
{ |
|||
private readonly IUserAppService _userAppService; |
|||
|
|||
public IdentityUsersController(IUserAppService userAppService) |
|||
{ |
|||
_userAppService = userAppService; |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("")] |
|||
public Task<ListResultDto<IdentityUserDto>> Get() |
|||
{ |
|||
return _userAppService.Get(); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("{id}")] |
|||
public Task<IdentityUserDto> Get(Guid id) |
|||
{ |
|||
return _userAppService.Get(id); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue