remove most of the uid calls from application
This commit is contained in:
parent
d2229ca498
commit
c8dcb41f1b
@ -73,7 +73,7 @@ int main(int argc, char ** argv) {
|
||||
|
||||
// categories factory
|
||||
[db = dbIt->get()](eedb::User * owner) { //
|
||||
return std::make_unique< eedb::PgCategoriesRepository >(*db, owner);
|
||||
return std::make_unique< eedb::PgCategoriesRepository >(*db);
|
||||
},
|
||||
|
||||
env);
|
||||
|
||||
@ -17,7 +17,7 @@ class PgCategoriesRepository : public CategoriesRepository {
|
||||
public:
|
||||
// CategoriesRepository interface
|
||||
public:
|
||||
PgCategoriesRepository(db::PgConnection & db, User * owner);
|
||||
PgCategoriesRepository(db::PgConnection & db);
|
||||
|
||||
std::unique_ptr< Category > root() const override;
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ class PgCategory : public Category {
|
||||
spimpl::impl_ptr< PgCategoryPrivate > _priv;
|
||||
|
||||
public:
|
||||
PgCategory(db::PgConnection & db, User * user);
|
||||
PgCategory(db::PgConnection & db);
|
||||
PgCategory(spimpl::impl_ptr<PgCategoryPrivate> priv);
|
||||
|
||||
string_view displayName() const override;
|
||||
|
||||
@ -7,19 +7,17 @@
|
||||
|
||||
namespace eedb {
|
||||
struct PgCategoriesRepository::PgCategoriesRepositoryPriv {
|
||||
PgCategoriesRepositoryPriv(db::PgConnection & db, User * owner) : _db{db}, _user{owner} {}
|
||||
PgCategoriesRepositoryPriv(db::PgConnection & db) : _db{db} {}
|
||||
|
||||
auto root() const {
|
||||
return std::make_unique< eedb::PgCategory >(_db, _user);
|
||||
return std::make_unique< eedb::PgCategory >(_db);
|
||||
}
|
||||
|
||||
private:
|
||||
db::PgConnection & _db;
|
||||
User * _user;
|
||||
};
|
||||
|
||||
PgCategoriesRepository::PgCategoriesRepository(db::PgConnection & db, User * owner)
|
||||
: _priv{spimpl::make_unique_impl< PgCategoriesRepositoryPriv >(db, owner)} {}
|
||||
PgCategoriesRepository::PgCategoriesRepository(db::PgConnection & db) : _priv{spimpl::make_unique_impl< PgCategoriesRepositoryPriv >(db)} {}
|
||||
|
||||
std::unique_ptr< Category > PgCategoriesRepository::root() const { //
|
||||
return _priv->root();
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <eedb/db/pg/Stats.hpp>
|
||||
|
||||
namespace eedb {
|
||||
|
||||
struct PgCategory::PgCategoryPrivate {
|
||||
@ -51,13 +53,13 @@ struct PgCategory::PgCategoryPrivate {
|
||||
public:
|
||||
Category * _self{nullptr};
|
||||
|
||||
PgCategoryPrivate(db::PgConnection & db, User * owner, Category * parent) : _db{db}, _owner{owner}, _parent{parent} {
|
||||
PgCategoryPrivate(db::PgConnection & db, Category * parent) : _db{db}, _parent{parent} {
|
||||
auto row = _db(select(columns()).from(table_list()).where(root_path_match()).limit(0ul));
|
||||
if(row.empty()) {
|
||||
// no root category
|
||||
row = _db(sqlpp::postgresql::insert_into(t_category)
|
||||
.set( //
|
||||
t_category.owner = _owner->uid(),
|
||||
t_category.owner = sqlpp::verbatim< sqlpp::integer >("app_current_user_id()"),
|
||||
t_category.status = 0,
|
||||
t_category.parent_id = sqlpp::null,
|
||||
t_category.name = "root",
|
||||
@ -72,7 +74,7 @@ struct PgCategory::PgCategoryPrivate {
|
||||
auto children = std::make_unique< std::vector< std::unique_ptr< Category > > >();
|
||||
children->reserve(100);
|
||||
for(auto & category_row : _db(select(columns()).from(table_list()).where(parent_match()))) {
|
||||
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _owner, _self);
|
||||
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _self);
|
||||
priv->init_data(category_row);
|
||||
children->emplace_back(std::make_unique< PgCategory >(std::move(priv)));
|
||||
}
|
||||
@ -85,7 +87,7 @@ struct PgCategory::PgCategoryPrivate {
|
||||
|
||||
auto create(std::string name, std::string description) const {
|
||||
const auto & row = _db(sqlpp::postgresql::insert_into(t_category)
|
||||
.set(t_category.owner = _owner->uid(),
|
||||
.set(t_category.owner = sqlpp::verbatim< sqlpp::integer >("app_current_user_id()"),
|
||||
t_category.status = 0,
|
||||
t_category.parent_id = _uid,
|
||||
t_category.name = name,
|
||||
@ -93,7 +95,7 @@ struct PgCategory::PgCategoryPrivate {
|
||||
.returning(columns()))
|
||||
.front();
|
||||
|
||||
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _owner, _self);
|
||||
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _self);
|
||||
priv->init_data(row);
|
||||
return std::make_unique< PgCategory >(std::move(priv));
|
||||
}
|
||||
@ -117,7 +119,6 @@ struct PgCategory::PgCategoryPrivate {
|
||||
|
||||
private:
|
||||
db::PgConnection & _db;
|
||||
User * _owner;
|
||||
|
||||
int64_t _uid{};
|
||||
Category * _parent{nullptr};
|
||||
@ -126,7 +127,7 @@ struct PgCategory::PgCategoryPrivate {
|
||||
std::string _description;
|
||||
};
|
||||
|
||||
PgCategory::PgCategory(db::PgConnection & db, User * user) : _priv{spimpl::make_impl< PgCategoryPrivate >(db, user, nullptr)} {
|
||||
PgCategory::PgCategory(db::PgConnection & db) : _priv{spimpl::make_impl< PgCategoryPrivate >(db, nullptr)} {
|
||||
_priv->_self = this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,8 +10,7 @@ class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest
|
||||
public:
|
||||
PgCategoriesRepositoryTest() : user{db()} {
|
||||
user._init();
|
||||
user._expect_call_uid();
|
||||
sut = std::make_unique< eedb::PgCategoriesRepository >(db(), &user);
|
||||
sut = std::make_unique< eedb::PgCategoriesRepository >(db());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@ -8,8 +8,7 @@ class PgCategoryTest : public DbTestBase< PgCategoryTest > {
|
||||
public:
|
||||
PgCategoryTest() : user{db()} {
|
||||
user._init();
|
||||
user._expect_call_uid();
|
||||
sut = std::make_unique< eedb::PgCategory >(db(), &user);
|
||||
sut = std::make_unique< eedb::PgCategory >(db());
|
||||
}
|
||||
|
||||
auto insertCategory(std::string name, int64_t parentId) {
|
||||
|
||||
@ -16,7 +16,7 @@ class PgItemsRepositoryTest : public DbTestBase< PgItemsRepositoryTest > {
|
||||
public:
|
||||
PgItemsRepositoryTest() : user{db()}, category{db()}, numericParameter{db()}, textParameter{db()}, listParameter{db()} {
|
||||
using namespace testing;
|
||||
user._init(); // create fake user
|
||||
user._init();
|
||||
category._init_simple("main");
|
||||
numericParameter._init("numeric");
|
||||
textParameter._init("text");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user