mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Delphi Tokyo Compat
This commit is contained in:
parent
d0c3414a5e
commit
9b414b8665
@ -77,13 +77,13 @@ end;
|
||||
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<TArticle>): 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 @@ end;
|
||||
|
||||
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.
|
||||
|
@ -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 = <>
|
||||
|
@ -41,10 +41,12 @@ type
|
||||
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<Byte>;
|
||||
{ Private declarations }
|
||||
procedure ShowError(const AResponse: IMVCRESTResponse);
|
||||
procedure SetFilter(const Value: string);
|
||||
@ -120,6 +122,14 @@ begin
|
||||
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 @@ begin
|
||||
begin
|
||||
ShowError(Res);
|
||||
Abort;
|
||||
end
|
||||
else
|
||||
begin
|
||||
DataSet.Refresh;
|
||||
end;
|
||||
fBkmrk := DataSet.GetBookmark;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -104,10 +104,13 @@ type
|
||||
/// </summary>
|
||||
function SetResponseCompletedProc(aResponseCompletedProc: TResponseCompletedProc): IMVCRESTClient;
|
||||
|
||||
|
||||
{$IF Defined(SYDNEYORBETTER)}
|
||||
/// <summary>
|
||||
/// Executes while sending data
|
||||
/// </summary>
|
||||
function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient;
|
||||
{$ENDIF}
|
||||
|
||||
///<summary>
|
||||
/// Set the client certificate for the request</summary>
|
||||
|
@ -110,7 +110,9 @@ type
|
||||
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 @@ type
|
||||
/// <summary>
|
||||
/// Executes while sending data
|
||||
/// </summary>
|
||||
{$IF defined(SYDNEYORBETTER)}
|
||||
function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient;
|
||||
{$ENDIF}
|
||||
|
||||
///<summary>
|
||||
/// Set the client certificate for the request</summary>
|
||||
@ -958,7 +962,9 @@ begin
|
||||
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 @@ begin
|
||||
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 @@ begin
|
||||
fSendDataProc(AContentLength, AWriteCount, AAbort);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TMVCRESTClient.Options: IMVCRESTResponse;
|
||||
begin
|
||||
@ -1896,11 +1904,13 @@ begin
|
||||
fResponseCompletedProc := aResponseCompletedProc;
|
||||
end;
|
||||
|
||||
{$IF Defined(SYDNEYORBETTER)}
|
||||
function TMVCRESTClient.SetSendDataProc(
|
||||
aSendDataProc: TSendDataProc): IMVCRESTClient;
|
||||
begin
|
||||
fSendDataProc := aSendDataProc;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TMVCRESTClient.SetValidateServerCertificateProc(
|
||||
aValidateCertificateProc: TValidateServerCertificateProc): IMVCRESTClient;
|
||||
|
Loading…
Reference in New Issue
Block a user