<commit_before>#include <cmd_handlers_lxd.h>
#include <utils_logger.h>
#include <runtasks.h>
#include <iostream>
#include <employ_settings.h>
#include <employ_database.h>
#include <employ_orchestra.h>

/*********************************************
 * Any actions with the container. Actions: create, start, stop and delete container
**********************************************/

CmdHandlerLXDContainers::CmdHandlerLXDContainers()
	: CmdHandlerBase("lxd_containers", "Any actions with the container. Actions: create, start, stop and delete container"){

	TAG = "LXD_HANDLER";

    m_modelCommandAccess.setAccessUnauthorized(false);
    m_modelCommandAccess.setAccessUser(false);
    m_modelCommandAccess.setAccessAdmin(true);

	// validation and description input fields
	m_vInputs.push_back(CmdInputDef("name").string_().required().description("Container name"));
    m_vInputs.push_back(CmdInputDef("action").string_().required().description("Actions: create, start, stop and delete container"));
}

// ---------------------------------------------------------------------

void CmdHandlerLXDContainers::handle(ModelRequest *pRequest){
    using namespace std;
    QJsonObject jsonRequest = pRequest->data();
    QJsonObject jsonResponse;
    EmployDatabase *pDatabase = findEmploy<EmployDatabase>();

    QSqlDatabase db = *(pDatabase->database());

    string name = jsonRequest["name"].toString().trimmed().toStdString();
    std::string action = jsonRequest["action"].toString().toStdString();

    std::string sError;
    int nErrorCode;

    if (action == "create")
        create_container(name, sError, nErrorCode);

    if (action == "start")
        start_container(name, sError, nErrorCode);

    if (action == "stop")
        stop_container(name, sError, nErrorCode);

    if (action == "delete")
        delete_container(name, sError, nErrorCode);

    if (sError == "")
        pRequest->sendMessageSuccess(cmd(), jsonResponse);<commit_msg>Добавил обработку ошибки при несуществущей операции<commit_after>#include <cmd_handlers_lxd.h>
#include <utils_logger.h>
#include <runtasks.h>
#include <iostream>
#include <employ_settings.h>
#include <employ_database.h>
#include <employ_orchestra.h>
#include <vector>
#include <algorithm>

/*********************************************
 * Any actions with the container. Actions: create, start, stop and delete container
**********************************************/

CmdHandlerLXDContainers::CmdHandlerLXDContainers()
	: CmdHandlerBase("lxd_containers", "Any actions with the container. Actions: create, start, stop and delete container"){

	TAG = "LXD_HANDLER";

    m_modelCommandAccess.setAccessUnauthorized(false);
    m_modelCommandAccess.setAccessUser(false);
    m_modelCommandAccess.setAccessAdmin(true);

	// validation and description input fields
	m_vInputs.push_back(CmdInputDef("name").string_().required().description("Container name"));
    m_vInputs.push_back(CmdInputDef("action").string_().required().description("Actions: create, start, stop and delete container"));
}

// ---------------------------------------------------------------------

void CmdHandlerLXDContainers::handle(ModelRequest *pRequest){
    using namespace std;
    QJsonObject jsonRequest = pRequest->data();
    QJsonObject jsonResponse;
    EmployDatabase *pDatabase = findEmploy<EmployDatabase>();

    QSqlDatabase db = *(pDatabase->database());

    string name = jsonRequest["name"].toString().trimmed().toStdString();
    std::string action = jsonRequest["action"].toString().toStdString();

    std::string sError;
    int nErrorCode;
    std::vector<std::string> actions = {"create", "start", "stop", "delete"};

    if (std::find(actions.begin(), actions.end(), action) == actions.end())
        sError = "Несуществующая операция. Возможные операции: create, start, stop, delete";

    if (action == "create")
        create_container(name, sError, nErrorCode);

    if (action == "start")
        start_container(name, sError, nErrorCode);

    if (action == "stop")
        stop_container(name, sError, nErrorCode);

    if (action == "delete")
        delete_container(name, sError, nErrorCode);

    if (sError == "")
        pRequest->sendMessageSuccess(cmd(), jsonResponse);
{'fraction_non_alphanumeric': 0.2000942729201037, 'fraction_numerical': 0.0, 'mean_word_length': 4.385786802030457, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7383648', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1194, 'n_words': 256}