Skip to content

Commit

Permalink
Updated CustomRoleAuth samples
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jul 28, 2024
1 parent 1edfe8f commit 42e0bc1
Show file tree
Hide file tree
Showing 11 changed files with 991 additions and 530 deletions.
497 changes: 316 additions & 181 deletions samples/CustomRoleAuth/CustomRoleAuthClient.dproj

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions samples/CustomRoleAuth/CustomRoleAuthGroup.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<Projects Include="..\jsonwebtoken_roleauth\JWTRoleAuthServer.dproj">
<Dependencies/>
</Projects>
<Projects Include="..\serversideviewcustom\ServerSideViewsCustomEngine.dproj">
<Dependencies/>
</Projects>
<Projects Include="..\serversideviews_lua\ServerSideViewsLua.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Default.Personality.12</Borland.Personality>
Expand Down Expand Up @@ -47,14 +53,32 @@
<Target Name="JWTRoleAuthServer:Make">
<MSBuild Projects="..\jsonwebtoken_roleauth\JWTRoleAuthServer.dproj" Targets="Make"/>
</Target>
<Target Name="ServerSideViewsCustomEngine">
<MSBuild Projects="..\serversideviewcustom\ServerSideViewsCustomEngine.dproj"/>
</Target>
<Target Name="ServerSideViewsCustomEngine:Clean">
<MSBuild Projects="..\serversideviewcustom\ServerSideViewsCustomEngine.dproj" Targets="Clean"/>
</Target>
<Target Name="ServerSideViewsCustomEngine:Make">
<MSBuild Projects="..\serversideviewcustom\ServerSideViewsCustomEngine.dproj" Targets="Make"/>
</Target>
<Target Name="ServerSideViewsLua">
<MSBuild Projects="..\serversideviews_lua\ServerSideViewsLua.dproj"/>
</Target>
<Target Name="ServerSideViewsLua:Clean">
<MSBuild Projects="..\serversideviews_lua\ServerSideViewsLua.dproj" Targets="Clean"/>
</Target>
<Target Name="ServerSideViewsLua:Make">
<MSBuild Projects="..\serversideviews_lua\ServerSideViewsLua.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="CustomRoleAuthServer;CustomRoleAuthClient;JWTRoleAuthServer"/>
<CallTarget Targets="CustomRoleAuthServer;CustomRoleAuthClient;JWTRoleAuthServer;ServerSideViewsCustomEngine;ServerSideViewsLua"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="CustomRoleAuthServer:Clean;CustomRoleAuthClient:Clean;JWTRoleAuthServer:Clean"/>
<CallTarget Targets="CustomRoleAuthServer:Clean;CustomRoleAuthClient:Clean;JWTRoleAuthServer:Clean;ServerSideViewsCustomEngine:Clean;ServerSideViewsLua:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="CustomRoleAuthServer:Make;CustomRoleAuthClient:Make;JWTRoleAuthServer:Make"/>
<CallTarget Targets="CustomRoleAuthServer:Make;CustomRoleAuthClient:Make;JWTRoleAuthServer:Make;ServerSideViewsCustomEngine:Make;ServerSideViewsLua:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
379 changes: 257 additions & 122 deletions samples/CustomRoleAuth/CustomRoleAuthServer.dproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion samples/CustomRoleAuth/MyWebModuleU.dfm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
object MyWebModule: TMyWebModule
OldCreateOrder = False
OnCreate = WebModuleCreate
OnDestroy = WebModuleDestroy
Actions = <>
Expand Down
2 changes: 1 addition & 1 deletion samples/CustomRoleAuth/MyWebModuleU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
Expand Down
2 changes: 1 addition & 1 deletion samples/CustomRoleAuth/PrivateControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
Expand Down
2 changes: 1 addition & 1 deletion samples/CustomRoleAuth/RoleAuthHandlerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
//
// Contributer on this file: Janidan - https://github.com/janidan
//
Expand Down
497 changes: 316 additions & 181 deletions samples/async_task/AsyncTaskSample.dproj

Large diffs are not rendered by default.

28 changes: 11 additions & 17 deletions samples/async_task/MainFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,25 @@ procedure TMainForm.btnWithExClick(Sender: TObject);
btnWithEx.Caption := 'processing...';
btnWithEx.Enabled := False;
MVCAsync.Run<String>(
function: String
function: String { background thread }
begin
Sleep(1000);
raise Exception.Create('BOOOM!');
end,
procedure(const Value: String)
procedure(const Value: String) { main thread }
begin
//never called
end,
procedure(const Expt: Exception)
procedure(const Expt: Exception) { main thread }
begin
ShowMessage(Expt.Message);
end,
procedure { main thread }
begin
// always executed
btnWithEx.Caption := lSavedCaption;
btnWithEx.Enabled := True;
btnWithEx.Update;
ShowMessage(Expt.Message);
end
);
end;
Expand All @@ -84,26 +88,16 @@ procedure TMainForm.btnWithExcDefaultClick(Sender: TObject);
procedure(const Value: String)
begin
//never called
end
);


