From 89083a50680ea3654145dc85945e6017d4891c09 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Fri, 26 Dec 2025 00:50:48 +0000 Subject: [PATCH] code: cpp,hpp,dbal (7 files) --- .../src/entities/workflow/create_workflow.hpp | 50 +++++++++++++++ .../src/entities/workflow/delete_workflow.hpp | 38 ++++++++++++ .../src/entities/workflow/get_workflow.hpp | 36 +++++++++++ dbal/cpp/src/entities/workflow/index.hpp | 14 +++++ .../src/entities/workflow/list_workflows.hpp | 62 +++++++++++++++++++ .../src/entities/workflow/update_workflow.hpp | 58 +++++++++++++++++ .../static_content/cli/main.cpp | 18 ++++++ 7 files changed, 276 insertions(+) create mode 100644 dbal/cpp/src/entities/workflow/create_workflow.hpp create mode 100644 dbal/cpp/src/entities/workflow/delete_workflow.hpp create mode 100644 dbal/cpp/src/entities/workflow/get_workflow.hpp create mode 100644 dbal/cpp/src/entities/workflow/index.hpp create mode 100644 dbal/cpp/src/entities/workflow/list_workflows.hpp create mode 100644 dbal/cpp/src/entities/workflow/update_workflow.hpp create mode 100644 packages/codegen_studio/static_content/cli/main.cpp diff --git a/dbal/cpp/src/entities/workflow/create_workflow.hpp b/dbal/cpp/src/entities/workflow/create_workflow.hpp new file mode 100644 index 000000000..6fb69988c --- /dev/null +++ b/dbal/cpp/src/entities/workflow/create_workflow.hpp @@ -0,0 +1,50 @@ +/** + * @file create_workflow.hpp + * @brief Create workflow operation + */ +#ifndef DBAL_CREATE_WORKFLOW_HPP +#define DBAL_CREATE_WORKFLOW_HPP + +#include "dbal/types.hpp" +#include "dbal/errors.hpp" +#include "../../store/in_memory_store.hpp" +#include "../../validation/workflow_validation.hpp" + +namespace dbal { +namespace entities { +namespace workflow { + +/** + * Create a new workflow in the store + */ +inline Result create(InMemoryStore& store, const CreateWorkflowInput& input) { + if (input.name.empty() || input.name.length() > 100) { + return Error::validationError("Name must be between 1 and 100 characters"); + } + if (input.type.empty()) { + return Error::validationError("Workflow type is required"); + } + if (!validation::isValidWorkflowType(input.type)) { + return Error::validationError("Invalid workflow type"); + } + + Workflow workflow; + workflow.id = store.generateId("workflow", ++store.workflow_counter); + workflow.name = input.name; + workflow.description = input.description; + workflow.type = input.type; + workflow.config = input.config; + workflow.is_active = input.is_active; + workflow.created_at = std::chrono::system_clock::now(); + workflow.updated_at = workflow.created_at; + + store.workflows[workflow.id] = workflow; + + return Result(workflow); +} + +} // namespace workflow +} // namespace entities +} // namespace dbal + +#endif diff --git a/dbal/cpp/src/entities/workflow/delete_workflow.hpp b/dbal/cpp/src/entities/workflow/delete_workflow.hpp new file mode 100644 index 000000000..7dfbcb3cf --- /dev/null +++ b/dbal/cpp/src/entities/workflow/delete_workflow.hpp @@ -0,0 +1,38 @@ +/** + * @file delete_workflow.hpp + * @brief Delete workflow operation + */ +#ifndef DBAL_DELETE_WORKFLOW_HPP +#define DBAL_DELETE_WORKFLOW_HPP + +#include "dbal/types.hpp" +#include "dbal/errors.hpp" +#include "../../store/in_memory_store.hpp" + +namespace dbal { +namespace entities { +namespace workflow { + +/** + * Delete a workflow by ID + */ +inline Result remove(InMemoryStore& store, const std::string& id) { + if (id.empty()) { + return Error::validationError("Workflow ID cannot be empty"); + } + + auto it = store.workflows.find(id); + if (it == store.workflows.end()) { + return Error::notFound("Workflow not found: " + id); + } + + store.workflows.erase(it); + + return Result(true); +} + +} // namespace workflow +} // namespace entities +} // namespace dbal + +#endif diff --git a/dbal/cpp/src/entities/workflow/get_workflow.hpp b/dbal/cpp/src/entities/workflow/get_workflow.hpp new file mode 100644 index 000000000..c2c5a925c --- /dev/null +++ b/dbal/cpp/src/entities/workflow/get_workflow.hpp @@ -0,0 +1,36 @@ +/** + * @file get_workflow.hpp + * @brief Get workflow by ID operation + */ +#ifndef DBAL_GET_WORKFLOW_HPP +#define DBAL_GET_WORKFLOW_HPP + +#include "dbal/types.hpp" +#include "dbal/errors.hpp" +#include "../../store/in_memory_store.hpp" + +namespace dbal { +namespace entities { +namespace workflow { + +/** + * Get a workflow by ID + */ +inline Result get(InMemoryStore& store, const std::string& id) { + if (id.empty()) { + return Error::validationError("Workflow ID cannot be empty"); + } + + auto it = store.workflows.find(id); + if (it == store.workflows.end()) { + return Error::notFound("Workflow not found: " + id); + } + + return Result(it->second); +} + +} // namespace workflow +} // namespace entities +} // namespace dbal + +#endif diff --git a/dbal/cpp/src/entities/workflow/index.hpp b/dbal/cpp/src/entities/workflow/index.hpp new file mode 100644 index 000000000..b0f050bc4 --- /dev/null +++ b/dbal/cpp/src/entities/workflow/index.hpp @@ -0,0 +1,14 @@ +/** + * @file index.hpp + * @brief Barrel include for workflow operations + */ +#ifndef DBAL_WORKFLOW_INDEX_HPP +#define DBAL_WORKFLOW_INDEX_HPP + +#include "create_workflow.hpp" +#include "get_workflow.hpp" +#include "update_workflow.hpp" +#include "delete_workflow.hpp" +#include "list_workflows.hpp" + +#endif diff --git a/dbal/cpp/src/entities/workflow/list_workflows.hpp b/dbal/cpp/src/entities/workflow/list_workflows.hpp new file mode 100644 index 000000000..ae629be8d --- /dev/null +++ b/dbal/cpp/src/entities/workflow/list_workflows.hpp @@ -0,0 +1,62 @@ +/** + * @file list_workflows.hpp + * @brief List workflows with filtering and pagination + */ +#ifndef DBAL_LIST_WORKFLOWS_HPP +#define DBAL_LIST_WORKFLOWS_HPP + +#include "dbal/types.hpp" +#include "dbal/errors.hpp" +#include "../../store/in_memory_store.hpp" +#include + +namespace dbal { +namespace entities { +namespace workflow { + +/** + * List workflows with filtering and pagination + */ +inline Result> list(InMemoryStore& store, const ListOptions& options) { + std::vector workflows; + + for (const auto& [id, workflow] : store.workflows) { + bool matches = true; + + if (options.filter.find("is_active") != options.filter.end()) { + bool filter_active = options.filter.at("is_active") == "true"; + if (workflow.is_active != filter_active) matches = false; + } + + if (options.filter.find("type") != options.filter.end()) { + if (workflow.type != options.filter.at("type")) matches = false; + } + + if (matches) workflows.push_back(workflow); + } + + if (options.sort.find("name") != options.sort.end()) { + std::sort(workflows.begin(), workflows.end(), [](const Workflow& a, const Workflow& b) { + return a.name < b.name; + }); + } else if (options.sort.find("created_at") != options.sort.end()) { + std::sort(workflows.begin(), workflows.end(), [](const Workflow& a, const Workflow& b) { + return a.created_at < b.created_at; + }); + } + + int start = (options.page - 1) * options.limit; + int end = std::min(start + options.limit, static_cast(workflows.size())); + + if (start < static_cast(workflows.size())) { + return Result>(std::vector(workflows.begin() + start, workflows.begin() + end)); + } + + return Result>(std::vector()); +} + +} // namespace workflow +} // namespace entities +} // namespace dbal + +#endif diff --git a/dbal/cpp/src/entities/workflow/update_workflow.hpp b/dbal/cpp/src/entities/workflow/update_workflow.hpp new file mode 100644 index 000000000..019e57200 --- /dev/null +++ b/dbal/cpp/src/entities/workflow/update_workflow.hpp @@ -0,0 +1,58 @@ +/** + * @file update_workflow.hpp + * @brief Update workflow operation + */ +#ifndef DBAL_UPDATE_WORKFLOW_HPP +#define DBAL_UPDATE_WORKFLOW_HPP + +#include "dbal/types.hpp" +#include "dbal/errors.hpp" +#include "../../store/in_memory_store.hpp" +#include "../../validation/workflow_validation.hpp" + +namespace dbal { +namespace entities { +namespace workflow { + +/** + * Update an existing workflow + */ +inline Result update(InMemoryStore& store, const std::string& id, const UpdateWorkflowInput& input) { + if (id.empty()) { + return Error::validationError("Workflow ID cannot be empty"); + } + + auto it = store.workflows.find(id); + if (it == store.workflows.end()) { + return Error::notFound("Workflow not found: " + id); + } + + Workflow& workflow = it->second; + + if (input.name.has_value()) { + if (input.name.value().empty() || input.name.value().length() > 100) { + return Error::validationError("Name must be between 1 and 100 characters"); + } + workflow.name = input.name.value(); + } + + if (input.type.has_value()) { + if (!validation::isValidWorkflowType(input.type.value())) { + return Error::validationError("Invalid workflow type"); + } + workflow.type = input.type.value(); + } + + if (input.description.has_value()) workflow.description = input.description.value(); + if (input.config.has_value()) workflow.config = input.config.value(); + if (input.is_active.has_value()) workflow.is_active = input.is_active.value(); + + workflow.updated_at = std::chrono::system_clock::now(); + return Result(workflow); +} + +} // namespace workflow +} // namespace entities +} // namespace dbal + +#endif diff --git a/packages/codegen_studio/static_content/cli/main.cpp b/packages/codegen_studio/static_content/cli/main.cpp new file mode 100644 index 000000000..ba4411496 --- /dev/null +++ b/packages/codegen_studio/static_content/cli/main.cpp @@ -0,0 +1,18 @@ +#include +#include + +int main(int argc, char** argv) { + std::string project = "starter-app"; + if (argc > 1 && argv[1] != nullptr) { + project = argv[1]; + } + + std::cout << "Codegen Studio CLI" << std::endl; + std::cout << "Project: " << project << std::endl; + std::cout << "Zip entries:" << std::endl; + std::cout << "- " << project << "/README.md" << std::endl; + std::cout << "- " << project << "/package.json" << std::endl; + std::cout << "- " << project << "/src/app/page.tsx" << std::endl; + + return 0; +}