Skip to content

Commit

Permalink
Added CreateResponse(string,string)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Apr 16, 2024
1 parent deff8e6 commit 74211a9
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions samples/services_injection/MainControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TMyController = class(TMVCController)

[MVCPath('/people')]
[MVCHTTPMethod([httpPOST])]
function CreatePerson([MVCFromBody] Person: TPerson): IMVCResponse;
function CreatePerson([MVCInject] OtherPeopleService: IPeopleService; [MVCFromBody] Person: TPerson): IMVCResponse;

[MVCPath('/people/($ID)')]
[MVCHTTPMethod([httpPUT])]
Expand Down Expand Up @@ -86,30 +86,22 @@ constructor TMyController.Create(const PeopleService: IPeopleService);
LogI('PeopleService in constructor: ' + IntToHex(NativeUInt(Pointer(PeopleService))));
end;


function TMyController.CreatePerson([MVCFromBody] Person: TPerson): IMVCResponse;
function TMyController.CreatePerson(OtherPeopleService: IPeopleService; Person: TPerson): IMVCResponse;
begin
LogI('Created ' + Person.FirstName + ' ' + Person.LastName);
Result := MVCResponseBuilder
.StatusCode(HTTP_STATUS.Created)
.Body('Person created')
.Build;
Result := CreatedResponse('', 'Person created (' + Person.ToString + ')' );
end;

function TMyController.UpdatePerson(ID: Integer; [MVCFromBody] Person: TPerson): IMVCResponse;
begin
LogI('Updated ' + Person.FirstName + ' ' + Person.LastName);
Result := MVCResponseBuilder
.StatusCode(HTTP_STATUS.NoContent)
.Build;
Result := NoContentResponse;
end;

function TMyController.DeletePerson(ID: Integer): IMVCResponse;
begin
LogI('Deleted person with id ' + ID.ToString);
Result := MVCResponseBuilder
.StatusCode(HTTP_STATUS.NoContent)
.Build;
Result := NoContentResponse;
end;


Expand Down

0 comments on commit 74211a9

Please sign in to comment.