added some more entities for work demo

This commit is contained in:
Sascha Kühl 2025-06-26 16:03:13 +02:00
parent 4dcbf009da
commit 9f718b7e36
15 changed files with 258 additions and 4 deletions

View File

@ -10,6 +10,12 @@
#include "work/admin/UserDirectory.hpp"
#include "work/admin/UserSession.hpp"
#include "work/jobs/Job.hpp"
#include "work/jobs/Task.hpp""
#include "work/jobs/Payload.hpp"
#include "work/jobs/IdPayload.hpp"
#include "work/jobs/IdListPayload.hpp"
#include "matador/object/schema.hpp"
#include "matador/sql/connection.hpp"
@ -20,7 +26,7 @@ using namespace matador;
using namespace work::models;
int main() {
object::schema schema;
object::schema schema("Administration");
auto result = schema.attach<admin::CollectionCenter>("collection_center")
.and_then([&schema] { return schema.attach<admin::InternalUserDirectory>("internal_user_directory"); })
@ -32,7 +38,12 @@ int main() {
.and_then([&schema] { return schema.attach<admin::Scenario>("scenario"); })
.and_then([&schema] { return schema.attach<admin::User>("user"); })
.and_then([&schema] { return schema.attach<admin::UserDirectory>("user_directory"); })
.and_then([&schema] { return schema.attach<admin::UserSession>("user_session"); });
.and_then([&schema] { return schema.attach<admin::UserSession>("user_session"); })
.and_then([&schema] { return schema.attach<jobs::Job>("jobs"); })
.and_then([&schema] { return schema.attach<jobs::Payload>("id_payloads"); })
.and_then([&schema] { return schema.attach<jobs::IdPayload>("id_list_payloads"); })
.and_then([&schema] { return schema.attach<jobs::IdListPayload>("payloads"); })
.and_then([&schema] { return schema.attach<jobs::Task>("tasks"); });
if (!result.is_ok()) {
return 0;
@ -51,3 +62,8 @@ int main() {
return 0;
}
// registering table 'collection_center' (pk field: 'id')
// registering relation table 'collection_center_users' (first fk field: 'collection_center_id', second fk field: 'user_id')
// registering table 'internal_user_directory' (pk field: 'id')
//

View File

@ -38,7 +38,7 @@ struct CollectionCenter : core::Model {
field::attribute( op, "name", name, 511 );
field::attribute( op, "symbol", symbol );
field::attribute( op, "type", type );
field::has_many( op, "users", users, "collection_center_id", matador::utils::fetch_type::LAZY );
field::has_many( op, "collection_center_users", users, "collection_center_id", matador::utils::fetch_type::LAZY );
}
};

View File

@ -0,0 +1,22 @@
#ifndef USERINFO_HPP
#define USERINFO_HPP
#include "matador/utils/access.hpp"
namespace work::core {
struct UserInfo {
unsigned long long user_session_id;
std::string user_role;
std::string database_name;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::attribute( op, "user_session_id", user_session_id );
field::attribute( op, "user_role", user_role, 255 );
field::attribute( op, "database_name", database_name, 255 );
}
};
}
#endif //USERINFO_HPP

View File

@ -0,0 +1,20 @@
#ifndef ID_LIST_PAYLOAD_HPP
#define ID_LIST_PAYLOAD_HPP
#include "Payload.hpp"
#include "matador/object/collection.hpp"
namespace work::models::jobs {
struct IdListPayload : Payload {
matador::object::collection<unsigned long long> ids;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::process( op, *matador::base_class<Payload>( this ) );
field::has_many( op, "payload_ids", ids );
}
};
}
#endif //ID_LIST_PAYLOAD_HPP

View File

@ -0,0 +1,18 @@
#ifndef ID_PAYLOAD_HPP
#define ID_PAYLOAD_HPP
#include "Payload.hpp"
namespace work::models::jobs {
struct IdPayload : Payload {
unsigned long long id;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::process( op, *matador::base_class<Payload>( this ) );
field::attribute( op, "id", id );
}
};
}
#endif //ID_PAYLOAD_HPP

46
demo/work/jobs/Job.hpp Normal file
View File

