Hi,
For training and understanding purposes, I'm trying to define and implement the same endpoints as the ones autogenerated when using xData/Aurelius.
I think I've been able to define (and Route w/TRoutingPrecedence = Service) the interface for a simple table (DemoTable), in a way that it is now using my implementation instead of the autogenerated ones.
Entity:
[Entity]
[Table('DemoTable')]
[Model('Default')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TDemoTable = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoUpdate])]
FID: Integer;
[Column('Name', [], 50)]
FName: Nullable<string>;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ParentID', [], 'ID')]
FParentID: Proxy<TDemoTable>;
function GetParentID: TDemoTable;
procedure SetParentID(const Value: TDemoTable);
public
property ID: Integer read FID write FID;
property Name: Nullable<string> read FName write FName;
property ParentID: TDemoTable read GetParentID write SetParentID;
end;
Interface definition:
[ServiceContract]
[Route('')]
IDemoTableService = interface(IInvokable)
['{350F11C4-DB96-4921-8757-22BD32B5BCD2}']
[HttpGet, Route('DemoTable')] function ListDemoTables(Query: TXDataQuery): TList<TDemoTable>;
[HttpPost, Route('DemoTable')] procedure CreateDemoTable;
[HttpGet, Route('DemoTable({ID})')] function RetrieveDemoTable(ID: integer): TDemoTable;
[HttpPut, Route('DemoTable({ID})')] procedure UpdateDemoTable;
[HttpDelete, Route('DemoTable({ID})')] procedure DeleteDemoTable(ID: integer);
[HttpPatch, Route('DemoTable({ID})')] procedure MergeDemoTable(ID: integer);
end;
Interface Implementation:
I've handled the implementation for HttpGet, HttpGet{ID} and HttpDelete{ID} in a way I'm happy with. But for HttpPost, HttpPut{ID} and HttpPatch{ID} I'm stuggling a bit.
For HttpPost I assume it would be something like:
procedure TDemoTableService.CreateDemoTable;
var
lManager: TObjectManager;
lDemoTable: TDemoTable;
begin
lManager := TXDataOperationContext.Current.GetManager;
lDemoTable := TDemoTable.Create;
"lDemoTable.Values" := "Posted body"; <-- HOW TO DO THIS?
lManager.AddOwnership(lDemoTable);
lManager.Save(lDemoTable);
end;
Assuming the above interface is defined correctly, may I ask if you have some hints/help or a quick example on to implement the mentioned functions/procedures?
Thank you in advance.