mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 08:15:53 +01:00
73 lines
1.6 KiB
ObjectPascal
73 lines
1.6 KiB
ObjectPascal
|
unit CustomersControllerU;
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses
|
||
|
MVCFramework, CustomersTDGU;
|
||
|
|
||
|
type
|
||
|
|
||
|
[MVCPath('/api')]
|
||
|
TCustomersController = class(TMVCController)
|
||
|
private
|
||
|
FCustomersTDG: TCustomersTDG;
|
||
|
protected
|
||
|
function GetDAL: TCustomersTDG;
|
||
|
procedure MVCControllerBeforeDestroy; override;
|
||
|
public
|
||
|
[MVCPath('/customers')]
|
||
|
[MVCHTTPMethod([httpGET])]
|
||
|
procedure GetCustomers;
|
||
|
|
||
|
[MVCPath('/customers/($ID)')]
|
||
|
[MVCHTTPMethod([httpGET])]
|
||
|
procedure GetCustomer(const ID: UInt64);
|
||
|
|
||
|
procedure OnBeforeAction(Context: TWebContext; const AActionName: string;
|
||
|
var Handled: Boolean); override;
|
||
|
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
|
||
|
|
||
|
end;
|
||
|
|
||
|
implementation
|
||
|
|
||
|
procedure TCustomersController.GetCustomer(const ID: UInt64);
|
||
|
begin
|
||
|
Render(GetDAL.GetCustomerById(ID), true, true);
|
||
|
end;
|
||
|
|
||
|
procedure TCustomersController.GetCustomers;
|
||
|
begin
|
||
|
Render(GetDAL.GetCustomers, true);
|
||
|
end;
|
||
|
|
||
|
function TCustomersController.GetDAL: TCustomersTDG;
|
||
|
begin
|
||
|
if not Assigned(FCustomersTDG) then
|
||
|
FCustomersTDG := TCustomersTDG.Create(nil);
|
||
|
Result := FCustomersTDG;
|
||
|
end;
|
||
|
|
||
|
procedure TCustomersController.MVCControllerBeforeDestroy;
|
||
|
begin
|
||
|
inherited;
|
||
|
FCustomersTDG.Free;
|
||
|
end;
|
||
|
|
||
|
procedure TCustomersController.OnAfterAction(Context: TWebContext; const AActionName: string);
|
||
|
begin
|
||
|
{ Executed after each action }
|
||
|
inherited;
|
||
|
end;
|
||
|
|
||
|
procedure TCustomersController.OnBeforeAction(Context: TWebContext; const AActionName: string;
|
||
|
var Handled: Boolean);
|
||
|
begin
|
||
|
{ Executed before each action
|
||
|
if handled is true (or an exception is raised) the actual
|
||
|
action will not be called }
|
||
|
inherited;
|
||
|
end;
|
||
|
|
||
|
end.
|