#ifndef OATPP_AUTHKIT_REPO_CONCRETE_USER_REPOSITORY_HPP #define OATPP_AUTHKIT_REPO_CONCRETE_USER_REPOSITORY_HPP // Concrete inner adapter of `Repository` (authkit#14 PR 4). // Stacks under TemporalRepository via `makeUserRepository`. #include "oatpp-authkit/db/UserDb.hpp" #include "oatpp-authkit/dto/UserDto.hpp" #include "oatpp-authkit/repo/Repository.hpp" #include "oatpp-authkit/repo/SchemaContract.hpp" #include "oatpp-authkit/repo/TemporalRepository.hpp" #include "oatpp/core/Types.hpp" #include namespace oatpp_authkit::repo { /** * @brief Inner adapter of `Repository`, delegating to `db::UserDb`. * * Empty schema — `db::UserSchema` owns the table declaration. */ class ConcreteUserRepository : public Repository { public: inline static constexpr DecoratorSchema kSchema = { "ConcreteUserRepository", nullptr, 0, nullptr, 0, nullptr, 0, }; explicit ConcreteUserRepository(std::shared_ptr udb) : m_db(std::move(udb)) {} oatpp::Object findByEntityId(const oatpp::String& entityId) override { auto res = m_db->findUserByEntityId(entityId); if (!res || !res->isSuccess()) return nullptr; auto rows = res->template fetch>>(); if (!rows || rows->empty()) return nullptr; return (*rows)[0]; } oatpp::Vector> list() override { auto res = m_db->getAllUsersRaw(); auto out = oatpp::Vector>::createShared(); if (!res || !res->isSuccess()) return out; auto fetched = res->template fetch>>(); if (!fetched) return out; for (auto& row : *fetched) if (row) out->push_back(row); return out; } void save(const oatpp::Object& d) override { m_db->upsertUserById(d); } void softDelete(const oatpp::String& entityId) override { m_db->softDeleteUser(entityId); } private: std::shared_ptr m_db; }; inline std::shared_ptr> makeUserRepository(std::shared_ptr udb) { auto concrete = std::make_shared(std::move(udb)); return std::make_shared>(concrete); } } // namespace oatpp_authkit::repo #endif