24 #include "core/credentials/Credential_odb.h" 50 std::vector<CRUDResourceHandler::ActionActionParam>
52 const json &req)
const 54 std::vector<CRUDResourceHandler::ActionActionParam> ret;
60 catch (json::out_of_range &e)
86 odb::transaction t(db->begin());
89 std::string type = req.at(
"credential-type");
90 if (type ==
"rfid-card")
92 new_cred = std::make_shared<Cred::RFIDCard>();
94 else if (type ==
"pin-code")
96 new_cred = std::make_shared<Cred::PinCode>();
101 BUILD_STR(
"Credential {" << type <<
"} are not supported."));
106 db->persist(assert_cast<Cred::CredentialPtr>(new_cred));
125 using Result = odb::result<Cred::Credential>;
127 odb::transaction t(db->begin());
140 rep[
"data"] = json::array();
141 for (
const auto &cred : result)
162 odb::transaction t(db->begin());
174 db->update(assert_cast<Cred::CredentialPtr>(cred));
187 odb::transaction t(db->begin());
virtual boost::optional< json > read_impl(const json &req) override
virtual boost::optional< json > update_impl(const json &req) override
An ODB enabled credential object.
This is the header file for a generated source file, GitSHA1.cpp.
static SecurityContext & instance()
Cred::CredentialId credential_id
virtual UserSecurityContext & security_context() const override
Helper function that returns the security context.
Audit::IAuditEntryPtr audit
The initial audit trail for the request.
static ICredentialEventPtr CredentialEventPtr(const DBPtr &database, Cred::ICredentialPtr target_cred, IAuditEntryPtr parent)
std::unique_ptr< CRUDResourceHandler > CRUDResourceHandlerUPtr
virtual boost::optional< json > create_impl(const json &req) override
Create a new credential.
std::shared_ptr< ICredential > ICredentialPtr
static json serialize(const Cred::ICredential &in, const SecurityContext &sc)
static std::string serialize(const Cred::ICredential &in, const SecurityContext &sc)
Exception class for LEOSAC Project related errors.
static void unserialize(Cred::ICredential &out, const json &in, const SecurityContext &sc)
std::shared_ptr< ICredentialEvent > ICredentialEventPtr
All modules that provides features to Leosac shall be in this namespace.
static CRUDResourceHandlerUPtr instanciate(RequestContext)
virtual boost::optional< json > delete_impl(const json &req) override
Base CRUD handler for use within the websocket module.
unsigned long CredentialId
CredentialCRUD(RequestContext ctx)
#define BUILD_STR(param)
Internal macro.
A base class for Leosac specific exception.
virtual std::vector< ActionActionParam > required_permission(Verb verb, const json &req) const override
odb::result< Tools::LogEntry > Result
Holds valuable pointer to provide context to a request.
std::shared_ptr< odb::database > DBPtr