2014-06-27 15:30:39 +02:00
|
|
|
unit Controllers.Base;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-01-18 21:53:53 +01:00
|
|
|
MVCFramework, MVCFramework.Commons, Services, MainDM;
|
2014-06-27 15:30:39 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TBaseController = class abstract(TMVCController)
|
|
|
|
strict private
|
|
|
|
FDM: TdmMain;
|
|
|
|
FArticlesService: TArticlesService;
|
|
|
|
function GetDataModule: TdmMain;
|
|
|
|
strict protected
|
|
|
|
function GetArticlesService: TArticlesService;
|
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2020-01-24 10:09:14 +01:00
|
|
|
[MVCPath('/private')]
|
|
|
|
TPrivateController = class(TBaseController)
|
|
|
|
public
|
|
|
|
[MVCPath('/articles')]
|
|
|
|
[MVCHTTPMethods([httpDELETE])]
|
|
|
|
procedure DeleteAllArticles;
|
|
|
|
end;
|
|
|
|
|
2014-06-27 15:30:39 +02:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils;
|
|
|
|
|
|
|
|
{ TBaseController }
|
|
|
|
|
|
|
|
destructor TBaseController.Destroy;
|
|
|
|
begin
|
|
|
|
FArticlesService.Free;
|
|
|
|
FDM.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBaseController.GetArticlesService: TArticlesService;
|
|
|
|
begin
|
|
|
|
if not Assigned(FArticlesService) then
|
|
|
|
FArticlesService := TArticlesService.Create(GetDataModule);
|
|
|
|
Result := FArticlesService;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBaseController.GetDataModule: TdmMain;
|
|
|
|
begin
|
|
|
|
if not Assigned(FDM) then
|
|
|
|
FDM := TdmMain.Create(nil);
|
|
|
|
Result := FDM;
|
|
|
|
end;
|
|
|
|
|
2020-01-24 10:09:14 +01:00
|
|
|
{ TPrivateController }
|
|
|
|
|
|
|
|
procedure TPrivateController.DeleteAllArticles;
|
|
|
|
begin
|
|
|
|
GetArticlesService.DeleteAllArticles();
|
|
|
|
end;
|
|
|
|
|
2014-06-27 15:30:39 +02:00
|
|
|
end.
|