9#ifndef MANTISBASE_ENTITY_H
10#define MANTISBASE_ENTITY_H
59 [[nodiscard]] std::string
id()
const;
65 [[nodiscard]] std::string
name()
const;
71 [[nodiscard]] std::string
type()
const;
83 [[nodiscard]]
bool hasApi()
const;
90 [[nodiscard]] std::string
viewQuery()
const;
96 [[nodiscard]]
const std::vector<json> &
fields()
const;
103 [[nodiscard]] std::optional<json>
field(
const std::string& field_name)
const;
110 [[nodiscard]] std::optional<json>
hasField(
const std::string& field_name)
const;
174 [[nodiscard]] std::optional<Record>
read(
const std::string &
id,
const json &opts = json::object())
const;
183 [[nodiscard]]
Record update(
const std::string &
id,
const json &data,
const json &opts = json::object())
const;
189 void remove(
const std::string &
id)
const;
208 [[nodiscard]]
bool isEmpty()
const;
216 [[nodiscard]]
bool recordExists(
const std::string &
id)
const;
223 [[nodiscard]] std::optional<json>
findField(
const std::string &field_name)
const;
231 [[nodiscard]] std::optional<json>
queryFromCols(
const std::string &value,
232 const std::vector<std::string> &columns)
const;
271 nlohmann::json m_schema;
Access rule definition for entity permissions.
Access control rule for entity permissions.
Definition access_rules.h:31
Represents a database table/entity with schema and CRUD operations.
Definition entity.h:39
const std::vector< json > & fields() const
Get all field definitions.
Definition entity.cpp:101
HandlerWithContentReaderFn postRouteHandler() const
Get route handler for POST /api/v1/entities/{table}.
Definition entity_routes_handlers.cpp:133
Record create(const json &record, const json &opts=json::object()) const
Create a new record in the entity table.
Definition entity.cpp:146
std::string viewQuery() const
Get SQL query for view type entities.
Definition entity.cpp:91
bool hasApi() const
Check if entity has API endpoints enabled.
Definition entity.cpp:87
int countRecords() const
Count total records in the entity table.
Definition entity.cpp:474
bool recordExists(const std::string &id) const
Check if a record exists by ID.
Definition entity.cpp:499
HandlerFn deleteRouteHandler() const
Get route handler for DELETE /api/v1/entities/{table}/:id.
Definition entity_routes_handlers.cpp:270
HandlerFn getManyRouteHandler() const
Get route handler for GET /api/v1/entities/{table}.
Definition entity_routes_handlers.cpp:59
Records list(const json &opts=json::object()) const
List all records in the entity table.
Definition entity.cpp:222
HandlerFn getOneRouteHandler() const
Get route handler for GET /api/v1/entities/{table}/:id.
Definition entity_routes_handlers.cpp:7
Record update(const std::string &id, const json &data, const json &opts=json::object()) const
Update an existing record by ID.
Definition entity.cpp:283
std::string type() const
Get entity type ("base", "auth", or "view").
Definition entity.cpp:79
HandlerWithContentReaderFn patchRouteHandler() const
Get route handler for PATCH /api/v1/entities/{table}/:id.
Definition entity_routes_handlers.cpp:202
bool isSystem() const
Check if entity is a system table.
Definition entity.cpp:83
AccessRule updateRule() const
Get update access rule (for PATCH /api/v1/entities/{table}/:id).
Definition entity.cpp:134
const json & schema() const
Get complete entity schema JSON.
Definition entity.cpp:472
void createEntityRoutes() const
Register all CRUD routes for this entity with the router.
Definition entity_routes_handlers.cpp:305
AccessRule addRule() const
Get create access rule (for POST /api/v1/entities/{table}).
Definition entity.cpp:130
std::optional< json > field(const std::string &field_name) const
Get field definition by name.
Definition entity.cpp:105
const json & rules() const
Get all access rules.
Definition entity.cpp:118
AccessRule getRule() const
Get read access rule (for GET /api/v1/entities/{table}/:id).
Definition entity.cpp:126
std::optional< Record > read(const std::string &id, const json &opts=json::object()) const
Read a single record by ID.
Definition entity.cpp:258
std::optional< json > findField(const std::string &field_name) const
Find field definition by name (alias for field()).
Definition entity.cpp:512
AccessRule deleteRule() const
Get delete access rule (for DELETE /api/v1/entities/{table}/:id).
Definition entity.cpp:138
std::optional< json > queryFromCols(const std::string &value, const std::vector< std::string > &columns) const
Query records by searching across multiple columns.
Definition entity.cpp:522
std::string id() const
Get entity unique identifier.
Definition entity.cpp:71
std::optional< json > hasField(const std::string &field_name) const
Check if field exists by name.
Definition entity.cpp:114
bool isEmpty() const
Check if entity table is empty.
Definition entity.cpp:486
std::string name() const
Get entity table name.
Definition entity.cpp:75
AccessRule listRule() const
Get list access rule (for GET /api/v1/entities/{table}).
Definition entity.cpp:122
void remove(const std::string &id) const
Delete a record by ID.
Definition entity.cpp:426
Custom exception class for MantisBase errors.
Convenience header that includes all MantisBase public API headers.
router.h
Definition auth.h:15
std::vector< Record > Records
Collection of database records.
Definition entity.h:21
nlohmann::json Record
Single database record as JSON object.
Definition entity.h:20
std::function< void(MantisRequest &, MantisResponse &, MantisContentReader &)> HandlerWithContentReaderFn
Route Handler function with content reader shorthand
Definition types.h:40
std::function< void(MantisRequest &, MantisResponse &)> HandlerFn
Route Handler function shorthand
Definition types.h:36
nlohmann::json json
Shorten JSON namespace.
Definition context_store.h:18
SOCI database wrapper utilities.