From fcee922c2acd315e81812cee373a7eb249b274bf Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Thu, 23 May 2024 10:03:30 +0200 Subject: [PATCH] Functional Actions Sample Clean --- .../ControllerU.pas | 29 +++++++++++++++---- .../function_actions_showcase.dpr | 15 ---------- .../function_actions_showcase.dproj | 5 ++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/samples/functional_actions_showcase/ControllerU.pas b/samples/functional_actions_showcase/ControllerU.pas index 44c8b80b..b73f97ee 100644 --- a/samples/functional_actions_showcase/ControllerU.pas +++ b/samples/functional_actions_showcase/ControllerU.pas @@ -67,7 +67,7 @@ TMyController = class(TMVCController) [MVCPath('/headers')] function GetWithCustomHeaders: TObjectList; - { using IMVCResponse } + { using IMVCResponse and Response Methods} [MVCPath('/mvcresponse/message')] function GetMVCResponseSimple: IMVCResponse; [MVCPath('/mvcresponse/data')] @@ -84,9 +84,14 @@ TMyController = class(TMVCController) function GetMVCResponseSimpleBuilderWithHeaders: IMVCResponse; [MVCPath('/mvcresponse/message/builder/nobody')] function GetMVCResponseNoBody: IMVCResponse; - // Standard Responses [MVCPath('/mvcresponse/ok')] function GetOKResponse: IMVCResponse; + [MVCPath('/mvcresponse/not_found')] + function GetNotFound: IMVCResponse; + [MVCPath('/mvcresponse/not_modified')] + function GetNotModified: IMVCResponse; + [MVCPath('/mvcresponse/accepted')] + function GetAccepted: IMVCResponse; end; implementation @@ -148,10 +153,7 @@ function TMyController.GetMVCResponseNoBody: IMVCResponse; function TMyController.GetMVCResponseSimple: IMVCResponse; begin - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Body('My Message') - .Build; + Result := OKResponse('My Message'); end; function TMyController.GetMVCResponseSimpleBuilderWithHeaders: IMVCResponse; @@ -209,6 +211,16 @@ function TMyController.GetMVCResponseWithObjectList: IMVCResponse; ])); end; +function TMyController.GetNotFound: IMVCResponse; +begin + Result := NotFoundResponse; +end; + +function TMyController.GetNotModified: IMVCResponse; +begin + Result := NotModifiedResponse; +end; + function TMyController.GetOKResponse: IMVCResponse; begin Result := OKResponse; @@ -270,6 +282,11 @@ function TMyController.GetSumAsFloat(const A, B: Extended): Extended; Result := A + B; end; +function TMyController.GetAccepted: IMVCResponse; +begin + Result := AcceptedResponse('https://www.danieleteti.it'); +end; + function TMyController.GetConcatAsString(const A, B: String): String; begin Result := A + B; diff --git a/samples/functional_actions_showcase/function_actions_showcase.dpr b/samples/functional_actions_showcase/function_actions_showcase.dpr index a77a40c4..89675d3e 100644 --- a/samples/functional_actions_showcase/function_actions_showcase.dpr +++ b/samples/functional_actions_showcase/function_actions_showcase.dpr @@ -59,21 +59,6 @@ begin if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass; - dotEnvConfigure( - function: IMVCDotEnv - begin - Result := NewDotEnv - .UseStrategy(TMVCDotEnvPriority.FileThenEnv) - //if available, by default, loads default environment (.env) - .UseProfile('test') //if available loads the test environment (.env.test) - .UseProfile('prod') //if available loads the prod environment (.env.prod) - .UseLogger(procedure(LogItem: String) - begin - LogW('dotEnv: ' + LogItem); - end) - .Build(); //uses the executable folder to look for .env* files - end); - WebRequestHandlerProc.MaxConnections := dotEnv.Env('dmvc.handler.max_connections', 1024); RunServer(dotEnv.Env('dmvc.server.port', 8080)); except diff --git a/samples/functional_actions_showcase/function_actions_showcase.dproj b/samples/functional_actions_showcase/function_actions_showcase.dproj index 5500510b..250270f1 100644 --- a/samples/functional_actions_showcase/function_actions_showcase.dproj +++ b/samples/functional_actions_showcase/function_actions_showcase.dproj @@ -9,6 +9,7 @@ 1 Console function_actions_showcase.dpr + function_actions_showcase true @@ -761,6 +762,9 @@ 1 + + 1 + @@ -1021,6 +1025,7 @@ + False