Skip to content

Commit

Permalink
modify api rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytang67 committed Apr 4, 2021
1 parent 0b08b69 commit f012eb8
Show file tree
Hide file tree
Showing 14 changed files with 849 additions and 622 deletions.
1,287 changes: 715 additions & 572 deletions angular/src/api/appService.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class FormsComponent implements OnInit {
form: {
title: "",
description: "",
theme: FormTheme.red
theme: 0
}
},
nzFooter: [
Expand Down
2 changes: 2 additions & 0 deletions backEnd/modules/TT.Abp.Core/Application/AuditLogAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
Expand All @@ -22,6 +23,7 @@ IAuditLogRepository auditlogRepository
_auditlogRepository = auditlogRepository;
}

[HttpGet]
public async Task<PagedResultDto<AuditLogListDto>> GetAuditLogs(GetAuditLogsInput input)
{
var query = _auditlogRepository.AsQueryable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ await CreateClientAsync(
{
var webClientRootUrl = configurationSection["SoMall_App:RootUrl"]?.TrimEnd('/');

await CreateClientAsync(
var client = await CreateClientAsync(
name: consoleAndAngularClientId,
scopes: commonScopes,
grantTypes: new[] {"password", "client_credentials", "implicit", "UserWithTenant"},
Expand All @@ -181,6 +181,7 @@ await CreateClientAsync(
postLogoutRedirectUri: webClientRootUrl,
corsOrigins: new[] {webClientRootUrl.RemovePostFix("/")}
);
client.AllowAccessTokensViaBrowser = true;
}

// Swagger Client
Expand Down
2 changes: 0 additions & 2 deletions backEnd/src/TT.SoMall.HttpApi.Host/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.Elasticsearch;
using Serilog.Exceptions;
using Winton.Extensions.Configuration.Consul;
using Elastic.CommonSchema.Serilog;

namespace TT.SoMall
Expand Down
18 changes: 10 additions & 8 deletions backEnd/src/TT.SoMall.HttpApi.Host/SoMallHttpApiHostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using TT.SoMall.EntityFrameworkCore;
using TT.SoMall.MultiTenancy;
using StackExchange.Redis;
using Microsoft.OpenApi.Models;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Conventions;
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Serilog;
Expand Down Expand Up @@ -48,7 +50,12 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();

Configure<AbpConventionalControllerOptions>(options =>
{
options.UseV3UrlStyle = true;
});
context.Services.Replace(ServiceDescriptor.Transient<IConventionalRouteBuilder, TtConventionalRouteBuilder>());

ConfigureConventionalControllers();
ConfigureAuthentication(context, configuration);
ConfigureLocalization();
Expand Down Expand Up @@ -90,10 +97,7 @@ private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)

private void ConfigureConventionalControllers()
{
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(SoMallApplicationModule).Assembly);
});
Configure<AbpAspNetCoreMvcOptions>(options => { options.ConventionalControllers.Create(typeof(SoMallApplicationModule).Assembly); });
}

