unit uSvcCustom;

interface

uses
  System.Generics.Collections,
  System.SysUtils,
  JsonDataObjects,
  uSvc_Base,
  uCommons,
  uHeoObj_Base,
  uHeOObj_Custom;

type

  TKDYPlanLisuService = class(TServiceBase)
   public
    function GetAll: TObjectList<TKDYPlanLisu>;
    function GetByParams(params: TDictionary<string, string>): TObjectList<TKDYPlanLisu>;
    function GetByID (const AID: integer): TKDYPlanLisu;
    function GetMeta: TJSONObject;
  end;

implementation

uses
  System.StrUtils,
  FireDAC.Stan.Option,
  FireDAC.Comp.Client,
  FireDAC.Stan.Param,
  MVCFramework.FireDAC.Utils,
  MVCFramework.DataSet.Utils,
  MVCFramework.Serializer.Commons,
  helTabsBIDs;


{ TKDYPlanLisuService }

 function TKDYPlanLisuService.GetAll:TObjectList<TKDYPlanLisu>;
  var lSQL: string;
  begin
   lSQL:= 'SELECT ' + GetTabCols('dbo', tblPlanNasazLisu) + ' FROM ' + tblPlanNasazLisu + ' ORDER BY ID';
   FDM.sqlQry1.Open(lSQL, []);
   result:= FDM.sqlQry1.AsObjectList<TKDYPlanLisu>;
   FDM.sqlQry1.Close;
  end;



 function TKDYPlanLisuService.GetByParams(params: TDictionary<string, string>): TObjectList<TKDYPlanLisu>;
  begin

  end;



 function TKDYPlanLisuService.GetByID (const AID: integer): TKDYPlanLisu;
  var lSQL: string;
  begin
   lSQL:= 'SELECT ' + GetTabCols('dbo', tblPlanNasazLisu) + ' FROM ' + tblPlanNasazLisu + ' WHERE ID=:ID';
   FDM.sqlQry1.Open(lSQL, [AID]);
   try
     if not(FDM.sqlQry1.EOF) then
       result:= FDM.sqlQry1.AsObject<TKDYPlanLisu>
     else
       raise EServiceException.Create('Plán s ID ' + AID.ToString + ' nebyl nalezen.');
   finally
    FDM.sqlQry1.Close;
   end;
  end;



 function TKDYPlanLisuService.GetMeta: TJSONObject;
  var lSQL: string;
  begin
   try
   lSQL:= 'SELECT ' + GetTabCols('dbo', tblPlanNasazLisu) + ' FROM ' + tblPlanNasazLisu + ' WHERE 1=0';
     FDM.sqlQry1.Open(lSQL);
     Result := FDM.sqlQry1.MetadataAsJSONObject();
    finally
     FDM.sqlQry1.Close;
   end;
  end;


end.
