Added MVCNameCaseDefault

This commit is contained in:
Daniele Teti 2024-06-19 14:25:04 +02:00
parent f795327a7e
commit 66f7fcb8ac
2 changed files with 27 additions and 4 deletions

View File

@ -7,14 +7,12 @@ uses
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;
@ -34,6 +32,8 @@ type
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;
@ -67,6 +67,15 @@ type
[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;
@ -140,7 +149,10 @@ begin
end;
end;
function TMyController.GetMVCException: Integer;
begin
raise EMVCException.Create(HTTP_STATUS.NotFound, 'Resource not found');
end;
function TMyController.GetMVCResponseNoBody: IMVCResponse;
begin
@ -226,6 +238,11 @@ begin
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"}'));
@ -292,6 +309,11 @@ begin
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;

View File

@ -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}
@ -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