Prvni verze
This commit is contained in:
246
_custom/EMPolar/uCtrlCustom.pas
Normal file
246
_custom/EMPolar/uCtrlCustom.pas
Normal file
@ -0,0 +1,246 @@
|
||||
unit uCtrlCustom;
|
||||
|
||||
interface
|
||||
{$I 'GlobalDefs.inc'}
|
||||
|
||||
uses
|
||||
MVCframework,
|
||||
MVCframework.Commons,
|
||||
MVCframework.Serializer.Commons,
|
||||
// MVCframework.Serializer.Intf,
|
||||
System.Generics.Collections, // kvuli TDictionary
|
||||
System.RegularExpressions,
|
||||
// JsonDataObjects,
|
||||
uCommons, // kvuli EServiceException
|
||||
uCtrlBase,
|
||||
// uSvc_Base,
|
||||
helTabsBIDs,
|
||||
uHeoObj_Base,
|
||||
uHeOObj_Custom,
|
||||
uSvcCustom,
|
||||
uSvc_Obecne,
|
||||
MVCFramework.Swagger.Commons; // kvuli dokumentaci
|
||||
|
||||
const
|
||||
{$I .\..\..\globalConsts.inc}
|
||||
|
||||
|
||||
type
|
||||
|
||||
[MVCPath('/emp/nadoba')]
|
||||
TEMPNadobaController = class(TBaseController)
|
||||
public
|
||||
|
||||
[MVCPath('')]
|
||||
[MVCSwagSummary('EMP - vyr<79>b<EFBFBD>n<EFBFBD> n<>doby', 'Vr<56>t<EFBFBD> seznam n<>dob', 'EMPNadobaGetByCislo')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagParam(plQuery, 'cislo', '<27><>slo n<>doby', ptString, false, '1')]
|
||||
procedure GetByCislo ([MVCFromQueryString('cislo', '')] cislo: string
|
||||
);
|
||||
|
||||
[MVCPath('/meta')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('EMP - vyr<79>b<EFBFBD>n<EFBFBD> n<>doby', 'Meta informace seznamu n<>dob', 'EMPNadobaGetMeta')]
|
||||
procedure GetMeta;
|
||||
|
||||
[MVCPath('/($id)')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('EMP - vyr<79>b<EFBFBD>n<EFBFBD> n<>doby', 'Vr<56>t<EFBFBD> <20>daje n<>doby dle jej<65>ho ID', 'EMPNadobaGetByID')]
|
||||
[MVCSwagParam(plPath, 'id', 'ID n<>doby', ptString, true)]
|
||||
[MVCProduces('application/json')]
|
||||
procedure GetByID (id: string);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
[MVCPath('/emp/atest')]
|
||||
TEMPDokumentAtestController = class(TBaseController)
|
||||
private
|
||||
FDokumService: TDokumentService;
|
||||
public
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
|
||||
[MVCPath('/meta')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('EMP - dokumenty atest<73>', 'Meta informace dokumentu atestu', 'EMPDokumAtestGetMeta')]
|
||||
procedure GetMeta;
|
||||
|
||||
[MVCPath('/($id)')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('EMP - dokumenty atest<73>', 'Vr<56>t<EFBFBD> <20>daje dokumentu atestu dle jeho ID', 'EMPDokumAtestGetByID')]
|
||||
[MVCSwagParam(plPath, 'id', 'ID dokumentu atestu', ptString, true)]
|
||||
[MVCProduces('application/json')]
|
||||
procedure GetByID (id: string);
|
||||
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
System.SysUtils,
|
||||
FireDAC.Stan.Option,
|
||||
FireDAC.Comp.Client,
|
||||
FireDAC.Stan.Param,
|
||||
MVCFramework.FireDAC.Utils,
|
||||
MVCFramework.DataSet.Utils,
|
||||
uDataMod;
|
||||
|
||||
|
||||
{ TEMPNadobaController }
|
||||
|
||||
procedure TEMPNadobaController.GetByCislo (cislo: string);
|
||||
begin
|
||||
cislo:= sanitizeSQLString (cislo);
|
||||
|
||||
try
|
||||
if (cislo<>'') then
|
||||
Render(ObjectDict().Add('data', GetEMPNadobaService.GetByCislo (cislo)))
|
||||
else
|
||||
Render(ObjectDict().Add('data', GetEMPNadobaService.GetAll));
|
||||
except
|
||||
// RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
}
|
||||
on E:Exception do
|
||||
begin
|
||||
Writeln(E.Message);
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end;
|
||||
// RenderStatusMessage (200); // raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TEMPNadobaController.GetByID (id: string);
|
||||
var iId: integer;
|
||||
begin
|
||||
id:= sanitizeSQLString (id);
|
||||
if not(TryStrToInt(id, iId)) then
|
||||
iId:= 0;
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetEMPNadobaService.GetByID (iId))); // viz uSvc_Custom1.pas
|
||||
except
|
||||
// RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
}
|
||||
on E:Exception do
|
||||
begin
|
||||
Writeln(E.Message);
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end;
|
||||
// RenderStatusMessage (200); // raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TEMPNadobaController.GetMeta;
|
||||
begin
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetEMPNadobaService.GetMeta));
|
||||
except
|
||||
// RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
}
|
||||
on E:Exception do
|
||||
begin
|
||||
Writeln(E.Message);
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end;
|
||||
// RenderStatusMessage (200); // raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{ TEMPDokumentAtestController }
|
||||
|
||||
constructor TEMPDokumentAtestController.Create;
|
||||
begin
|
||||
inherited;
|
||||
FDokumService:= GetDokumentService;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
destructor TEMPDokumentAtestController.Destroy;
|
||||
begin
|
||||
if (FDokumService<>nil) then
|
||||
FreeAndNil (FDokumService);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TEMPDokumentAtestController.GetMeta;
|
||||
begin
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetDokumentService.GetMeta));
|
||||
except
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
{$ELSE}
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 404);
|
||||
end
|
||||
else
|
||||
raise;
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TEMPDokumentAtestController.GetByID (id: string);
|
||||
var iId: integer;
|
||||
p: TDictionary<string, string>;
|
||||
begin
|
||||
id:= sanitizeSQLString (id);
|
||||
if not(TryStrToInt(id, iId)) then
|
||||
iId:= 0;
|
||||
|
||||
p:= TDictionary<string, string>.Create;
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetDokumentService.GetByID (iId, true))) // viz uSvc_Custom1.pas
|
||||
except
|
||||
{$IFDEF NORENDER400}
|
||||
RenderStatusMessage (200);
|
||||
{$ELSE}
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 404);
|
||||
end
|
||||
else
|
||||
raise;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
p.Free;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user