You are not logged in.
Pages: 1
Can I be corrected for this code ?
I definitely miss Mormot2 documentation
function TUtilisateursService.GetUtilisateur(aID: TID): RawJSON;
var
obj: TOrmUtilisateurs;
begin
if not fClientDB.Retrieve(aID, obj, false) then
begin
raise ERestException.Create('404 - Utilisateur non trouvé');
end;
try
Result := JsonEncode(obj);
finally
obj.Free;
end;
end;
Offline
[dcc32 Erreur] Utilisateurs.pas(66): E2250 Aucune version surchargée de 'JsonEncode' ne peut être appelée avec ces arguments
Offline
You are missing the object creation that will trigger an AV and use ObjectToJson, not JsonEncode.
function TUtilisateursService.GetUtilisateur(aID: TID): RawJSON;
var
obj: TOrmUtilisateurs;
begin
obj := TOrmUtilisateurs; // <- missing create
try
if not fClientDB.Orm.Retrieve(aID, obj) then
raise ERestException.Create('404 - Utilisateur non trouvé');
Result := ObjectToJson(obj);
finally
obj.Free;
end;
end;
ou
function TUtilisateursService.GetUtilisateur(aID: TID): RawJSON;
var
obj: TOrmUtilisateurs;
begin
obj := TOrmUtilisateurs.Create(fClientDB.Orm, aID);
try
if ID = 0 then
raise ERestException.Create('404 - Utilisateur non trouvé');
Result := ObjectToJson(obj);
finally
obj.Free;
end;
end;
read there: SAD1.18 5.2. Working with Objects
Offline
You are still working at HTTP level in your mind: 404 error, bulk JSON result...
Just define services, with high level code, as if it was running locally.
So here you could e.g. return a TOrmUtilisateurs in an "out" parameter, with a boolean for success/failure.
Offline
You are missing the object creation that will trigger an AV and use ObjectToJson, not JsonEncode.
read there: SAD1.18 5.2. Working with Objects
Very helpfull
Thanks!
Offline
You are still working at HTTP level in your mind: 404 error, bulk JSON result...
Just define services, with high level code, as if it was running locally.
So here you could e.g. return a TOrmUtilisateurs in an "out" parameter, with a boolean for success/failure.
Right, it should be more informative.
Thank you for the advice.
Offline
Pages: 1