Prvni verze
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
unit uCtrlZamestnanci;
|
||||
|
||||
interface
|
||||
{$I 'GlobalDefs.inc'}
|
||||
|
||||
uses
|
||||
System.Generics.Collections,
|
||||
mvcframework,
|
||||
mvcframework.Commons,
|
||||
mvcframework.Serializer.Commons,
|
||||
uCtrlBase,
|
||||
uHeoObj_Base
|
||||
{$IFDEF SWAGGER}
|
||||
, MVCFramework.Swagger.Commons
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
const
|
||||
{$I globalConsts.inc}
|
||||
|
||||
type
|
||||
[MVCPath('/zamestnanec')]
|
||||
[MVCSwagSummary('Zamìstnanec', 'Zamìstnanci', '')]
|
||||
TZamestnanciController = class(TBaseController)
|
||||
public
|
||||
[MVCPath('/meta')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('Zamìstnanec', 'Vratí metadata', 'ZamestnanciGetMeta')]
|
||||
procedure GetMeta;
|
||||
|
||||
// [MVCDoc('Vrati udaje zamestnance dle jeho ID')]
|
||||
[MVCPath('/($id)')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('Zamìstnanec', 'Vratí detail zamìstnance (jen jméno/pøíjmení/tituly/støedisko/zakázka)', 'ZamestnanciGetByID')]
|
||||
[MVCSwagParam(plPath, 'id', 'ID zamìstnance', ptString, true)]
|
||||
[MVCSwagParam(plQuery, 'cislo', 'Èíslo zamìstnance', ptString, false)]
|
||||
[MVCSwagParam(plQuery, 'prijm', 'Pøíjmení zamìstnance', ptString, false)]
|
||||
[MVCSwagParam(plQuery, 'vestavu', '1=zamìstnanci ve stavu', ptString, false)]
|
||||
[MVCSwagParam(plQuery, 'kodcipu', 'Kód èipu zamìstnance (max 36 znakù)', ptString, false)]
|
||||
[MVCSwagResponses(200, 'Success', TZamestnanec)]
|
||||
procedure GetByID (id: string='';
|
||||
[MVCFromQueryString('cislo', '')] cislo: string='';
|
||||
[MVCFromQueryString('prijm', '')] prijm: string='';
|
||||
[MVCFromQueryString('vestavu', '')] veStavu: string='';
|
||||
[MVCFromQueryString('kodcipu', '')] kodCipu: string=''
|
||||
);
|
||||
|
||||
[MVCPath('')]
|
||||
[MVCHTTPMethod([httpGET])]
|
||||
[MVCSwagSummary('Zamìstnanec', 'Vratí seznam zamìstnancù', 'ZamestnanciGetAll')]
|
||||
[MVCSwagParam(plQuery, 'vestavu', '1=jen zamìstnance ve stavu', ptString, false)]
|
||||
[MVCSwagResponses(200, 'Success', TZamestnanec, true)]
|
||||
procedure GetAll ([MVCFromQueryString('vestavu', '')] veStavu: string=''
|
||||
);
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
uses
|
||||
uSvc_Base,
|
||||
uCommons,
|
||||
mvcframework.Serializer.Intf,
|
||||
System.RegularExpressions,
|
||||
System.StrUtils,
|
||||
System.SysUtils;
|
||||
|
||||
|
||||
|
||||
procedure TZamestnanciController.GetAll (veStavu: string= '');
|
||||
var idZam, cisZam: integer;
|
||||
params: TDictionary<string, string>;
|
||||
begin
|
||||
|
||||
params:= TDictionary<string, string>.Create;
|
||||
|
||||
veStavu:= sanitizeSQLString(veStavu);
|
||||
if (veStavu='1') then
|
||||
params.Add('veStavu', veStavu);
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetZamestnanciService.GetByParams (params)))
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
else
|
||||
raise;
|
||||
}
|
||||
end;
|
||||
|
||||
params.Free;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
procedure TZamestnanciController.GetByID (id: string=''; cislo: string=''; prijm: string=''; veStavu: string=''; kodCipu: string='');
|
||||
var idZam, cisZam: integer;
|
||||
params: TDictionary<string, string>;
|
||||
begin
|
||||
|
||||
params:= TDictionary<string, string>.Create;
|
||||
|
||||
idZam:= 0;
|
||||
id:= sanitizeSQLString(id);
|
||||
if (id<>'') then
|
||||
if not(TryStrToInt(id, idZam)) then
|
||||
idZam:= 0;
|
||||
if (idZam>0) then
|
||||
params.Add('id', idZam.ToString);
|
||||
|
||||
cisZam:= 0;
|
||||
cislo:= sanitizeSQLString(cislo);
|
||||
if (cislo<>'') then
|
||||
if not(TryStrToInt(cislo, cisZam)) then
|
||||
cisZam:= 0;
|
||||
if (cisZam>0) then
|
||||
params.Add('cislo', cisZam.ToString);
|
||||
|
||||
prijm:= sanitizeSQLString(prijm);
|
||||
if (prijm<>'') then
|
||||
params.Add('prijm', prijm);
|
||||
|
||||
kodCipu:= sanitizeSQLString(kodCipu);
|
||||
if (kodCipu<>'') then
|
||||
params.Add('kodCipu', kodCipu);
|
||||
|
||||
veStavu:= sanitizeSQLString(veStavu);
|
||||
if (veStavu<>'') then
|
||||
params.Add('veStavu', veStavu);
|
||||
|
||||
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetZamestnanciService.GetByParams (params)))
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
else
|
||||
raise;
|
||||
}
|
||||
end;
|
||||
|
||||
params.Free;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TZamestnanciController.GetMeta;
|
||||
begin
|
||||
try
|
||||
Render(ObjectDict().Add('data', GetZamestnanciService.GetMeta));
|
||||
except
|
||||
RenderStatusMessage (200);
|
||||
{
|
||||
on E: EServiceException do
|
||||
begin
|
||||
raise EMVCException.Create(E.Message, '', 0, 200);
|
||||
end
|
||||
else
|
||||
raise;
|
||||
}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user