Skip to content

Commit a8d2777

Browse files
authored
Merge pull request #35 from DeeJayTC/netDevDays
changes
2 parents 15ac038 + 44e9e89 commit a8d2777

File tree

18 files changed

+68
-50
lines changed

18 files changed

+68
-50
lines changed

sample/ApiGeneratorSampleApp/ApiGeneratorSampleApI.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<ProjectReference Include="..\..\src\TCDev.APIGenerator.OData\TCDev.APIGenerator.OData.csproj" />
2727
<ProjectReference Include="..\..\src\TCDev.APIGenerator.RabbitMQ\TCDev.APIGenerator.RabbitMQ.csproj" />
2828
<ProjectReference Include="..\..\src\TCDev.APIGenerator\TCDev.APIGenerator.csproj" />
29-
<ProjectReference Include="..\..\TCDev.APIGenerator.Events\TCDev.APIGenerator.RabbitMQ.csproj" />
3029
</ItemGroup>
3130

3231
<ItemGroup>

sample/ApiGeneratorSampleApp/Model/Person.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace DemoAPI
1313
{
1414

15-
[Api("/people", ApiMethodsToGenerate.All)]
16-
public class Person : IObjectBase<Guid>
15+
[Api("/people", ApiMethodsToGenerate.All, authorize:true)]
16+
public class Person : IObjectBase<Guid>, IBeforeCreate<Person>
1717
{
1818
public Guid Id { get; set; } = new Guid();
1919

@@ -27,6 +27,15 @@ public class Person : IObjectBase<Guid>
2727

2828
public string Image { get; set; }
2929

30+
public Task<Person> BeforeCreate(Person newItem, IApplicationDataService<GenericDbContext, AuthDbContext> data)
31+
{
32+
return Task.Run(async () =>
33+
{
34+
35+
36+
return newItem;
37+
});
38+
}
3039
}
3140

3241
}

sample/ApiGeneratorSampleApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
builder.Services.AddApiGeneratorIdentity(builder.Configuration);
1212

1313
builder.Services.AddApiGeneratorServices()
14-
.AddAssembly(Assembly.GetExecutingAssembly())
14+
.AddAssemblyWithOData(Assembly.GetExecutingAssembly())
1515
.AddDataContextSQL()
1616
.AddOData()
1717
.AddRedisCache()

sample/ApiGeneratorSampleApp/appsettings.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For more info see https://aka.ms/dotnet-template-ms-identity-platform
1313
"CallbackPath": "/signin-oidc"
1414
},
1515
"ConnectionStrings": {
16-
"ApiGeneratorDatabase": "Server=localhost;database=tcdev_dev_22123;user=sa;password=Password!23;"
16+
"ApiGeneratorDatabase": "Server=localhost;database=tcdev_dev_22123;user=sa;password=youAreWeak123!;"
1717
},
1818
"Logging": {
1919
"LogLevel": {
@@ -37,7 +37,7 @@ For more info see https://aka.ms/dotnet-template-ms-identity-platform
3737
"AutoDelete": true,
3838
"Exclusive": false
3939
},
40-
"Host": "localhost"
40+
"Host": "localhost"
4141
},
4242
"Swagger": {
4343
"EnableProduction": "false", // Enable/Disable for production builds
@@ -49,10 +49,10 @@ For more info see https://aka.ms/dotnet-template-ms-identity-platform
4949
},
5050
"Database": {
5151
"DatabaseType": "SQL",
52-
"Connection": "Server=localhost;database=123123123;user=sa;password=Password!23;"
52+
"Connection": "Server=localhost;database=tcdev_dev_22123;user=sa;password=youAreWeak123!;"
5353
},
5454
"Redis": {
55-
"Connection": "",
55+
"Connection": ""
5656
},
5757
"Odata": {
5858
"Enabled": true,
@@ -62,14 +62,14 @@ For more info see https://aka.ms/dotnet-template-ms-identity-platform
6262
},
6363
"Identity": {
6464
"EnableIdentity": true,
65-
"Audience": "...",
66-
"Authority": "...",
67-
"Issuser": "....",
68-
"ValidateAuthority": true,
69-
"ValidateIssuer": true,
70-
"MetaDataUri": "",
71-
"ValidateLifetime": true,
72-
"ValidateIssuerSigningkey": true
65+
"Audience": "https://netdddemo.tcdev.de",
66+
"Authority": "https://dev-dy2rk4vd.us.auth0.com",
67+
"Issuer": "https://dev-dy2rk4vd.us.auth0.com",
68+
"ValidateAuthority": false,
69+
"ValidateIssuer": false,
70+
"MetaDataUri": "https://dev-dy2rk4vd.us.auth0.com/.well-known/openid-configuration",
71+
"ValidateLifetime": false,
72+
"ValidateIssuerSigningkey": false
7373
}
7474
}
7575
}

