2014-03-10 17:39:29 +01:00
|
|
|
unit RoutingSampleControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-10-10 12:54:04 +02:00
|
|
|
MVCFramework, MVCFramework.Commons;
|
2014-03-10 17:39:29 +01:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
[MVCPath('/')]
|
|
|
|
TRoutingSampleController = class(TMVCController)
|
|
|
|
public
|
|
|
|
[MVCPath('/')]
|
|
|
|
procedure Index(CTX: TWebContext);
|
|
|
|
|
|
|
|
[MVCHTTPMethod([httpGet])]
|
|
|
|
[MVCPath('/search/($searchtext)/($page)')]
|
|
|
|
[MVCProduces('text/plain', 'UTF-8')]
|
|
|
|
[MVCConsumes('text/html')]
|
2020-05-11 23:39:43 +02:00
|
|
|
procedure SearchCustomers;
|
2014-03-10 17:39:29 +01:00
|
|
|
|
|
|
|
[MVCHTTPMethod([httpGet])]
|
|
|
|
[MVCPath('/people/($id)')]
|
|
|
|
[MVCProduces('application/json')]
|
2016-11-18 14:09:54 +01:00
|
|
|
procedure GetPerson(const id: Integer);
|
2014-03-10 17:39:29 +01:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, BusinessObjectsU, Data.DBXJSON;
|
|
|
|
|
|
|
|
{ TRoutingSampleController }
|
|
|
|
|
2016-11-18 14:09:54 +01:00
|
|
|
procedure TRoutingSampleController.GetPerson(const id: Integer);
|
2014-03-10 17:39:29 +01:00
|
|
|
var
|
|
|
|
P: TPerson;
|
|
|
|
begin
|
|
|
|
{
|
2016-11-18 14:09:54 +01:00
|
|
|
Use ID to load the person from a database...
|
2014-03-10 17:39:29 +01:00
|
|
|
In this example, we're creating a fake person
|
|
|
|
}
|
|
|
|
P := TPerson.Create;
|
|
|
|
P.FirstName := 'Daniele';
|
|
|
|
P.LastName := 'Teti';
|
|
|
|
P.DOB := EncodeDate(1975, 5, 2);
|
|
|
|
P.Married := True;
|
|
|
|
Render(P);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRoutingSampleController.Index(CTX: TWebContext);
|
|
|
|
begin
|
|
|
|
Render('This is the root path');
|
|
|
|
end;
|
|
|
|
|
2020-05-11 23:39:43 +02:00
|
|
|
procedure TRoutingSampleController.SearchCustomers;
|
2014-03-10 17:39:29 +01:00
|
|
|
var
|
|
|
|
search: string;
|
|
|
|
P: Integer;
|
|
|
|
orderby: string;
|
|
|
|
begin
|
2020-05-11 23:39:43 +02:00
|
|
|
search := Context.Request.Params['searchtext'];
|
|
|
|
P := Context.Request.ParamsAsInteger['page'];
|
2014-03-10 17:39:29 +01:00
|
|
|
orderby := '';
|
2020-05-11 23:39:43 +02:00
|
|
|
if Context.Request.QueryStringParamExists('order') then
|
|
|
|
orderby := Context.Request.QueryStringParam('order');
|
2014-03-10 17:39:29 +01:00
|
|
|
Render(Format(
|
|
|
|
'SEARCHTEXT: "%s"' + sLineBreak +
|
|
|
|
'PAGE: %d' + sLineBreak +
|
|
|
|
'ORDERBYFIELD: "%s"',
|
|
|
|
[search, P, orderby]));
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|