From 5ef932f0c5b3c9fb775f7673d0e4d3e24d0a15a7 Mon Sep 17 00:00:00 2001 From: Michael Justin Date: Sun, 3 Jul 2016 18:35:55 +0200 Subject: [PATCH] * use IRoute where possible * fixes #11 --- src/main/djRestfulComponent.pas | 28 ++++++++++++++-------------- src/main/rsConfiguration.pas | 8 ++++---- src/main/rsRouteMappings.pas | 15 ++++++++------- src/test/Unittests.dproj | 4 ++-- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/djRestfulComponent.pas b/src/main/djRestfulComponent.pas index 86b9ea3..7fe1a91 100644 --- a/src/main/djRestfulComponent.pas +++ b/src/main/djRestfulComponent.pas @@ -57,13 +57,13 @@ TdjRestfulComponent = class(TdjWebComponent) procedure Trace(const S: string); - procedure DELETE(Route: TrsRoute); overload; - procedure GET(Route: TrsRoute); overload; - procedure HEAD(Route: TrsRoute); overload; - procedure PATCH(Route: TrsRoute); overload; - procedure POST(Route: TrsRoute); overload; - procedure PUT(Route: TrsRoute); overload; - procedure OPTIONS(Route: TrsRoute); overload; + procedure DELETE(const Route: IRoute); overload; + procedure GET(const Route: IRoute); overload; + procedure HEAD(const Route: IRoute); overload; + procedure PATCH(const Route: IRoute); overload; + procedure POST(const Route: IRoute); overload; + procedure PUT(const Route: IRoute); overload; + procedure OPTIONS(const Route: IRoute); overload; protected procedure SendError(AResponseInfo: TIdHTTPResponseInfo; Error: @@ -333,7 +333,7 @@ procedure TdjRestfulComponent.&Path(Path: string); RestConfig.SetPath(Path); end; -procedure TdjRestfulComponent.GET(Route: TrsRoute); +procedure TdjRestfulComponent.GET(const Route: IRoute); begin RestConfig.AddMapping('GET', Route); end; @@ -344,7 +344,7 @@ procedure TdjRestfulComponent.GET(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.POST(Route: TrsRoute); +procedure TdjRestfulComponent.POST(const Route: IRoute); begin RestConfig.AddMapping('POST', Route); end; @@ -355,7 +355,7 @@ procedure TdjRestfulComponent.POST(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.DELETE(Route: TrsRoute); +procedure TdjRestfulComponent.DELETE(const Route: IRoute); begin RestConfig.AddMapping('DELETE', Route); end; @@ -366,7 +366,7 @@ procedure TdjRestfulComponent.DELETE(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.PUT(Route: TrsRoute); +procedure TdjRestfulComponent.PUT(const Route: IRoute); begin RestConfig.AddMapping('PUT', Route); end; @@ -377,7 +377,7 @@ procedure TdjRestfulComponent.PUT(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.HEAD(Route: TrsRoute); +procedure TdjRestfulComponent.HEAD(const Route: IRoute); begin RestConfig.AddMapping('HEAD', Route); end; @@ -388,7 +388,7 @@ procedure TdjRestfulComponent.HEAD(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.PATCH(Route: TrsRoute); +procedure TdjRestfulComponent.PATCH(const Route: IRoute); begin RestConfig.AddMapping('PATCH', Route); end; @@ -399,7 +399,7 @@ procedure TdjRestfulComponent.PATCH(Handler: TRouteProc); RestConfig.ClearNextPath; end; -procedure TdjRestfulComponent.OPTIONS(Route: TrsRoute); +procedure TdjRestfulComponent.OPTIONS(const Route: IRoute); begin RestConfig.AddMapping('OPTIONS', Route); end; diff --git a/src/main/rsConfiguration.pas b/src/main/rsConfiguration.pas index 74d87e3..27c558c 100644 --- a/src/main/rsConfiguration.pas +++ b/src/main/rsConfiguration.pas @@ -74,9 +74,9 @@ TrsConfiguration = class(TInterfacedObject, IContextConfiguration) destructor Destroy; override; - procedure AddMapping(const AMethod: string; const ACriteria: IRouteCriteria; const ARoute: TrsRoute); overload; + procedure AddMapping(const AMethod: string; const ACriteria: IRouteCriteria; const ARoute: IRoute); overload; - procedure AddMapping(const AMethod: string; const ARoute: TrsRoute); overload; + procedure AddMapping(const AMethod: string; const ARoute: IRoute); overload; function MethodMappings(const AMethod: string): TrsRouteMappings; @@ -223,7 +223,7 @@ procedure TrsConfiguration.SetPath(const APath: string); end; end; -procedure TrsConfiguration.AddMapping(const AMethod: string; const ARoute: TrsRoute); +procedure TrsConfiguration.AddMapping(const AMethod: string; const ARoute: IRoute); var C: IRouteCriteria; begin @@ -238,7 +238,7 @@ procedure TrsConfiguration.AddMapping(const AMethod: string; const ARoute: TrsRo end; procedure TrsConfiguration.AddMapping(const AMethod: string; - const ACriteria: IRouteCriteria; const ARoute: TrsRoute); + const ACriteria: IRouteCriteria; const ARoute: IRoute); begin if MethodMappings(AMethod).ContainsKey(ACriteria) then begin diff --git a/src/main/rsRouteMappings.pas b/src/main/rsRouteMappings.pas index 76e4804..2062336 100644 --- a/src/main/rsRouteMappings.pas +++ b/src/main/rsRouteMappings.pas @@ -43,7 +43,7 @@ interface type TMatchResult = record RouteCriteria: IRouteCriteria; - Route: TRsRoute; + Route: IRoute; end; (** @@ -52,12 +52,12 @@ TMatchResult = record TrsRouteMappings = class(TInterfacedObject, IRouteMappings) private FRouteCriteriaList: IInterfaceList; - FRouteList: TObjectList; + FRouteList: IInterfaceList; public constructor Create; overload; destructor Destroy; override; - procedure Add(const ACriteria: IRouteCriteria; const ARoute: TrsRoute); + procedure Add(const ACriteria: IRouteCriteria; const ARoute: IRoute); function ContainsKey(const ACriteria: IRouteCriteria): Boolean; @@ -90,15 +90,16 @@ constructor TrsRouteMappings.Create; inherited; FRouteCriteriaList := TInterfaceList.Create; - FRouteList := TObjectList.Create(True); + FRouteList := TInterfaceList.Create; end; destructor TrsRouteMappings.Destroy; begin - FRouteList.Free; + // FRouteList.Free; + inherited; end; -procedure TrsRouteMappings.Add(const ACriteria: IRouteCriteria; const ARoute: TrsRoute); +procedure TrsRouteMappings.Add(const ACriteria: IRouteCriteria; const ARoute: IRoute); begin Assert(Assigned(FRouteCriteriaList)); Assert(Assigned(ACriteria)); @@ -126,7 +127,7 @@ function TrsRouteMappings.FindMatch(const ACriteria: IRouteCriteria): TMatchResu // Log(Format('Comparing %s %s', [C.Path + C.Produces, MatchingRC.Path + MatchingRC.Produces])); if TrsRouteCriteria.Matches(MatchingRC, ACriteria) then begin - Result.Route := FRouteList[I] as TrsRoute; + Result.Route := FRouteList[I] as IRoute; Result.RouteCriteria := MatchingRC; Break; end; diff --git a/src/test/Unittests.dproj b/src/test/Unittests.dproj index 6ce1889..d5e8019 100644 --- a/src/test/Unittests.dproj +++ b/src/test/Unittests.dproj @@ -21,7 +21,7 @@ ..\main;..\..\..\daraja-framework\source;..\..\..\slf4p\src\main;$(DCC_UnitSearchPath) - DARAJA_LOGGING;DARAJA_RESTFUL_COMPATIBLE;$(DCC_Define) + DARAJA_LOGGING;xDARAJA_RESTFUL_COMPATIBLE;$(DCC_Define) Unittests.exe 00400000 x86 @@ -44,9 +44,9 @@ - + Base