Skip to content

Commit

Permalink
New class methods GetDocFullPath for returning path as string and as …
Browse files Browse the repository at this point in the history
…TRequestResourceParam
  • Loading branch information
SchneiderInfosystems committed Oct 6, 2023
1 parent 30ccd06 commit 8304f95
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Source/FB4D.Document.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ TFirestoreDocument = class(TInterfacedObject, IFirestoreDocument)
function ConvertRefPath(const Reference: string): string;
public
class function CreateCursor(const ProjectID: string): IFirestoreDocument;
class function GetDocFullPath(
const ProjectID: string;
const Database: string = cDefaultDatabaseID;
DocumentPath: TRequestResourceParam = []): TRequestResourceParam; overload;
class function GetDocFullPath(DocumentPath: TRequestResourceParam;
const ProjectID: string;
const Database: string = cDefaultDatabaseID): string; overload;
constructor Create(DocumentPath: TRequestResourceParam;
const ProjectID: string; const Database: string = cDefaultDatabaseID);
constructor CreateFromJSONObj(Response: IFirebaseResponse); overload;
Expand Down Expand Up @@ -386,12 +393,34 @@ function TFirestoreDocuments.GetGenericEnumerator: IEnumerator<IFirestoreDocumen

{ TFirestoreDocument }

class function TFirestoreDocument.GetDocFullPath(
DocumentPath: TRequestResourceParam; const ProjectID,
Database: string): string;
begin
result := Format(cFirestoreDocumentPath,
[ProjectID, Database, TFirebaseHelpers.EncodeResourceParams(DocumentPath)]);
end;

class function TFirestoreDocument.GetDocFullPath(const ProjectID,
Database: string; DocumentPath: TRequestResourceParam): TRequestResourceParam;
var
c, c0: integer;
begin
result := ['projects', ProjectID, 'databases', Database, 'documents'];
if length(DocumentPath) > 0 then
begin
c0 := length(result);
SetLength(result, c0 + length(DocumentPath));
for c := 0 to length(DocumentPath) - 1 do
result[c0 + c] := DocumentPath[c];
end;
end;

constructor TFirestoreDocument.Create(DocumentPath: TRequestResourceParam;
const ProjectID, Database: string);
begin
inherited Create;
fDocumentName := Format(cFirestoreDocumentPath,
[ProjectID, Database, TFirebaseHelpers.EncodeResourceParams(DocumentPath)]);
fDocumentName := GetDocFullPath(DocumentPath, ProjectID, Database);
fJSONObj := TJSONObject.Create;
fJSONObj.AddPair('name', fDocumentName);
SetLength(fFields, 0);
Expand Down

0 comments on commit 8304f95

Please sign in to comment.