private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
Expand Down Expand Up @@ -173,8 +177,6 @@ private void ConfigureCors(ServiceConfigurationContext context, IConfiguration c

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{


var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();

Expand Down Expand Up @@ -227,7 +229,7 @@ public static ApiDescription Resolve(IEnumerable<ApiDescription> descriptions, s
{
var parameters = descriptions
.SelectMany(desc => desc.ParameterDescriptions)
.GroupBy(x => x, (x, xs) => new { IsOptional = xs.Count() == 1, Parameter = x },
.GroupBy(x => x, (x, xs) => new {IsOptional = xs.Count() == 1, Parameter = x},
ApiParameterDescriptionEqualityComparer.Instance)
.ToList();
var description = descriptions.First();
Expand Down
11 changes: 9 additions & 2 deletions backEnd/src/TT.SoMall.HttpApi/SoMallHttpApiModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ public class SoMallHttpApiModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Replace(ServiceDescriptor.Transient<IAbpServiceConvention, TtServiceConvention>());
ConfigureLocalization();
// Configure<AbpConventionalControllerOptions>(options =>
// {
// options.UseV3UrlStyle = true;
// });

// context.Services.Replace(ServiceDescriptor.Transient<IAbpServiceConvention, TtServiceConvention>());
// context.Services.Replace(ServiceDescriptor.Transient<IConventionalRouteBuilder, TtConventionalRouteBuilder>());
// ConfigureLocalization();
}
private void ConfigureLocalization()
{

Configure<AbpLocalizationOptions>(options =>
{
options.Resources
Expand Down
93 changes: 92 additions & 1 deletion backEnd/src/TT.SoMall.HttpApi/TtServiceConvention.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,99 @@
using System;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Conventions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http;
using Volo.Abp.Reflection;

namespace TT.SoMall
{
[Dependency(ReplaceServices = true)]
//[Dependency(ReplaceServices = true)]
public class TtConventionalRouteBuilder : ConventionalRouteBuilder
{
public TtConventionalRouteBuilder(IOptions<AbpConventionalControllerOptions> options) : base(options)
{
}

public override string Build(string rootPath, string controllerName, ActionModel action, string httpMethod, ConventionalControllerSetting configuration)
{
var controllerNameInUrl = NormalizeUrlControllerName(rootPath, controllerName, action, httpMethod, configuration);

var url = $"api/{rootPath}/{NormalizeControllerNameCase(controllerNameInUrl, configuration)}";

//Add {id} path if needed
// var idParameterModel = action.Parameters.FirstOrDefault(p => p.ParameterName == "id");
// if (idParameterModel != null)
// {
// if (TypeHelper.IsPrimitiveExtended(idParameterModel.ParameterType, includeEnums: true))
// {
// url += "/{id}";
// }
// else
// {
// var properties = idParameterModel
// .ParameterType
// .GetProperties(BindingFlags.Instance | BindingFlags.Public);
//
// foreach (var property in properties)
// {
// url += "/{" + NormalizeIdPropertyNameCase(property, configuration) + "}";
// }
// }
// }

//Add action name if needed
var actionNameInUrl = NormalizeUrlActionName(rootPath, controllerName, action, httpMethod, configuration);
if (!actionNameInUrl.IsNullOrEmpty())
{
url += $"/{NormalizeActionNameCase(actionNameInUrl, configuration)}";

//Add secondary Id
var secondaryIds = action.Parameters
.Where(p => p.ParameterName.EndsWith("Id", StringComparison.Ordinal)).ToList();
if (secondaryIds.Count == 1)
{
url += $"/{{{NormalizeSecondaryIdNameCase(secondaryIds[0], configuration)}}}";
}
}

return url;
}


protected override string NormalizeUrlActionName(string rootPath, string controllerName, ActionModel action, string httpMethod, ConventionalControllerSetting configuration)
{
// return base.NormalizeUrlActionName(rootPath, controllerName, action, httpMethod, configuration);
var actionNameInUrl =
//HttpMethodHelper
//.RemoveHttpMethodPrefix(action.ActionName, httpMethod)
action.ActionName.RemovePostFix("Async");

if (configuration?.UrlActionNameNormalizer == null)
{
return actionNameInUrl;
}

return configuration.UrlActionNameNormalizer(
new UrlActionNameNormalizerContext(
rootPath,
controllerName,
action,
actionNameInUrl,
httpMethod
)
);
}
}





//[Dependency(ReplaceServices = true)]
public class TtServiceConvention : AbpServiceConvention
{
public TtServiceConvention(
Expand All @@ -18,6 +103,12 @@ public TtServiceConvention(
{
}

protected override void ConfigureSelector(string rootPath, string controllerName, ActionModel action, ConventionalControllerSetting configuration)
{
base.ConfigureSelector(rootPath, controllerName, action, configuration);
}


#region Obsolete

// protected override string CalculateRouteTemplate(string rootPath, string controllerName, ActionModel action,
Expand Down
13 changes: 10 additions & 3 deletions backEnd/src/TT.SoMall.IdentityServer/SoMallIdentityServerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
using Volo.Abp;
using Volo.Abp.Account;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Mvc.UI;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
Expand Down Expand Up @@ -73,6 +71,14 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
});

Configure<AbpBundlingOptions>(options =>
{
options.StyleBundles.Configure(
BasicThemeBundles.Styles.Global,
bundle => { bundle.AddFiles("/global-styles.css"); }
);
});

Configure<AbpAuditingOptions>(options =>
{
Expand All @@ -84,7 +90,8 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<SoMallDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}TT.SoMall.Domain.Shared"));
options.FileSets.ReplaceEmbeddedByPhysical<SoMallDomainSharedModule>(
Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}TT.SoMall.Domain.Shared"));
options.FileSets.ReplaceEmbeddedByPhysical<SoMallDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}TT.SoMall.Domain"));
});
}
Expand Down
26 changes: 1 addition & 25 deletions backEnd/src/TT.SoMall.IdentityServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Configuration;
using IdentityServer4.Models;
using IdentityServer4.Validation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using TT.HttpClient.Weixin;

namespace TT.SoMall
{
Expand All @@ -15,23 +8,6 @@ public class Startup
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<SoMallIdentityServerModule>();

#region custom
// var config = services.GetConfiguration();
//
// services.PostConfigure<IdentityServerOptions>(options =>
// {
// // options.PublicOrigin = config["AuthServer:Authority"];
// options.IssuerUri = config["AuthServer:Authority"];
// });
//
// services.Configure<ForwardedHeadersOptions>(options =>
// {
// options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
// options.KnownNetworks.Clear();
// options.KnownProxies.Clear();
// });
#endregion
}

public void Configure(IApplicationBuilder app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@

<ItemGroup>
<PackageReference Include="Volo.Abp.Autofac" Version="4.2.2" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="4.2.2" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="4.2.2" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="4.2.2" />
<PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="4.2.2" />
<PackageReference Include="Volo.Abp.Account.Application" Version="4.2.2" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="4.2.2" />
<PackageReference Include="Volo.Abp.TenantManagement.Web" Version="4.2.2" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="5.0.1" />
<ProjectReference Include="..\TT.SoMall.EntityFrameworkCore.DbMigrations\TT.SoMall.EntityFrameworkCore.DbMigrations.csproj" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion backEnd/src/TT.SoMall.IdentityServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"RabbitMQ": "localhost"
},
"Redis": {
"ConnectionString": "127.0.0.1"
"ConnectionString": "127.0.0.1",
"Configuration": "127.0.0.1"
},
"AuthServer": {
"Authority": "http://127.0.0.1:44380"
Expand Down
2 changes: 1 addition & 1 deletion backEnd/src/TT.SoMall.IdentityServer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "my-app-identityserver",
"private": true,
"dependencies": {
"@abp/aspnetcore.mvc.ui.theme.basic": "^3.2.0-rc.2"
"@abp/aspnetcore.mvc.ui.theme.basic": "^4.2.2"
}
}
6 changes: 3 additions & 3 deletions uni-mall/src/pages/index/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import wechat from "../../utils/wechat";
@Component
export default class LoginPage extends BaseView {
onShow() {
// if H5
// #ifdef H5
console.log("h5");
if (wechat.isWechat()) {
console.log("wechat.isWechat");
Expand All @@ -95,13 +95,13 @@ export default class LoginPage extends BaseView {
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${host}&response_type=code&scope=snsapi_userinfo&state=${_state}#wechat_redirect`;
location.href = url;
} else {
api.oAuth({ code }).then(res => {
api.oAuth({ code }).then((res) => {
console.log(res);
});
}
}
// endif
// #endif
}
theme = "black";
Expand Down

0 comments on commit f012eb8

Please sign in to comment.