HandlerPage: Support lookup by title

This commit is contained in:
Albert S. 2022-03-29 22:34:22 +02:00
parent e876b15c5d
commit 15e4f081cc

View File

@ -26,9 +26,20 @@ Response HandlerPage::handle(const Request &r)
std::string pagename = r.get("page");
auto pageDao = this->database->createPageDao();
if(pagename.empty())
{
std::string title = r.get("title");
if(title.empty())
{
return errorResponse("No page given", "No page given to request");
}
title = utils::strreplace(title, "-", " ");
auto page = pageDao->findByTitle(title);
if(!page)
{
return errorResponse("No page by such title", "No page with such title exists");
}
pagename = page->name;
}
if(pageMustExist() && !pageDao->exists(pagename))
{