diff --git a/samples/articles_crud_server/Controllers.Articles.pas b/samples/articles_crud_server/Controllers.Articles.pas index 10e930d6..74a7cdbc 100644 --- a/samples/articles_crud_server/Controllers.Articles.pas +++ b/samples/articles_crud_server/Controllers.Articles.pas @@ -77,13 +77,13 @@ constructor TArticlesController.Create(ArticlesService: IArticlesService); function TArticlesController.CreateArticle(const Article: TArticle): IMVCResponse; begin fArticlesService.Add(Article); - Render201Created('/articles/' + Article.id.ToString, 'Article Created'); + Result := CreatedResponse('/articles/' + Article.id.ToString, 'Article Created'); end; function TArticlesController.CreateArticles(const ArticleList: TObjectList): IMVCResponse; begin fArticlesService.CreateArticles(ArticleList); - Result := MVCResponseBuilder.StatusCode(HTTP_STATUS.Created).Build; + Result := CreatedResponse('', 'Articles created'); end; procedure TArticlesController.DeleteArticleByID(id: Integer); @@ -93,43 +93,29 @@ procedure TArticlesController.DeleteArticleByID(id: Integer); function TArticlesController.GetArticles: IMVCResponse; begin - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Body(fArticlesService.GetAll) - .Build; + Result := OKResponse(fArticlesService.GetAll); end; function TArticlesController.GetArticlesByDescription(const Search: String): IMVCResponse; begin - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Body(fArticlesService.GetArticles(Search)) - .Build; + Result := OKResponse(fArticlesService.GetArticles(Search)); end; function TArticlesController.UpdateArticleByID(const Article: TArticle; const id: Integer): IMVCResponse; begin Article.id := id; fArticlesService.Update(Article); - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Build; + Result := OKResponse; end; function TArticlesController.GetArticleByID(id: Integer): IMVCResponse; begin - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Body(fArticlesService.GetByID(id)) - .Build; + Result := OKResponse(fArticlesService.GetByID(id)); end; function TArticlesController.GetArticleMeta: IMVCResponse; begin - Result := MVCResponseBuilder - .StatusCode(HTTP_STATUS.OK) - .Body(fArticlesService.GetMeta) - .Build; + Result := OKResponse(fArticlesService.GetMeta); end; end. diff --git a/samples/articles_crud_vcl_client/MainFormU.dfm b/samples/articles_crud_vcl_client/MainFormU.dfm index d7069d22..2858e633 100644 --- a/samples/articles_crud_vcl_client/MainFormU.dfm +++ b/samples/articles_crud_vcl_client/MainFormU.dfm @@ -19,7 +19,6 @@ object MainForm: TMainForm Height = 112 Align = alTop TabOrder = 0 - ExplicitWidth = 872 object DBNavigator1: TDBNavigator AlignWithMargins = True Left = 585 @@ -29,7 +28,6 @@ object MainForm: TMainForm DataSource = dsrcArticles Align = alRight TabOrder = 3 - ExplicitLeft = 581 end object btnOpen: TButton AlignWithMargins = True @@ -72,7 +70,6 @@ object MainForm: TMainForm Align = alBottom BevelOuter = bvNone TabOrder = 4 - ExplicitWidth = 870 object Label1: TLabel Left = 3 Top = 11 @@ -153,6 +150,7 @@ object MainForm: TMainForm object dsArticles: TFDMemTable AfterOpen = dsArticlesAfterOpen BeforePost = dsArticlesBeforePost + AfterPost = dsArticlesAfterPost BeforeDelete = dsArticlesBeforeDelete BeforeRefresh = dsArticlesBeforeRefresh FieldDefs = <> diff --git a/samples/articles_crud_vcl_client/MainFormU.pas b/samples/articles_crud_vcl_client/MainFormU.pas index 26124f50..53cddf5d 100644 --- a/samples/articles_crud_vcl_client/MainFormU.pas +++ b/samples/articles_crud_vcl_client/MainFormU.pas @@ -41,10 +41,12 @@ TMainForm = class(TForm) procedure dsArticlesBeforeRowRequest(DataSet: TFDDataSet); procedure btnRefreshRecordClick(Sender: TObject); procedure btnFilterClick(Sender: TObject); + procedure dsArticlesAfterPost(DataSet: TDataSet); private fFilter: string; fLoading: Boolean; fRESTClient: IMVCRESTClient; + fBkmrk: TArray; { Private declarations } procedure ShowError(const AResponse: IMVCRESTResponse); procedure SetFilter(const Value: string); @@ -120,6 +122,14 @@ procedure TMainForm.dsArticlesAfterOpen(DataSet: TDataSet); end; end; +procedure TMainForm.dsArticlesAfterPost(DataSet: TDataSet); +begin + if DataSet.BookmarkValid(fBkmrk) then + begin + DataSet.GotoBookmark(fBkmrk); + end; +end; + procedure TMainForm.dsArticlesBeforeDelete(DataSet: TDataSet); var Res: IMVCRESTResponse; @@ -147,11 +157,8 @@ procedure TMainForm.dsArticlesBeforePost(DataSet: TDataSet); begin ShowError(Res); Abort; - end - else - begin - DataSet.Refresh; end; + fBkmrk := DataSet.GetBookmark; end; end; diff --git a/sources/MVCFramework.RESTClient.Intf.pas b/sources/MVCFramework.RESTClient.Intf.pas index 4a7ef1bb..92696af0 100644 --- a/sources/MVCFramework.RESTClient.Intf.pas +++ b/sources/MVCFramework.RESTClient.Intf.pas @@ -104,10 +104,13 @@ interface /// function SetResponseCompletedProc(aResponseCompletedProc: TResponseCompletedProc): IMVCRESTClient; + +{$IF Defined(SYDNEYORBETTER)} /// /// Executes while sending data /// function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient; +{$ENDIF} /// /// Set the client certificate for the request diff --git a/sources/MVCFramework.RESTClient.pas b/sources/MVCFramework.RESTClient.pas index 2468c810..8649fd05 100644 --- a/sources/MVCFramework.RESTClient.pas +++ b/sources/MVCFramework.RESTClient.pas @@ -110,7 +110,9 @@ TMVCRESTClient = class(TInterfacedObject, IMVCRESTClient) procedure DoBeforeRequest(aRequest: IHTTPRequest); procedure DoRequestCompleted(aResponse: IHTTPResponse; var aHandled: Boolean); procedure DoResponseCompleted(aMVCRESTResponse: IMVCRESTResponse); +{$IF defined(SYDNEYORBETTER)} procedure DoOnSendDataEvent(const Sender: TObject; AContentLength, AWriteCount: Int64; var AAbort: Boolean); +{$ENDIF} function GetBodyFormData: TMultipartFormData; function ObjectIsList(aObject: TObject): Boolean; function SerializeObject(aObject: TObject): string; @@ -190,7 +192,9 @@ TMVCRESTClient = class(TInterfacedObject, IMVCRESTClient) /// /// Executes while sending data /// + {$IF defined(SYDNEYORBETTER)} function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient; + {$ENDIF} /// /// Set the client certificate for the request @@ -958,7 +962,9 @@ constructor TMVCRESTClient.Create; fHTTPClient.OnValidateServerCertificate := DoValidateServerCertificate; fHTTPClient.HandleRedirects := True; fHTTPClient.MaxRedirects := TMVCRESTClientConsts.DEFAULT_MAX_REDIRECTS; +{$IF defined(SYDNEYORBETTER)} fHTTPClient.OnSendData := DoOnSendDataEvent; +{$ENDIF} {$IF defined(TOKYOORBETTER)} fHTTPClient.SecureProtocols := CHTTPDefSecureProtocols; {$ENDIF} @@ -1520,6 +1526,7 @@ function TMVCRESTClient.ObjectIsList(aObject: TObject): Boolean; Result := fRttiContext.GetType(aObject.ClassType).GetMethod('GetEnumerator') <> nil; end; +{$IF defined(SYDNEYORBETTER)} procedure TMVCRESTClient.DoOnSendDataEvent(const Sender: TObject; AContentLength, AWriteCount: Int64; var AAbort: Boolean); begin @@ -1528,6 +1535,7 @@ procedure TMVCRESTClient.DoOnSendDataEvent(const Sender: TObject; AContentLength fSendDataProc(AContentLength, AWriteCount, AAbort); end; end; +{$ENDIF} function TMVCRESTClient.Options: IMVCRESTResponse; begin @@ -1896,11 +1904,13 @@ function TMVCRESTClient.SetResponseCompletedProc(aResponseCompletedProc: TRespon fResponseCompletedProc := aResponseCompletedProc; end; +{$IF Defined(SYDNEYORBETTER)} function TMVCRESTClient.SetSendDataProc( aSendDataProc: TSendDataProc): IMVCRESTClient; begin fSendDataProc := aSendDataProc; end; +{$ENDIF} function TMVCRESTClient.SetValidateServerCertificateProc( aValidateCertificateProc: TValidateServerCertificateProc): IMVCRESTClient;