Browse Source

moved tags from pages to documents

master
Pascal Gloor 5 years ago
parent
commit
5ebf446344
2 changed files with 18 additions and 16 deletions
  1. 10
    8
      cgi/autodoc.fcgi
  2. 8
    8
      etc/openapi.json

+ 10
- 8
cgi/autodoc.fcgi View File

my $document; my $document;
my @pages; my @pages;
my @pageids; my @pageids;
my @tags;


my $q = sqlquery($dbh, "SELECT * FROM documents WHERE id = ?", $id); my $q = sqlquery($dbh, "SELECT * FROM documents WHERE id = ?", $id);
while(my $hash = $q->fetchrow_hashref()) { $document = $hash; } while(my $hash = $q->fetchrow_hashref()) { $document = $hash; }
$q = sqlquery($dbh, "SELECT * FROM pages WHERE documentId = ?", $id); $q = sqlquery($dbh, "SELECT * FROM pages WHERE documentId = ?", $id);
while(my $hash = $q->fetchrow_hashref()) { push @pages, $hash; push @pageids, $hash->{id}; } while(my $hash = $q->fetchrow_hashref()) { push @pages, $hash; push @pageids, $hash->{id}; }


$q = sqlquery($dbh, "
SELECT tags.tag AS tag
FROM documents_tags LEFT JOIN tags ON documents_tags.tagId = tags.id
WHERE documentId = ?i SORT BY tag", $id);
while(my ($tag) = $q->fetchrow_array()) { push @tags, $tag; }

my %lang; my %lang;


foreach my $page ( @pages ) { foreach my $page ( @pages ) {
owner => $document->{owner}, owner => $document->{owner},
status => $document->{status}, status => $document->{status},
languages => [ keys %lang ], languages => [ keys %lang ],
tags => [ @tags ],
}; };
return (200, "application/json", $out); return (200, "application/json", $out);
} }




my $out; my $out;
my %lang; my %lang;
my @tags;


my $q = sqlquery($dbh, "SELECT * FROM pages_lang WHERE pageId = ?", $id); my $q = sqlquery($dbh, "SELECT * FROM pages_lang WHERE pageId = ?", $id);
while(my $hash = $q->fetchrow_hashref()) { while(my $hash = $q->fetchrow_hashref()) {
$lang{$hash->{language}}++; $lang{$hash->{language}}++;
} }


$q = sqlquery($dbh, "
SELECT tags.tag AS tag
FROM pages_tags LEFT JOIN tags ON pages_tags.tagId = tags.id
WHERE pageId = ?i SORT BY tag", $id);
while(my ($tag) = $q->fetchrow_array()) { push @tags, $tag; }



$q = sqlquery($dbh, "SELECT * FROM pages WHERE documentId = ?", $id); $q = sqlquery($dbh, "SELECT * FROM pages WHERE documentId = ?", $id);
while(my $hash = $q->fetchrow_hashref()) { while(my $hash = $q->fetchrow_hashref()) {
owner => $hash->{owner}, owner => $hash->{owner},
status => $hash->{status}, status => $hash->{status},
language => [ keys %lang ], language => [ keys %lang ],
tags => [ @tags ],
}; };
} }



+ 8
- 8
etc/openapi.json View File

"fr" "fr"
] ]
} }
},
"tags": {
"readOnly": true,
"description": "List of all tags",
"type": "array",
"items": {
"type": "string"
}
} }
} }
}, },
"fr" "fr"
] ]
} }
},
"tags": {
"readOnly": true,
"description": "List of all tags",
"type": "array",
"items": {
"type": "string"
}
} }
} }
} }

Loading…
Cancel
Save