From 420e541e7577508d8a97d2f571feb52c30a0a217 Mon Sep 17 00:00:00 2001 From: Albert S Date: Tue, 12 Oct 2021 20:02:43 +0200 Subject: [PATCH] CLI: Implement category delete,show,list --- cli.cpp | 31 +++++++++++++++++++++++++++++++ cli.h | 10 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/cli.cpp b/cli.cpp index 95cceba..6a23559 100644 --- a/cli.cpp +++ b/cli.cpp @@ -249,3 +249,34 @@ std::pair CLIHandler::version(const std::vector { return {true, get_version_string()}; } + +std::pair CLIHandler::category_list(const std::vector &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 CLIHandler::category_delete(const std::vector &args) +{ + auto categoryDao = this->db->createCategoryDao(); + categoryDao->deleteCategory(args.at(0)); + return {true, ""}; +} + +std::pair CLIHandler::category_show(const std::vector &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()}; +} diff --git a/cli.h b/cli.h index e39731e..9826002 100644 --- a/cli.h +++ b/cli.h @@ -33,6 +33,9 @@ class CLIHandler std::pair page_list(const std::vector &args); std::pair pageperms_set_permissions(const std::vector &args); std::pair version(const std::vector &args); + std::pair category_list(const std::vector &args); + std::pair category_delete(const std::vector &args); + std::pair category_show(const std::vector &args); std::vector cmds{ {{"user", @@ -50,6 +53,13 @@ class CLIHandler 1, {{{"list", "- lists existing pages", 0, {}, &CLIHandler::page_list}}}, &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", "set permissions on pages", 1,