44using Microsoft . AspNetCore . Http ;
55using System . ComponentModel . DataAnnotations ;
66using System . Reflection ;
7+ using Microsoft . Extensions . Logging ;
78
89namespace Fritz . InstantAPIs ;
910
@@ -12,12 +13,14 @@ internal class MapApiExtensions
1213
1314 // TODO: Authentication / Authorization
1415 private static Dictionary < Type , PropertyInfo > _IdLookup = new ( ) ;
16+ private static ILogger Logger ;
1517
16- internal static void Initialize < D , C > ( )
18+ internal static void Initialize < D , C > ( ILogger logger )
1719 where D : DbContext
1820 where C : class
1921 {
2022
23+ Logger = logger ;
2124 var theType = typeof ( C ) ;
2225 var idProp = theType . GetProperty ( "id" , BindingFlags . IgnoreCase | BindingFlags . Public | BindingFlags . Instance ) ?? theType . GetProperties ( ) . FirstOrDefault ( p => p . CustomAttributes . Any ( a => a . AttributeType == typeof ( KeyAttribute ) ) ) ;
2326
@@ -33,6 +36,7 @@ internal static void MapInstantGetAll<D, C>(IEndpointRouteBuilder app, string ur
3336 where D : DbContext where C : class
3437 {
3538
39+ Logger . LogInformation ( $ "Created API: HTTP GET\t { url } ") ;
3640 app . MapGet ( url , ( [ FromServices ] D db ) =>
3741 {
3842 return Results . Ok ( db . Set < C > ( ) ) ;
@@ -51,6 +55,8 @@ internal static void MapGetById<D,C>(IEndpointRouteBuilder app, string url)
5155
5256 if ( idProp == null ) return ;
5357
58+ Logger . LogInformation ( $ "Created API: HTTP GET\t { url } /{{id}}") ;
59+
5460 app . MapGet ( $ "{ url } /{{id}}", async ( [ FromServices ] D db , [ FromRoute ] string id ) =>
5561 {
5662
@@ -76,6 +82,7 @@ internal static void MapInstantPost<D, C>(IEndpointRouteBuilder app, string url)
7682 where D : DbContext where C : class
7783 {
7884
85+ Logger . LogInformation ( $ "Created API: HTTP POST\t { url } ") ;
7986
8087 app . MapPost ( url , async ( [ FromServices ] D db , [ FromBody ] C newObj ) =>
8188 {
@@ -92,6 +99,7 @@ internal static void MapInstantPut<D, C>(IEndpointRouteBuilder app, string url)
9299 where D : DbContext where C : class
93100 {
94101
102+ Logger . LogInformation ( $ "Created API: HTTP PUT\t { url } ") ;
95103
96104 app . MapPut ( $ "{ url } /{{id}}", async ( [ FromServices ] D db , [ FromRoute ] string id , [ FromBody ] C newObj ) =>
97105 {
@@ -113,6 +121,7 @@ internal static void MapDeleteById<D, C>(IEndpointRouteBuilder app, string url)
113121 var idProp = _IdLookup [ theType ] ;
114122
115123 if ( idProp == null ) return ;
124+ Logger . LogInformation ( $ "Created API: HTTP DELETE\t { url } ") ;
116125
117126 app . MapDelete ( $ "{ url } /{{id}}", async ( [ FromServices ] D db , [ FromRoute ] string id ) =>
118127 {
0 commit comments