src - Verknüpfung.lnk

1.2 KB
Binary file not shown.

src/TCDev.APIGenerator.Data.SQL/TCDev.APIGenerator.Data.SQL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<PackageId>TCDev.APIGenerator.Data.SQL</PackageId>
6-
<Version>0.7.0-RC1</Version>
6+
<Version>0.7.1-RC1</Version>
77
<Authors>Tim Cadenbach</Authors>
88
<Company>TCDev</Company>
99
<Description>Adds necessary functionality to use MS SQL Server and Azure SQL Instances with the API Generator. </Description>

src/TCDev.APIGenerator.Data/Data/GenericDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace TCDev.APIGenerator.Data
2323
{
24+
25+
2426
public class GenericDbContext : DbContext
2527
{
2628
private readonly AssemblyService assemblyService;

src/TCDev.APIGenerator.Data/Data/GenericRepository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ record = await baseEntity.BeforeCreate(record, data);
6767
.CurrentValue = DateTime.UtcNow;
6868

6969

70-
7170
if (typeof(TEntity).IsAssignableTo(typeof(IAfterCreate<TEntity>)))
7271
{
73-
var baseEntity = record as IBeforeCreate<TEntity>;
74-
await baseEntity.BeforeCreate(record, data);
72+
var baseEntity = record as IAfterCreate<TEntity>;
73+
await baseEntity.AfterCreate(record, data);
7574
}
7675
}
7776

src/TCDev.APIGenerator.Data/TCDev.APIGenerator.Data.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.7.0-RC1</Version>
7+
<Version>0.7.1-RC1</Version>
88
<PackageProjectUrl>https://www.rasepi.com</PackageProjectUrl>
99
<PackageIcon>logo_small.png</PackageIcon>
1010
<PackageReadmeFile>README.md</PackageReadmeFile>

src/TCDev.APIGenerator.OData/Controllers/GenericODataController.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,33 @@ public class GenericODataController<T, TEntityId> : ODataController
3838
private ApiGeneratorConfig apiGenConfig;
3939

4040

41+
//public GenericODataController(
42+
// IAuthorizationService authorizationService,
43+
// IGenericRespository<T, TEntityId> repository,
44+
// ApplicationDataService<GenericDbContext, AuthDbContext> dataService)
45+
//{
46+
// this.repository = repository;
47+
// this.authorizationService = authorizationService;
48+
// this.appDataService = dataService;
49+
50+
// ConfigureController();
51+
//}
52+
53+
4154
public GenericODataController(
4255
IAuthorizationService authorizationService,
4356
IGenericRespository<T, TEntityId> repository,
4457
ApplicationDataService<GenericDbContext, AuthDbContext> dataService,
58+
ODataScopeService<T, TEntityId> scopeLookup,
4559
ApiGeneratorConfig apiGenConfig)
4660
{
4761
this.repository = repository;
4862
this.authorizationService = authorizationService;
4963
this.appDataService = dataService;
5064
this.apiGenConfig = apiGenConfig;
5165

66+
this.scopeLookup = scopeLookup;
67+
5268
ConfigureController();
5369
}
5470
private void ConfigureController()
@@ -70,6 +86,13 @@ private void ConfigureController()
7086
{
7187
this.cacheOptions = cacheAttrib;
7288
}
89+
90+
// Get RabbitMQ Settings
91+
var eventAttr = Attribute.GetCustomAttributes(typeof(EventAttribute));
92+
if (attrs.FirstOrDefault(p => p.GetType() == typeof(EventAttribute)) is EventAttribute eventAttrib)
93+
{
94+
this.eventOptions = eventAttrib;
95+
}
7396
}
7497

