refactor(#I12XQJ): api 支持 System.Text.Json

#Issue
link #I12XQJ
This commit is contained in:
Argo Zhang 2019-10-03 15:52:20 +08:00
parent 0b69f5d51d
commit f883028783
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
10 changed files with 24 additions and 31 deletions

View File

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta5" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta6" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="3.0.0" />
<PackageReference Include="Longbow.Tasks" Version="2.2.24" />

View File

@ -1,4 +1,4 @@
using Bootstrap.Admin.Query;
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;

View File

@ -29,16 +29,15 @@ namespace Bootstrap.Admin.Controllers.Api
/// <summary>
/// JWT 登陆认证接口
/// </summary>
/// <param name="value"></param>
/// <param name="user"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpPost]
public string Post([FromBody]JObject value)
public string Post([FromBody]User user)
{
string token = null;
dynamic user = value;
string userName = user.userName;
string password = user.password;
var token = string.Empty;
string userName = user.UserName;
string password = user.Password;
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
{
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);

View File

@ -106,9 +106,8 @@ namespace Bootstrap.Admin
app.UseStaticFiles();
app.UseAutoGenerateDatabase();
app.UseRouting();
app.UseAuthentication();
app.UseBootstrapAdminAuthentication(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
app.UseAuthorization();
app.UseBootstrapAdminAuthorization(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
app.UseBootstrapHealthChecks();
app.UseOnlineUsers(TraceHelper.Filter, TraceHelper.Save);

View File

@ -4,13 +4,9 @@
<TargetFrameworks>netcoreapp3.0;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Longbow" Version="3.0.0-beta2" />
<PackageReference Include="Longbow" Version="3.0.0-beta3" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.3.8" />
<PackageReference Include="Longbow.GiteeAuth" Version="2.2.0" />

View File

@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Longbow" Version="3.0.0-beta3" />
<PackageReference Include="Longbow.Cache" Version="2.2.15" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.3.8" />

View File

@ -6,10 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta4" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta6" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -90,9 +90,8 @@ namespace Bootstrap.Client
app.UseCookiePolicy();
app.UseRouting();
app.UseAuthentication();
app.UseBootstrapAdminAuthentication(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
app.UseAuthorization();
app.UseBootstrapAdminAuthorization(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
app.UseCacheManager();
app.UseOnlineUsers(callback: TraceHelper.Save);
app.UseEndpoints(endpoints =>

View File

@ -8,8 +8,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text.Json;
using UnitTest;
using Xunit;
@ -85,8 +85,7 @@ namespace Bootstrap.Admin.Api
services.AddCacheManager();
services.AddConfigurationManager();
services.AddDbAdapter();
var builder = services.AddHealthChecks();
builder.AddCheck<DBHealthCheck>("db");
services.AddHealthChecks().AddCheck<DBHealthCheck>("db");
services.AddControllers();
}
@ -101,10 +100,10 @@ namespace Bootstrap.Admin.Api
});
app.UseEndpoints(builder => builder.MapHealthChecks("/Healths", new HealthCheckOptions()
{
ResponseWriter = (context, report) =>
ResponseWriter = async (context, report) =>
{
context.Response.ContentType = "application/json";
return context.Response.WriteAsync(JsonConvert.SerializeObject(new { report.Entries.Keys, Report = report }));
await context.Response.WriteAsync(JsonSerializer.Serialize(new { report.Status, report.TotalDuration }));
},
ResultStatusCodes =
{

View File

@ -1,6 +1,7 @@
using Newtonsoft.Json;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
namespace Bootstrap.Admin
@ -18,7 +19,7 @@ namespace Bootstrap.Admin
{
var resp = await client.GetAsync(requestUri);
var json = await resp.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(json);
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions().Configure());
}
/// <summary>
@ -34,7 +35,7 @@ namespace Bootstrap.Admin
{
var resp = await client.PostAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TRet>(json);
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
}
/// <summary>
@ -59,12 +60,12 @@ namespace Bootstrap.Admin
public static async Task<TRet> DeleteAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
{
var req = new HttpRequestMessage(HttpMethod.Delete, requestUri);
req.Content = new StringContent(JsonConvert.SerializeObject(t));
req.Content = new StringContent(JsonSerializer.Serialize(t));
req.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var resp = await client.SendAsync(req);
var json = await resp.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TRet>(json);
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
}
/// <summary>
@ -90,7 +91,7 @@ namespace Bootstrap.Admin
{
var resp = await client.PutAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TRet>(json);
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
}
/// <summary>