2019-07-27 20:23:48 +02:00
|
|
|
|
unit MyController2U;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
MVCFramework,
|
|
|
|
|
MVCFramework.Commons,
|
2019-07-29 22:49:31 +02:00
|
|
|
|
MVCFramework.Swagger.Commons,
|
2019-07-31 13:40:11 +02:00
|
|
|
|
MVCFramework.Serializer.Commons,
|
|
|
|
|
MVCFramework.Middleware.Authentication.RoleBasedAuthHandler;
|
2019-07-27 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
type
|
2019-07-29 22:49:31 +02:00
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
TPerson = class
|
|
|
|
|
private
|
|
|
|
|
FName: string;
|
|
|
|
|
FAge: Integer;
|
|
|
|
|
FCountry: string;
|
2019-08-01 23:07:23 +02:00
|
|
|
|
FCode: Integer;
|
2019-07-29 22:49:31 +02:00
|
|
|
|
public
|
2019-08-02 20:54:52 +02:00
|
|
|
|
[MVCSwagJsonSchemaField(stInteger, 'code', 'person id', True, False)]
|
2019-08-01 23:07:23 +02:00
|
|
|
|
property Code: Integer read FCode write FCode;
|
2019-08-02 20:54:52 +02:00
|
|
|
|
[MVCSwagJsonSchemaField('name', 'person name', True, False)]
|
2019-07-29 22:49:31 +02:00
|
|
|
|
property Name: string read FName write FName;
|
2019-08-02 20:54:52 +02:00
|
|
|
|
[MVCSwagJsonSchemaField('age', 'person age', True, False)]
|
2019-07-29 22:49:31 +02:00
|
|
|
|
property Age: Integer read FAge write FAge;
|
2019-08-02 20:54:52 +02:00
|
|
|
|
[MVCSwagJsonSchemaField('country', 'Nationality of the person', True, False)]
|
2019-07-29 22:49:31 +02:00
|
|
|
|
property Country: string read FCountry write FCountry;
|
|
|
|
|
end;
|
2019-07-27 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
[MVCPath('/person')]
|
2019-10-30 00:21:13 +01:00
|
|
|
|
[MVCRequiresAuthentication]
|
2019-07-27 20:23:48 +02:00
|
|
|
|
TMyController2 = class(TMVCController)
|
|
|
|
|
public
|
|
|
|
|
[MVCPath('/($Id)')]
|
2019-09-25 14:54:02 +02:00
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
2019-08-01 23:07:23 +02:00
|
|
|
|
[MVCSwagSummary('Person', 'List Persons', '66e83aa7-d170-44a7-a502-8f25ddd2a18a')]
|
2019-10-30 00:21:13 +01:00
|
|
|
|
[MVCSwagParam(plPath, 'Id', 'Person id', ptInteger, True)]
|
|
|
|
|
[MVCSwagParam(plQuery, 'filter', 'Search filter', ptString, False)]
|
|
|
|
|
[MVCSwagParam(plQuery, 'per_page', 'Items per page', ptInteger, False)]
|
2019-09-25 14:54:02 +02:00
|
|
|
|
[MVCSwagResponses(200, 'Success', TPerson)]
|
2019-07-27 20:23:48 +02:00
|
|
|
|
[MVCSwagResponses(500, 'Internal Server Error')]
|
|
|
|
|
procedure GetPerson(const Id: Integer);
|
|
|
|
|
|
|
|
|
|
[MVCPath('')]
|
2019-09-25 14:54:02 +02:00
|
|
|
|
[MVCHTTPMethod([httpPOST])]
|
2019-07-27 20:23:48 +02:00
|
|
|
|
[MVCSwagSummary('Person', 'Insert Person')]
|
2019-08-02 20:54:52 +02:00
|
|
|
|
[MVCSwagParam(plBody, 'entity', 'Person object', TPerson, ptNotDefined, True)]
|
2019-07-27 20:23:48 +02:00
|
|
|
|
[MVCSwagResponses(201, 'Created')]
|
2019-08-01 23:07:23 +02:00
|
|
|
|
[MVCSwagResponses(401, 'Requires Authentication')]
|
2019-07-27 20:23:48 +02:00
|
|
|
|
[MVCSwagResponses(500, 'Internal Server Error')]
|
|
|
|
|
[MVCConsumes(TMVCMediaType.APPLICATION_JSON)]
|
|
|
|
|
procedure InsertPerson;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
MVCFramework.Controllers.Register;
|
|
|
|
|
|
|
|
|
|
{ TMyController2 }
|
|
|
|
|
|
2019-08-01 23:07:23 +02:00
|
|
|
|
procedure TMyController2.GetPerson(const Id: Integer);
|
2019-07-27 20:23:48 +02:00
|
|
|
|
var
|
|
|
|
|
LPerson: TPerson;
|
|
|
|
|
begin
|
|
|
|
|
LPerson := TPerson.Create;
|
2019-08-01 23:07:23 +02:00
|
|
|
|
LPerson.Code := Id;
|
2019-07-27 20:23:48 +02:00
|
|
|
|
LPerson.Name := 'Jo<4A>o Ant<6E>nio Duarte';
|
|
|
|
|
LPerson.Age := 26;
|
|
|
|
|
LPerson.Country := 'Brasil';
|
|
|
|
|
Render(LPerson);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyController2.InsertPerson;
|
2019-08-01 23:07:23 +02:00
|
|
|
|
var
|
|
|
|
|
LPerson: TPerson;
|
2019-07-27 20:23:48 +02:00
|
|
|
|
begin
|
2019-08-01 23:07:23 +02:00
|
|
|
|
LPerson := Context.Request.BodyAs<TPerson>;
|
|
|
|
|
Render(LPerson);
|
2019-10-30 00:21:13 +01:00
|
|
|
|
ResponseCreated();
|
2019-07-27 20:23:48 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
|
|
|
|
TControllersRegister.Instance.RegisterController(TMyController2, 'MyServerName');
|
|
|
|
|
|
|
|
|
|
end.
|