Skip to content

Commit

Permalink
Added MVCNameCaseDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jun 19, 2024
1 parent f795327 commit 66f7fcb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 25 additions & 3 deletions samples/functional_actions_showcase/ControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ interface
System.Generics.Collections, Data.DB, JsonDataObjects, System.Rtti;

type
[MVCNameCase(ncCamelCase)]
TPersonRec = record
FirstName, LastName: String;
Age: Integer;
class function Create: TPersonRec; static;
end;

[MVCNameCase(ncCamelCase)]
TPerson = class
private
fAge: Integer;
Expand All @@ -34,6 +32,8 @@ TMyController = class(TMVCController)
function GetSum(const A, B: Integer): Integer;
[MVCPath('/sumsasfloat/($A)/($B)')]
function GetSumAsFloat(const A, B: Extended): Extended;
[MVCPath('/booleans/($A)/($B)')]
function GetOrTruthTable(const A, B: Boolean): Boolean;
[MVCPath('/string/($A)/($B)')]
function GetConcatAsString(const A, B: String): String;

Expand Down Expand Up @@ -67,6 +67,15 @@ TMyController = class(TMVCController)
[MVCPath('/headers')]
function GetWithCustomHeaders: TObjectList<TPerson>;

{ exceptions }
[MVCPath('/exception1')]
function GetMVCException: Integer;

[MVCPath('/exception2')]
function GetGeneralException: Integer;



{ using IMVCResponse and Response Methods}
[MVCPath('/mvcresponse/message')]
function GetMVCResponseSimple: IMVCResponse;
Expand Down Expand Up @@ -140,7 +149,10 @@ function TMyController.GetMultipleDataSet2: IMVCObjectDictionary;
end;
end;


function TMyController.GetMVCException: Integer;
begin
raise EMVCException.Create(HTTP_STATUS.NotFound, 'Resource not found');
end;

function TMyController.GetMVCResponseNoBody: IMVCResponse;
begin
Expand Down Expand Up @@ -226,6 +238,11 @@ function TMyController.GetOKResponse: IMVCResponse;
Result := OKResponse;
end;

function TMyController.GetOrTruthTable(const A, B: Boolean): Boolean;
begin
Result := A or B;
end;

function TMyController.GetMVCResponseWithJSON: IMVCResponse;
begin
Result := OKResponse(StrToJSONObject('{"name":"Daniele","surname":"Teti"}'));
Expand Down Expand Up @@ -292,6 +309,11 @@ function TMyController.GetConcatAsString(const A, B: String): String;
Result := A + B;
end;

function TMyController.GetGeneralException: Integer;
begin
raise Exception.Create('This is a general exception');
end;

function TMyController.GetWithCustomHeaders: TObjectList<TPerson>;
begin
Result := TObjectList<TPerson>.Create;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ uses
IdHTTPWebBrokerBridge,
ControllerU in 'ControllerU.pas',
WebModuleU in 'WebModuleU.pas' {MyWebModule: TWebModule},
MainDMU in 'MainDMU.pas' {dmMain: TDataModule};
MainDMU in 'MainDMU.pas', MVCFramework.Serializer.Commons {dmMain: TDataModule};

{$R *.res}

Expand Down Expand Up @@ -54,6 +54,7 @@ begin
// When MVCSerializeNulls = True empty nullables and nil are serialized as json null.
// When MVCSerializeNulls = False empty nullables and nil are not serialized at all.
MVCSerializeNulls := True;
MVCNameCaseDefault := TMVCNameCase.ncCamelCase;

try
if WebRequestHandler <> nil then
Expand Down

0 comments on commit 66f7fcb

Please sign in to comment.