Skip to content

Commit

Permalink
* use IRoute where possible
Browse files Browse the repository at this point in the history
* fixes #11
  • Loading branch information
michaelJustin committed Jul 3, 2016
1 parent 6ee9f80 commit 5ef932f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
28 changes: 14 additions & 14 deletions src/main/djRestfulComponent.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/rsConfiguration.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions src/main/rsRouteMappings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface
type
TMatchResult = record
RouteCriteria: IRouteCriteria;
Route: TRsRoute;
Route: IRoute;
end;

(**
Expand All @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/Unittests.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_UnitSearchPath>..\main;..\..\..\daraja-framework\source;..\..\..\slf4p\src\main;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Define>DARAJA_LOGGING;DARAJA_RESTFUL_COMPATIBLE;$(DCC_Define)</DCC_Define>
<DCC_Define>DARAJA_LOGGING;xDARAJA_RESTFUL_COMPATIBLE;$(DCC_Define)</DCC_Define>
<DCC_DependencyCheckOutputName>Unittests.exe</DCC_DependencyCheckOutputName>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_Platform>x86</DCC_Platform>
Expand All @@ -44,9 +44,9 @@
<DCCReference Include="..\main\rsRoute.pas"/>
<DCCReference Include="..\main\rsRouteCriteria.pas"/>
<DCCReference Include="..\main\rsRouteMappings.pas"/>
<DCCReference Include="TestRestful.pas"/>
<DCCReference Include="..\main\rsInterfaces.pas"/>
<DCCReference Include="..\main\rsGlobal.pas"/>
<DCCReference Include="TestRestful.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down

0 comments on commit 5ef932f

Please sign in to comment.