//just to re-enable the button
MVCAsync.Run<Boolean>(
function: Boolean
begin
Sleep(3000);
Result := True;
end,
procedure(const Value: Boolean)
nil, //there isn't a exception handler - the default one is used
procedure
begin
// always executed
btnWithExcDefault.Caption := lSavedCaption;
btnWithExcDefault.Enabled := True;
btnWithExcDefault.Update;
end
);


end;

end.
38 changes: 16 additions & 22 deletions samples/avoid_mid_air_collisions_sample/MainControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ TMyController = class(TMVCController)
public
[MVCPath]
[MVCHTTPMethod([httpGET])]
procedure GetPeople;

function GetPeople: IMVCObjectDictionary;

[MVCPath('/($id)')]
[MVCHTTPMethod([httpGET])]
procedure Getperson(id: Integer);
function GetPersonByID(id: Integer): TPerson;

[MVCPath]
[MVCHTTPMethod([httpPOST])]
procedure Createperson([MVCFromBody] const Person: TPerson);
function Createperson([MVCFromBody] const Person: TPerson): IMVCResponse;

[MVCPath('/($id)')]
[MVCHTTPMethod([httpPUT])]
procedure UpdatePerson(id: Integer; [MVCFromBody] const Person: TPerson);
function UpdatePerson(id: Integer; [MVCFromBody] const Person: TPerson): IMVCResponse;

[MVCPath('/($id)')]
[MVCHTTPMethod([httpDELETE])]
procedure DeletePerson(id: Integer);

function DeletePerson(id: Integer): IMVCResponse;
end;


Expand All @@ -39,21 +37,18 @@ implementation
System.SysUtils, MVCFramework.Logger, System.StrUtils, MVCFramework.Cache,
System.Rtti, MVCFramework.Rtti.Utils, MVCFramework.ActiveRecord;

procedure TMyController.GetPeople;
function TMyController.GetPeople: IMVCObjectDictionary;
begin
Render(ObjectDict().Add('people', TMVCActiveRecord.All<TPerson>));
Result := ObjectDict().Add('people', TMVCActiveRecord.All<TPerson>);
end;

procedure TMyController.Getperson(id: Integer);
var
lPerson: TPerson;
function TMyController.GetPersonByID(id: Integer): TPerson;
begin
lPerson := TMVCActiveRecord.GetByPK<TPerson>(ID);
SetETag(lPerson.GetUniqueString);
Render(lPerson, True);
Result := TMVCActiveRecord.GetByPK<TPerson>(ID);
SetETag(Result.GetUniqueString);
end;

procedure TMyController.Createperson([MVCFromBody] const Person: TPerson);
function TMyController.Createperson([MVCFromBody] const Person: TPerson): IMVCResponse;
var
lValue: TValue;
begin
Expand All @@ -70,10 +65,10 @@ procedure TMyController.Createperson([MVCFromBody] const Person: TPerson);
finally
TMVCCacheSingleton.Instance.EndWrite;
end;
Render201Created();
Result := CreatedResponse();
end;

procedure TMyController.UpdatePerson(id: Integer; [MVCFromBody] const Person: TPerson);
function TMyController.UpdatePerson(id: Integer; [MVCFromBody] const Person: TPerson): IMVCResponse;
var
lPerson: TPerson;
begin
Expand All @@ -92,22 +87,21 @@ procedure TMyController.UpdatePerson(id: Integer; [MVCFromBody] const Person: TP
SetETag(lPerson.GetUniqueString);

//reply with a 200 OK
RenderStatusMessage(HTTP_STATUS.OK);
Result := OKResponse();
finally
lPerson.Free;
end;
end;


procedure TMyController.DeletePerson(id: Integer);
function TMyController.DeletePerson(id: Integer): IMVCResponse;
var
lPerson: TPerson;
begin
lPerson := TMVCActiveRecord.GetByPK<TPerson>(ID);
try
CheckIfMatch(lPerson.GetUniqueString);
lPerson.Delete();
Render204NoContent();
Result := NoContentResponse();
except
lPerson.Free;
raise;
Expand Down
Loading

0 comments on commit 42e0bc1

Please sign in to comment.