Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 8e1b031

Browse files
committed
updating light version
1 parent b1d7fb5 commit 8e1b031

7 files changed

Lines changed: 41 additions & 28 deletions

File tree

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
using AutoMapper;
2+
using AutoMapper.Configuration;
23
using JPProject.Admin.Application.AutoMapper;
34
using JPProject.AspNet.Core;
45
using MediatR;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.DependencyInjection.Extensions;
9+
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
810

911
namespace JPProject.Admin.Api.Configuration
1012
{
1113
public static class AdminUiConfiguration
1214
{
13-
public static void ConfigureAdminUi(this IServiceCollection services, IConfiguration configuration)
15+
public static IServiceCollection ConfigureAdminUi(this IServiceCollection services, IConfiguration configuration)
1416
{
1517
var database = configuration["ApplicationSettings:DatabaseType"].ToUpper();
1618
var connString = configuration.GetConnectionString("SSOConnection");
17-
var builder = services.ConfigureJpAdmin<AspNetUser>();
19+
var identityServerApiBuilder = services.ConfigureJpAdmin<AspNetUser>();
20+
1821
switch (database)
1922
{
2023
case "MYSQL":
21-
builder.WithMySql(connString);
24+
identityServerApiBuilder.WithMySql<Startup>(connString);
2225
break;
2326
case "SQLSERVER":
24-
builder.WithSqlServer(connString);
27+
identityServerApiBuilder.WithSqlServer<Startup>(connString);
28+
2529
break;
2630
case "POSTGRESQL":
27-
builder.WithPostgreSql(connString);
31+
identityServerApiBuilder.WithPostgreSql<Startup>(connString);
2832
break;
2933
case "SQLITE":
30-
builder.WithSqlite(connString);
34+
identityServerApiBuilder.WithSqlite<Startup>(connString);
3135
break;
3236
}
37+
return services;
38+
}
39+
40+
public static void ConfigureDefaultSettings(this IServiceCollection services)
41+
{
42+
var configurationExpression = new MapperConfigurationExpression();
43+
AdminUiMapperConfiguration.RegisterMappings().ForEach(p => configurationExpression.AddProfile(p));
44+
var automapperConfig = new MapperConfiguration(configurationExpression);
3345

34-
var mappings = AdminUiMapperConfiguration.RegisterMappings();
35-
var automapperConfig = new MapperConfiguration(mappings);
3646
services.TryAddSingleton(automapperConfig.CreateMapper());
3747
// Adding MediatR for Domain Events and Notifications
3848
services.AddMediatR(typeof(Startup));
39-
40-
4149
}
4250
}
4351
}

src/Backend/JPProject.Admin.Api/Configuration/ConfigurePolicy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using IdentityServer4.Extensions;
2-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Extensions.DependencyInjection;
32

43
namespace JPProject.Admin.Api.Configuration
54
{
@@ -15,7 +14,7 @@ public static void AddPolicies(this IServiceCollection services)
1514
c.User.IsInRole("Administrator")));
1615

1716
options.AddPolicy("ReadOnly", policy =>
18-
policy.RequireAssertion(context => context.User.IsAuthenticated()));
17+
policy.RequireAssertion(context => context.User.Identity != null && context.User.Identity.IsAuthenticated));
1918

2019
options.AddPolicy("UserManagement", policy =>
2120
policy.RequireAuthenticatedUser());

src/Backend/JPProject.Admin.Api/Controllers/ApiResourceController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using IdentityServer4.Models;
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using IdentityServer4.Models;
24
using JPProject.Admin.Application.Interfaces;
35
using JPProject.Admin.Application.ViewModels;
46
using JPProject.Admin.Application.ViewModels.ApiResouceViewModels;
@@ -8,8 +10,6 @@
810
using Microsoft.AspNetCore.Authorization;
911
using Microsoft.AspNetCore.JsonPatch;
1012
using Microsoft.AspNetCore.Mvc;
11-
using System.Collections.Generic;
12-
using System.Threading.Tasks;
1313

