2016-12-01 15:23:03 +01:00
|
|
|
unit CustomersControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-01-18 21:53:53 +01:00
|
|
|
MVCFramework, MVCFramework.Commons, CustomersTDGU;
|
2016-12-01 15:23:03 +01:00
|
|
|
|
|
|
|
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.
|