Compare commits
2 Commits
7a2f15cabe
...
420e541e75
Author | SHA1 | Date | |
---|---|---|---|
420e541e75 | |||
c18178a50f |
31
cli.cpp
31
cli.cpp
@ -249,3 +249,34 @@ std::pair<bool, std::string> CLIHandler::version(const std::vector<std::string>
|
|||||||
{
|
{
|
||||||
return {true, get_version_string()};
|
return {true, get_version_string()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<bool, std::string> CLIHandler::category_list(const std::vector<std::string> &args)
|
||||||
|
{
|
||||||
|
auto categoryDao = this->db->createCategoryDao();
|
||||||
|
auto categories = categoryDao->fetchList(QueryOption{});
|
||||||
|
std::stringstream stream;
|
||||||
|
for(std::string &cat : categories)
|
||||||
|
{
|
||||||
|
stream << cat << std::endl;
|
||||||
|
}
|
||||||
|
return {true, stream.str()};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<bool, std::string> CLIHandler::category_delete(const std::vector<std::string> &args)
|
||||||
|
{
|
||||||
|
auto categoryDao = this->db->createCategoryDao();
|
||||||
|
categoryDao->deleteCategory(args.at(0));
|
||||||
|
return {true, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<bool, std::string> CLIHandler::category_show(const std::vector<std::string> &args)
|
||||||
|
{
|
||||||
|
auto categoryDao = this->db->createCategoryDao();
|
||||||
|
auto members = categoryDao->fetchMembers(args.at(0), QueryOption{});
|
||||||
|
std::stringstream stream;
|
||||||
|
for(std::string &member : members)
|
||||||
|
{
|
||||||
|
stream << member << std::endl;
|
||||||
|
}
|
||||||
|
return {true, stream.str()};
|
||||||
|
}
|
||||||
|
10
cli.h
10
cli.h
@ -33,6 +33,9 @@ class CLIHandler
|
|||||||
std::pair<bool, std::string> page_list(const std::vector<std::string> &args);
|
std::pair<bool, std::string> page_list(const std::vector<std::string> &args);
|
||||||
std::pair<bool, std::string> pageperms_set_permissions(const std::vector<std::string> &args);
|
std::pair<bool, std::string> pageperms_set_permissions(const std::vector<std::string> &args);
|
||||||
std::pair<bool, std::string> version(const std::vector<std::string> &args);
|
std::pair<bool, std::string> version(const std::vector<std::string> &args);
|
||||||
|
std::pair<bool, std::string> category_list(const std::vector<std::string> &args);
|
||||||
|
std::pair<bool, std::string> category_delete(const std::vector<std::string> &args);
|
||||||
|
std::pair<bool, std::string> category_show(const std::vector<std::string> &args);
|
||||||
|
|
||||||
std::vector<struct cmd> cmds{
|
std::vector<struct cmd> cmds{
|
||||||
{{"user",
|
{{"user",
|
||||||
@ -50,6 +53,13 @@ class CLIHandler
|
|||||||
1,
|
1,
|
||||||
{{{"list", "- lists existing pages", 0, {}, &CLIHandler::page_list}}},
|
{{{"list", "- lists existing pages", 0, {}, &CLIHandler::page_list}}},
|
||||||
&CLIHandler::cli_help},
|
&CLIHandler::cli_help},
|
||||||
|
{"category",
|
||||||
|
"operation on categories",
|
||||||
|
1,
|
||||||
|
{{{"list", "- lists existing categories", 0, {}, &CLIHandler::category_list},
|
||||||
|
{"delete", " - deletes a category", 1, {}, &CLIHandler::category_delete},
|
||||||
|
{"show", " - shows pages of a category", 1, {}, &CLIHandler::category_show}}},
|
||||||
|
&CLIHandler::cli_help},
|
||||||
{"pageperms",
|
{"pageperms",
|
||||||
"set permissions on pages",
|
"set permissions on pages",
|
||||||
1,
|
1,
|
||||||
|
@ -46,15 +46,18 @@ SqliteQueryOption &SqliteQueryOption::setPrependWhere(bool b)
|
|||||||
std::string SqliteQueryOption::build()
|
std::string SqliteQueryOption::build()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
if(this->prependWhere)
|
||||||
|
{
|
||||||
|
result += "WHERE ";
|
||||||
|
}
|
||||||
if(!o.includeInvisible && !this->visibleColumnName.empty())
|
if(!o.includeInvisible && !this->visibleColumnName.empty())
|
||||||
{
|
{
|
||||||
if(this->prependWhere)
|
|
||||||
{
|
|
||||||
result += "WHERE ";
|
|
||||||
}
|
|
||||||
result += this->visibleColumnName + " = 1";
|
result += this->visibleColumnName + " = 1";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += " 1 = 1";
|
||||||
|
}
|
||||||
result += " ORDER BY " + orderByColumnName;
|
result += " ORDER BY " + orderByColumnName;
|
||||||
if(o.order == ASCENDING)
|
if(o.order == ASCENDING)
|
||||||
{
|
{
|
||||||
@ -66,7 +69,8 @@ std::string SqliteQueryOption::build()
|
|||||||
}
|
}
|
||||||
// TODO: limits for offset?
|
// TODO: limits for offset?
|
||||||
if(o.limit > 0)
|
if(o.limit > 0)
|
||||||
|
{
|
||||||
result += " LIMIT " + std::to_string(o.limit) + " OFFSET " + std::to_string(o.offset);
|
result += " LIMIT " + std::to_string(o.limit) + " OFFSET " + std::to_string(o.offset);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user