1414
namespace JPProject.Admin.Api.Controllers
1515
{

src/Backend/JPProject.Admin.Api/Controllers/ClientController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using JPProject.Admin.Application.ViewModels;
66
using JPProject.Admin.Application.ViewModels.ClientsViewModels;
77
using JPProject.Domain.Core.Bus;
8+
using JPProject.Domain.Core.Interfaces;
89
using JPProject.Domain.Core.Notifications;
10+
using JPProject.Domain.Core.ViewModels;
911
using MediatR;
1012
using Microsoft.AspNetCore.Authorization;
1113
using Microsoft.AspNetCore.JsonPatch;
@@ -17,13 +19,15 @@ namespace JPProject.Admin.Api.Controllers
1719
public class ClientsController : ApiController
1820
{
1921
private readonly IClientAppService _clientAppService;
22+
private readonly ISystemUser _user;
2023

2124
public ClientsController(
2225
INotificationHandler<DomainNotification> notifications,
2326
IMediatorHandler mediator,
24-
IClientAppService clientAppService) : base(notifications, mediator)
27+
IClientAppService clientAppService, ISystemUser user) : base(notifications, mediator)
2528
{
2629
_clientAppService = clientAppService;
30+
_user = user;
2731
}
2832

2933
[HttpGet("")]
@@ -48,7 +52,9 @@ public async Task<ActionResult<Client>> Post([FromBody] SaveClientViewModel clie
4852
NotifyModelStateErrors();
4953
return ModelStateErrorResponseError();
5054
}
55+
5156
await _clientAppService.Save(client);
57+
5258
var newClient = await _clientAppService.GetClientDetails(client.ClientId);
5359

5460
return ResponsePost(nameof(GetClient), new { client = client.ClientId }, newClient);

src/Backend/JPProject.Admin.Api/Controllers/PersistedGrantsController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System.ComponentModel.DataAnnotations;
2-
using System.Threading.Tasks;
3-
using JPProject.Admin.Application.Interfaces;
1+
using JPProject.Admin.Application.Interfaces;
42
using JPProject.Admin.Application.ViewModels;
53
using JPProject.Domain.Core.Bus;
64
using JPProject.Domain.Core.Notifications;
75
using JPProject.Domain.Core.ViewModels;
86
using MediatR;
97
using Microsoft.AspNetCore.Authorization;
108
using Microsoft.AspNetCore.Mvc;
9+
using System.ComponentModel.DataAnnotations;
10+
using System.Threading.Tasks;
1111

1212
namespace JPProject.Admin.Api.Controllers
1313
{
@@ -28,6 +28,7 @@ public PersistedGrantsController(
2828
public async Task<ActionResult<ListOfPersistedGrantViewModel>> List([Range(1, 50)] int? limit = 10, [Range(1, int.MaxValue)] int? offset = 1)
2929
{
3030
var irs = await _persistedGrantAppService.GetPersistedGrants(new PagingViewModel(limit ?? 10, offset ?? 0));
31+
3132
return ResponseGet(irs);
3233
}
3334

src/Backend/JPProject.Admin.Api/JPProject.Admin.Api.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
1111
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="3.1.0" />
1212
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
13-
<PackageReference Include="JPProject.Admin.Application" Version="1.0.1-10-30-130325" />
14-
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.MySql" Version="1.0.1-10-30-130325" />
15-
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.PostgreSQL" Version="1.0.1-10-30-130325" />
16-
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.Sql" Version="1.0.1-10-30-130325" />
17-
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.Sqlite" Version="1.0.1-10-30-130325" />
18-
<PackageReference Include="JPProject.AspNet.Core" Version="1.0.1-10-30-130325" />
19-
<PackageReference Include="JPProject.Sso.Application" Version="1.0.1-10-30-130325" />
13+
<PackageReference Include="JPProject.Admin.Application" Version="1.0.1-10-31-160927" />
14+
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.MySql" Version="1.0.1-10-31-160927" />
15+
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.PostgreSQL" Version="1.0.1-10-31-160927" />
16+
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.Sql" Version="1.0.1-10-31-160927" />
17+
<PackageReference Include="JPProject.Admin.EntityFrameworkCore.Sqlite" Version="1.0.1-10-31-160927" />
18+
<PackageReference Include="JPProject.AspNet.Core" Version="1.0.1-10-31-160927" />
2019
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
2120
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
2221
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />

src/Backend/JPProject.Admin.Api/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void ConfigureServices(IServiceCollection services)
3737
services.AddBrotliCompression();
3838

3939
// Configure Admin
40-
services.ConfigureAdminUi(Configuration);
40+
services.ConfigureAdminUi(Configuration).ConfigureDefaultSettings();
4141

4242
// Cors request
4343
services.ConfigureCors();

0 commit comments

Comments
 (0)