extract api

This commit is contained in:
Bartosz Wieczorek 2018-02-28 07:40:39 +01:00
parent 99678def8a
commit ac05b84067
23 changed files with 162 additions and 88 deletions

View File

@ -10,9 +10,9 @@ target_link_libraries(eedb_app
PRIVATE wthttp # or {Wt_HTTP_DEBUG_LIBRARY}
PRIVATE wt # or {Wt_DEBUG_LIBRARY}
PRIVATE postgres_connector
PRIVATE eedb
PRIVATE auth
PRIVATE widgets
PRIVATE app
z
)

View File

@ -7,3 +7,5 @@ add_subdirectory(db)
add_subdirectory(auth)
add_subdirectory(widgets)
add_subdirectory(app)

View File

@ -0,0 +1,34 @@
set(LIB app)
file(GLOB_RECURSE app_SOURCE src/*)
# find packages
find_package(nlohmann_json CONFIG REQUIRED)
# create library
add_library(${LIB} ${app_SOURCE})
# link all
target_include_directories(${LIB}
PUBLIC include
)
target_link_libraries(${LIB}
PUBLIC eedb-api
PUBLIC auth
PUBLIC widgets
PUBLIC postgres_connector
PUBLIC Boost::system
PUBLIC Boost::filesystem
PUBLIC Boost::thread
PUBLIC Boost::program_options
PUBLIC stdc++fs
PUBLIC nlohmann_json
)
# add cotire
set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${LIB})
# add tests
#add_subdirectory(test)

View File

@ -0,0 +1,41 @@
# cotire.cmake 1.7.10 generated file
# /home/bwieczor/src/eedb/src/libs/app/app_CXX_cotire.cmake
set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS "inc;inl;ipp")
set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH "")
set (COTIRE_CLEAN_ALL_TARGET_NAME "clean_cotire")
set (COTIRE_CLEAN_TARGET_SUFFIX "_clean_cotire")
set (COTIRE_CMAKE_MODULE_FILE "/home/bwieczor/src/eedb/cmake/cotire.cmake")
set (COTIRE_CMAKE_MODULE_VERSION "1.7.10")
set (COTIRE_DEBUG "OFF")
set (COTIRE_INTDIR "cotire")
set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES "0")
set (COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES "3")
set (COTIRE_PCH_ALL_TARGET_NAME "all_pch")
set (COTIRE_PCH_TARGET_SUFFIX "_pch")
set (COTIRE_PREFIX_HEADER_FILENAME_SUFFIX "_prefix")
set (COTIRE_TARGETS_FOLDER "cotire")
set (COTIRE_TARGET_COMPILE_FLAGS_NONE "-std=gnu++1z")
set (COTIRE_TARGET_CONFIGURATION_TYPES "None")
set (COTIRE_TARGET_CXX_COMPILER_LAUNCHER "COTIRE_TARGET_CXX_COMPILER_LAUNCHER-NOTFOUND")
set (COTIRE_TARGET_IGNORE_PATH "/home/bwieczor/src/eedb")
set (COTIRE_TARGET_INCLUDE_DIRECTORIES_NONE "/home/bwieczor/src/eedb/external/include;/home/bwieczor/src/eedb/external/include/date;/home/bwieczor/src/eedb/share;/home/bwieczor/src/eedb/src/.;/home/bwieczor/src/eedb/src/libs/app/include;/home/bwieczor/src/eedb/src/libs/eedb/include;/home/bwieczor/src/eedb/src/libs/auth/include;/home/bwieczor/src/eedb/src/libs/widgets/include;/home/bwieczor/src/eedb/src/libs/db/postgresql_connector/include;/home/bwieczor/.hunter/_Base/a412c45/04ca7b3/85521ae/Install/include")
set (COTIRE_TARGET_INCLUDE_PRIORITY_PATH "")
set (COTIRE_TARGET_LANGUAGE "CXX")
set (COTIRE_TARGET_MAXIMUM_NUMBER_OF_INCLUDES "")
set (COTIRE_TARGET_POST_UNDEFS "")
set (COTIRE_TARGET_PRE_UNDEFS "")
set (COTIRE_TARGET_SOURCES "/home/bwieczor/src/eedb/src/libs/app/src/EEDB.cpp;/home/bwieczor/src/eedb/src/libs/app/src/WebSession.cpp;/home/bwieczor/src/eedb/src/libs/app/src/dummy.cpp")
set (COTIRE_UNITY_BUILD_ALL_TARGET_NAME "all_unity")
set (COTIRE_UNITY_BUILD_TARGET_SUFFIX "_unity")
set (COTIRE_UNITY_OUTPUT_DIRECTORY "")
set (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS "m;mm")
set (COTIRE_UNITY_SOURCE_FILENAME_SUFFIX "_unity")
set (CMAKE_GENERATOR "Unix Makefiles")
set (CMAKE_BUILD_TYPE "")
set (CMAKE_CXX_COMPILER_ID "GNU")
set (CMAKE_CXX_COMPILER_VERSION "5.4.1")
set (CMAKE_CXX_COMPILER "/usr/bin/c++")
set (CMAKE_CXX_COMPILER_ARG1 "")
set (CMAKE_INCLUDE_FLAG_CXX "-I")
set (CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
set (CMAKE_CXX_SOURCE_FILE_EXTENSIONS "C;M;c++;cc;cpp;cxx;mm;CPP")

View File

@ -17,7 +17,7 @@ target_include_directories( ${LIB}
target_link_libraries( ${LIB}
PRIVATE nlohmann_json
PRIVATE eedb
PRIVATE eedb-api
)
# add cotire

View File

@ -19,7 +19,10 @@ target_include_directories( ${LIB}
)
target_link_libraries( ${LIB}
PRIVATE eedb
PRIVATE eedb-api
PRIVATE Boost::filesystem
PRIVATE Boost::system
PUBLIC stdc++fs
PUBLIC sqlpp11-connector-postgresql
PUBLIC pq
)

View File

@ -13,6 +13,8 @@
#include <random>
#include <eedb/db/User.hpp>
namespace eedb::db {
class AuthTokenMock : public ::eedb::AuthTokenMock {
@ -30,7 +32,7 @@ class AuthTokenMock : public ::eedb::AuthTokenMock {
}
private:
uint64_t id;
int64_t id;
};
} // namespace eedb::db

View File

@ -17,31 +17,38 @@ namespace eedb::db {
class UserMock : public ::eedb::UserMock {
public:
/// TODO chenge to transaction
void _init(db::PgConnection & db) {
UserMock(db::PgConnection & db) : _db{db} {}
void _init() {
using namespace testing;
_id = db(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
_id = _db(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
.front()
.id;
ON_CALL(*this, uid()).WillByDefault(Return(_id));
}
void _createIdentity(db::PgConnection & db, const ::eedb::AuthIdentityConst & id) {
db(insert_into(t_auth_identity) //
.set(t_auth_identity.auth_info_id = _id,
t_auth_identity.provider = std::string{id.provider()},
t_auth_identity.identity = std::string{id.identity()}));
void _createIdentity(const ::eedb::AuthIdentityConst & id) {
_db(insert_into(t_auth_identity) //
.set(t_auth_identity.auth_info_id = _id,
t_auth_identity.provider = std::string{id.provider()},
t_auth_identity.identity = std::string{id.identity()}));
}
void _expect_call_uid() {
using namespace testing;
EXPECT_CALL(*this, uid()).WillRepeatedly(Return(_id));
}
private:
int64_t _id;
db::PgConnection & _db;
};
class PgUserMock : public UserMock {};

View File

@ -12,7 +12,7 @@ file(GLOB_RECURSE TEST_FILES test_*.cpp )
add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES})
target_link_libraries(${TEST_EXECUTABLE_NAME}
PRIVATE postgres_connector-mock
PRIVATE eedb
PRIVATE eedb-api
PRIVATE postgres_connector
PRIVATE GMock::main
)

View File

@ -8,12 +8,13 @@
class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > {
public:
PgAuthIdentitiesTest() {
PgAuthIdentitiesTest() : user{db()} {
using namespace testing;
db().native()->start_transaction();
user._init(db());
user._createIdentity(db(), {"identity", "provider"});
user._init();
user._createIdentity({"identity", "provider"});
user._expect_call_uid();
sut = std::make_unique< eedb::PgAuthIdentities >(db(), &user);
}

View File

@ -14,15 +14,16 @@
class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
public:
PgAuthTokenTest() {
PgAuthTokenTest() : user{db()} {
using namespace testing;
db().native()->start_transaction();
_user._init(db());
user._init();
user._expect_call_uid();
sutId = db()(sqlpp::postgresql::insert_into(t_auth_token) //
.set( //
t_auth_token.auth_info_id = _user.uid(), //
t_auth_token.auth_info_id = user.uid(), //
t_auth_token.expires = std::chrono::system_clock::now(), //
t_auth_token.role = static_cast< int >(eedb::AuthTokenRole::Auth), //
t_auth_token.value = "empty") //
@ -43,7 +44,7 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
}
protected:
eedb::db::UserMock _user;
eedb::db::UserMock user;
int64_t sutId;
std::unique_ptr< eedb::PgAuthToken > sut;

View File

@ -4,15 +4,16 @@
#include "DbTestBase.hpp"
#include <eedb/mock/db/pg/UserMock.hpp>
#include <eedb/mock/db/pg/AuthTokenMock.hpp>
#include <eedb/mock/db/pg/UserMock.hpp>
class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > {
public:
PgAuthTokensTest() {
PgAuthTokensTest() : user{db()} {
using namespace testing;
db().native()->start_transaction();
user._init(db());
user._init();
user._expect_call_uid();
sut = std::make_unique< eedb::PgAuthTokens >(db(), &user);
}

View File

@ -8,10 +8,11 @@
class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest > {
public:
PgCategoriesRepositoryTest() {
PgCategoriesRepositoryTest() : user{db()} {
db().native()->start_transaction();
_userMock._init(db());
sut = std::make_unique< eedb::PgCategoriesRepository >(db(), &_userMock);
user._init();
user._expect_call_uid();
sut = std::make_unique< eedb::PgCategoriesRepository >(db(), &user);
}
~PgCategoriesRepositoryTest() {
@ -19,7 +20,7 @@ class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest
}
protected:
eedb::db::UserMock _userMock;
eedb::db::UserMock user;
std::unique_ptr< eedb::PgCategoriesRepository > sut;
};
@ -29,9 +30,8 @@ std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesRepositoryTest
using namespace testing;
TEST_F(PgCategoriesRepositoryTest, rootNotNull) {
EXPECT_CALL(_userMock, uid()).WillOnce(Return(1));
auto root = sut->root();
ASSERT_TRUE(root);
// EXPECT_FALSE(root->detached());
// EXPECT_FALSE(root->detached());
EXPECT_FALSE(root->parent());
}

View File

@ -6,9 +6,10 @@
class PgCategoryTest : public DbTestBase< PgCategoryTest > {
public:
PgCategoryTest() {
PgCategoryTest() : user{db()} {
db().native()->start_transaction();
user._init(db());
user._init();
user._expect_call_uid();
sut = std::make_unique< eedb::PgCategory >(db(), &user);
}

View File

@ -1,33 +1,15 @@
set(LIB eedb)
file(GLOB_RECURSE eedb_SOURCE src/*)
set(LIB eedb-api)
# find packages
find_package(nlohmann_json CONFIG REQUIRED)
# create library
add_library(${LIB} ${eedb_SOURCE})
add_library(${LIB} INTERFACE)
# link all
target_include_directories(${LIB}
PUBLIC include
INTERFACE include
)
target_link_libraries(${LIB}
PUBLIC Boost::system
PUBLIC Boost::filesystem
PUBLIC Boost::thread
PUBLIC Boost::program_options
PUBLIC stdc++fs
PUBLIC nlohmann_json
PRIVATE auth
PRIVATE postgres_connector
PRIVATE widgets
)
# add cotire
set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${LIB})
# add tests
add_subdirectory(test)

View File

@ -14,7 +14,7 @@ target_include_directories(${LIB}
)
target_link_libraries(${LIB}
PUBLIC eedb
PUBLIC eedb-api
PUBLIC auth
)

View File

@ -19,7 +19,6 @@
#include <Wt/WHBoxLayout.h>
#include <Wt/WVBoxLayout.h>
#include <eedb/Session.hpp>
#include <widget/model/CategoriesModel.hpp>
#include <widget/NavigationBar.hpp>
@ -47,37 +46,37 @@ eedb::DefaultHomePage::DefaultHomePage(Session & session, std::unique_ptr< eedb:
DefaultHomePage::~DefaultHomePage() = default;
void DefaultHomePage::attachTo(Wt::WContainerWidget * container) {
auto stackedWidget = std::make_unique< Wt::WStackedWidget >();
// auto stackedWidget = std::make_unique< Wt::WStackedWidget >();
_navigationBar->attachTo(stackedWidget.get());
_navigationBar->registerLogoutAction([=]() { this->_session.login().logout(); });
// _navigationBar->attachTo(stackedWidget.get());
// _navigationBar->registerLogoutAction([=]() { this->_session.login().logout(); });
auto vbox = std::make_unique< Wt::WVBoxLayout >();
vbox->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
{
auto hbox = std::make_unique< Wt::WHBoxLayout >();
hbox->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
{
auto tree = make_tree();
_categoryTree = tree.get();
tree->clicked().connect([](Wt::WModelIndex, Wt::WMouseEvent) { Wt::log("notice") << "Item selection changed"; });
///TODO #7 collumn size based on the actual size of text
tree->setColumnWidth(0, 100.0);
hbox->addWidget(std::move(tree), 1);
}
// auto vbox = std::make_unique< Wt::WVBoxLayout >();
// vbox->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
// {
// auto hbox = std::make_unique< Wt::WHBoxLayout >();
// hbox->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
// {
// auto tree = make_tree();
// _categoryTree = tree.get();
// tree->clicked().connect([](Wt::WModelIndex, Wt::WMouseEvent) { Wt::log("notice") << "Item selection changed"; });
// ///TODO #7 collumn size based on the actual size of text
// tree->setColumnWidth(0, 100.0);
// hbox->addWidget(std::move(tree), 1);
// }
{
auto contents = std::make_unique< Wt::WStackedWidget >();
contents->setId("contents");
hbox->addWidget(std::move(contents), 2);
}
// {
// auto contents = std::make_unique< Wt::WStackedWidget >();
// contents->setId("contents");
// hbox->addWidget(std::move(contents), 2);
// }
hbox->setResizable(0, true);
// hbox->setResizable(0, true);
vbox->addWidget(std::move(stackedWidget), 0);
vbox->addLayout(std::move(hbox), 20);
}
// vbox->addWidget(std::move(stackedWidget), 0);
// vbox->addLayout(std::move(hbox), 20);
// }
container->setLayout(std::move(vbox));
// container->setLayout(std::move(vbox));
}
} // namespace eedb