7598
/// <summary>
@@ -80,7 +103,7 @@ private void ConfigureController()
80103
[ProducesErrorResponseType(typeof(BadRequestResult))]
81104
[HttpGet]
82105
[EnableQuery(
83-
AllowedQueryOptions = AllowedQueryOptions.All,
106+
AllowedQueryOptions = AllowedQueryOptions.Search | AllowedQueryOptions.Filter,
84107
AllowedFunctions = AllowedFunctions.All,
85108
PageSize = 20)
86109
]
@@ -130,7 +153,6 @@ public async Task<IActionResult> Find(ODataQueryOptions<T> ODataOpts, TEntityId
130153
return Ok(record);
131154
}
132155

133-
134156
[HttpPost]
135157
public async Task<IActionResult> Create([FromBody] T record)
136158
{
@@ -144,7 +166,7 @@ public async Task<IActionResult> Create([FromBody] T record)
144166
await this.repository.SaveAsync();
145167

146168

147-
if (eventOptions.events.HasFlag(AMQPEvents.Created)) CheckAndSendEvent(record, typeof(T).Name + ".CREATED", null);
169+
if (eventOptions != null && eventOptions.events.HasFlag(AMQPEvents.Created)) CheckAndSendEvent(record, typeof(T).Name + ".CREATED", null);
148170

149171
// respond with the newly created record
150172
return CreatedAtAction("Find", new
@@ -201,7 +223,7 @@ record = await baseEntity.BeforeUpdate(record, existingRecord, this.appDataServi
201223
}
202224

203225

204-
if (eventOptions.events.HasFlag(AMQPEvents.Created)) CheckAndSendEvent(record, typeof(T).Name + ".UPDATED", null);
226+
if (eventOptions != null && eventOptions.events.HasFlag(AMQPEvents.Updated)) CheckAndSendEvent(record, typeof(T).Name + ".UPDATED", existingRecord);
205227

206228

207229
return Ok(record);
@@ -229,7 +251,7 @@ public async Task<IActionResult> Delete(TEntityId id)
229251

230252
this.repository.Delete(id, this.appDataService);
231253

232-
if (eventOptions.events.HasFlag(AMQPEvents.Created)) CheckAndSendEvent(existingRecord, typeof(T).Name + ".DELETED", null);
254+
if (eventOptions != null && eventOptions.events.HasFlag(AMQPEvents.Created)) CheckAndSendEvent(existingRecord, typeof(T).Name + ".DELETED", null);
233255
if (await this.repository.SaveAsync() == 0)
234256
{
235257
return BadRequest();
@@ -243,20 +265,6 @@ public async Task<IActionResult> Delete(TEntityId id)
243265
}
244266
}
245267

246-
public GenericODataController(
247-
IAuthorizationService authorizationService,
248-
IGenericRespository<T, TEntityId> repository,
249-
ODataScopeService<T, TEntityId> scopeLookup,
250-
ApplicationDataService<GenericDbContext, AuthDbContext> dataService)
251-
{
252-
this.repository = repository;
253-
this.authorizationService = authorizationService;
254-
this.scopeLookup = scopeLookup;
255-
this.appDataService = dataService;
256-
257-
ConfigureController();
258-
}
259-
260268

261269

262270
private void CheckAndSendEvent(T record, string Name, T oldRecord)

0 commit comments

Comments
 (0)