@ -0,0 +1,46 @@
#ifndef JOB_HPP
#define JOB_HPP
#include "JobMode.hpp"
#include "JobState.hpp"
#include "Payload.hpp"
#include "Task.hpp"
#include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "../core/UserInfo.hpp"
#include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp"
namespace work::models::jobs {
struct Job : core::Model {
std::string name;
std::string description;
JobState state;
JobMode mode;
core::timestamp created_at;
matador::object::object_ptr<Payload> payload;
matador::object::object_ptr<Task> task;
core::UserInfo user_info;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) );
field::attribute( op, "name", name, 511 );
field::attribute( op, "description", description, 511 );
field::attribute( op, "state", state );
field::attribute( op, "mode", mode );
field::attribute( op, "created_at", created_at );
field::belongs_to( op, "payload", payload, matador::utils::default_foreign_attributes );
field::belongs_to( op, "task", task, matador::utils::default_foreign_attributes );
field::attribute( op, "user_info", user_info );
}
};
}
#endif //JOB_HPP

View File

@ -0,0 +1,20 @@
#ifndef JOB_MODE_HPP
#define JOB_MODE_HPP
#include "matador/utils/enum_mapper.hpp"
#include <cstdint>
namespace work::models::jobs {
enum class JobMode : uint8_t {
Background,
Foreground
};
static const matador::utils::enum_mapper<JobMode> JobModeEnum({
{JobMode::Background, "Background"},
{JobMode::Foreground, "Foreground"}
});
}
#endif //JOB_MODE_HPP

View File

@ -0,0 +1,28 @@
#ifndef JOB_STATE_HPP
#define JOB_STATE_HPP
#include "matador/utils/enum_mapper.hpp"
#include <cstdint>
namespace work::models::jobs {
enum class JobState : uint8_t {
Pending,
Running,
Succeeded,
Failed,
Cancelled
};
static const matador::utils::enum_mapper<JobState> JobStateEnum({
{JobState::Pending, "Pending"},
{JobState::Running, "Running"},
{JobState::Succeeded, "Succeeded"},
{JobState::Failed, "Failed"},
{JobState::Cancelled, "Cancelled"}
});
}
#endif //JOB_STATE_HPP

View File

@ -0,0 +1,20 @@
#ifndef PAYLOAD_HPP
#define PAYLOAD_HPP
#include "../core/Model.hpp"
#include "matador/utils/base_class.hpp"
namespace work::models::jobs {
struct Payload : core::Model {
std::string type;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) );
field::attribute( op, "type", type, 255 );
}
};
}
#endif //PAYLOAD_HPP

42
demo/work/jobs/Task.hpp Normal file
View File

@ -0,0 +1,42 @@
#ifndef TASK_HPP
#define TASK_HPP
#include "TaskState.hpp"
#include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp"
namespace work::models::jobs {
struct Task : core::Model {
std::string name;
std::string description;
std::string job_name;
TaskState state;
matador::object::object_ptr<Payload> payload;
JobMode job_mode;
core::timestamp start_delay;
core::timestamp interval;
unsigned long long user_session_id;
template<typename Operator>
void process( Operator& op ) {
namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) );
field::attribute( op, "name", name, 511 );
field::attribute( op, "description", description, 511 );
field::attribute( op, "job_name", job_name, 511 );
field::attribute( op, "state", state );
field::belongs_to( op, "payload", payload, matador::utils::default_foreign_attributes );
field::attribute( op, "job_mode", job_mode );
field::attribute( op, "start_delay", start_delay );
field::attribute( op, "interval", interval );
field::attribute( op, "user_session_id", user_session_id );
}
};
}
#endif //TASK_HPP

View File

@ -0,0 +1,22 @@
#ifndef TASK_STATE_HPP
#define TASK_STATE_HPP
#include "matador/utils/enum_mapper.hpp"
#include <cstdint>
namespace work::models::jobs {
enum class TaskState : uint8_t {
Active,
Inactive
};
static const matador::utils::enum_mapper<TaskState> TaskStateEnum({
{TaskState::Active, "Active"},
{TaskState::Inactive, "Inactive"}
});
}
#endif //TASK_STATE_HPP

View File

@ -1,7 +1,7 @@
#ifndef SCHEMA_HPP
#define SCHEMA_HPP
#include "primary_key_resolver.hpp"
#include "matador/object/primary_key_resolver.hpp"
#include "matador/object/error_code.hpp"
#include "matador/object/schema_node.hpp"
#include "matador/object/schema_node_iterator.hpp"

View File

View File

View File