From 4770ccc681634e0fdd4681f63162a4f4a165fd53 Mon Sep 17 00:00:00 2001 From: Bartosz Wieczorek Date: Mon, 26 Feb 2018 14:03:13 +0100 Subject: [PATCH] replace some files --- CMakeLists.txt | 2 +- sql/schema.sql | 160 ++++++++---------- src/CMakeLists.txt | 2 +- src/app/CMakeLists.txt | 32 ++-- src/eedb/CMakeLists.txt | 24 --- src/eedb/db/CMakeLists.txt | 28 --- src/eedb/db/model/all.hpp | 17 -- src/libs/CMakeLists.txt | 7 + src/libs/auth/CMakeLists.txt | 18 ++ .../auth/include}/eedb/auth/PgUserAuth.hpp | 0 .../auth/include}/eedb/auth/Services.hpp | 0 .../auth => libs/auth/src}/PgUserAuth.cpp | 2 +- src/{eedb/auth => libs/auth/src}/Services.cpp | 0 src/libs/db/CMakeLists.txt | 1 + .../db/postgresql_connector/CMakeLists.txt | 24 +++ .../postgresql_connector/include}/RawSql.hpp | 0 .../postgresql_connector/include}/config.hpp | 0 .../include}/connection.hpp | 2 +- .../include}/data/PgAuthIdentity.hpp | 0 .../include}/data/PgAuthToken.hpp | 0 .../include}/data/PgCategories.hpp | 0 .../include}/data/PgCategoriesRepository.hpp | 0 .../include}/data/PgCategory.hpp | 5 +- .../include/data/PgItem.hpp} | 0 .../include/data/PgItems.hpp | 0 .../include}/data/PgUser.hpp | 0 .../include}/data/PgUsers.hpp | 0 .../include}/data/Stats.hpp | 0 .../include/model/all.hpp | 17 ++ .../include}/model/auth_identity.h | 0 .../include}/model/auth_info.h | 0 .../include}/model/auth_token.h | 0 .../include}/model/category.h | 0 .../include}/model/group.h | 0 .../include}/model/stat.h | 0 .../include}/model/system_info.h | 0 .../include}/model/user_audit.h | 0 .../include}/model/user_audit_action.h | 0 .../db/postgresql_connector/src}/RawSql.cpp | 4 +- .../db/postgresql_connector/src}/config.cpp | 2 +- .../postgresql_connector/src}/connection.cpp | 4 +- .../src}/data/PgAuthIdentity.cpp | 6 +- .../src/data/PgAuthIdentity.hpp | 46 +++++ .../src}/data/PgAuthToken.cpp | 6 +- .../src/data/PgAuthToken.hpp | 52 ++++++ .../src}/data/PgCategories.cpp | 8 +- .../src/data/PgCategories.hpp | 28 +++ .../src}/data/PgCategoriesRepository.cpp | 8 +- .../src/data/PgCategoriesRepository.hpp | 28 +++ .../src}/data/PgCategory.cpp | 48 +++--- .../src/data/PgCategory.hpp | 37 ++++ .../postgresql_connector/src/data/PgItem.cpp | 0 .../postgresql_connector/src/data/PgItem.hpp | 0 .../postgresql_connector/src/data/PgItems.cpp | 0 .../postgresql_connector/src/data/PgItems.hpp | 0 .../postgresql_connector/src}/data/PgUser.cpp | 10 +- .../postgresql_connector/src/data/PgUser.hpp | 37 ++++ .../src}/data/PgUsers.cpp | 12 +- .../postgresql_connector/src/data/PgUsers.hpp | 31 ++++ .../postgresql_connector/src/data/Stats.hpp | 7 + .../postgresql_connector/test/CMakeLists.txt | 15 ++ .../postgresql_connector/test}/DbTestBase.hpp | 8 +- .../test/sql/categories_tree_test.sql | 0 .../test/sql/sql_data_base.sql | 0 .../test/test_eedb_data_PgAuthIdentities.cpp | 93 ++++++++++ .../test/test_eedb_data_PgAuthIdentity.cpp | 40 +++++ .../test/test_eedb_data_PgAuthToken.cpp | 82 +++++++++ .../test/test_eedb_data_PgAuthTokens.cpp | 105 ++++++++++++ .../test/test_eedb_data_PgCategories.cpp | 22 +++ .../test_eedb_data_PgCategoriesRepository.cpp | 30 ++++ .../test/test_eedb_data_PgCategory.cpp | 75 ++++++++ .../test/test_eedb_data_PgUser.cpp | 70 ++++++++ .../test/test_eedb_data_PgUsers.cpp | 132 +++++++++++++++ src/libs/eedb/CMakeLists.txt | 7 + src/{ => libs/eedb/include}/eedb/EEDB.hpp | 0 src/{ => libs/eedb/include}/eedb/Session.hpp | 0 .../eedb/include}/eedb/WebSession.hpp | 0 .../include}/eedb/data/AuthIdentities.hpp | 0 .../eedb/data/AuthIdentitiesConst.hpp | 0 .../eedb/include}/eedb/data/AuthIdentity.hpp | 0 .../include}/eedb/data/AuthIdentityConst.hpp | 0 .../eedb/include}/eedb/data/AuthInfo.hpp | 0 .../eedb/include}/eedb/data/AuthInfoConst.hpp | 0 .../eedb/include}/eedb/data/AuthToken.hpp | 0 .../include}/eedb/data/AuthTokenConst.hpp | 0 .../eedb/include}/eedb/data/AuthTokens.hpp | 0 .../eedb/include}/eedb/data/Category.hpp | 12 +- .../eedb/include}/eedb/data/Email.hpp | 0 src/libs/eedb/include/eedb/data/Item.hpp | 85 ++++++++++ .../eedb/include}/eedb/data/Password.hpp | 0 .../eedb/include}/eedb/data/StatInfo.hpp | 0 src/libs/eedb/include/eedb/data/Unit.hpp | 18 ++ .../eedb/include}/eedb/data/User.hpp | 0 .../eedb/include}/eedb/data/Users.hpp | 0 src/libs/eedb/include/eedb/data/Value.hpp | 16 ++ src/{eedb => libs/eedb/src}/EEDB.cpp | 0 src/{eedb => libs/eedb/src}/WebSession.cpp | 0 src/libs/eedb/src/dummy.cpp | 0 src/libs/widgets/CMakeLists.txt | 18 ++ .../widgets/include/widget}/AuthPage.hpp | 0 .../include/widget}/BootstrapTheme.hpp | 2 +- .../widgets/include/widget}/CategoryThree.hpp | 0 .../include/widget}/DefaultAuthPage.hpp | 2 +- .../include/widget}/DefaultCategoryTree.hpp | 2 +- .../include/widget}/DefaultHomePage.hpp | 2 +- .../include/widget}/DefaultNavigationBar.hpp | 2 +- .../widgets/include/widget}/HomePage.hpp | 0 .../widgets/include/widget}/NavigationBar.hpp | 0 .../widgets/include/widget}/Theme.hpp | 0 .../include/widget/model/CategoriesModel.cpp | 0 .../include/widget/model}/CategoriesModel.hpp | 0 .../widgets/src}/BootstrapTheme.cpp | 2 +- .../widgets/src}/DefaultAuthPage.cpp | 3 +- .../widgets/src}/DefaultCategoryTree.cpp | 2 +- .../widgets/src}/DefaultHomePage.cpp | 6 +- .../widgets/src}/DefaultNavigationBar.cpp | 2 +- .../test_eedb_data_PgCategoriesRepository.cpp | 2 +- tests/unit/db/test_eedb_data_PgCategory.cpp | 17 +- tests/unit/test_eedb_Item.cpp | 0 tests/unit/test_eedb_Items.cpp | 0 120 files changed, 1331 insertions(+), 256 deletions(-) delete mode 100644 src/eedb/CMakeLists.txt delete mode 100644 src/eedb/db/CMakeLists.txt delete mode 100644 src/eedb/db/model/all.hpp create mode 100644 src/libs/CMakeLists.txt create mode 100644 src/libs/auth/CMakeLists.txt rename src/{ => libs/auth/include}/eedb/auth/PgUserAuth.hpp (100%) rename src/{ => libs/auth/include}/eedb/auth/Services.hpp (100%) rename src/{eedb/auth => libs/auth/src}/PgUserAuth.cpp (99%) rename src/{eedb/auth => libs/auth/src}/Services.cpp (100%) create mode 100644 src/libs/db/CMakeLists.txt create mode 100644 src/libs/db/postgresql_connector/CMakeLists.txt rename src/{eedb/db => libs/db/postgresql_connector/include}/RawSql.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/config.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/connection.hpp (88%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgAuthIdentity.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgAuthToken.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgCategories.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgCategoriesRepository.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgCategory.hpp (86%) rename src/{eedb/widgets/models/CategoriesModel.cpp => libs/db/postgresql_connector/include/data/PgItem.hpp} (100%) create mode 100644 src/libs/db/postgresql_connector/include/data/PgItems.hpp rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgUser.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/PgUsers.hpp (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/data/Stats.hpp (100%) create mode 100644 src/libs/db/postgresql_connector/include/model/all.hpp rename src/{eedb/db => libs/db/postgresql_connector/include}/model/auth_identity.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/auth_info.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/auth_token.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/category.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/group.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/stat.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/system_info.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/user_audit.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/include}/model/user_audit_action.h (100%) rename src/{eedb/db => libs/db/postgresql_connector/src}/RawSql.cpp (88%) rename src/{eedb/db => libs/db/postgresql_connector/src}/config.cpp (97%) rename src/{eedb/db => libs/db/postgresql_connector/src}/connection.cpp (74%) rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgAuthIdentity.cpp (96%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgAuthIdentity.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgAuthToken.cpp (98%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgAuthToken.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgCategories.cpp (89%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgCategories.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgCategoriesRepository.cpp (79%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgCategory.cpp (82%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgCategory.hpp create mode 100644 src/libs/db/postgresql_connector/src/data/PgItem.cpp create mode 100644 src/libs/db/postgresql_connector/src/data/PgItem.hpp create mode 100644 src/libs/db/postgresql_connector/src/data/PgItems.cpp create mode 100644 src/libs/db/postgresql_connector/src/data/PgItems.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgUser.cpp (91%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgUser.hpp rename src/{eedb/db => libs/db/postgresql_connector/src}/data/PgUsers.cpp (96%) create mode 100644 src/libs/db/postgresql_connector/src/data/PgUsers.hpp create mode 100644 src/libs/db/postgresql_connector/src/data/Stats.hpp create mode 100644 src/libs/db/postgresql_connector/test/CMakeLists.txt rename {tests/utils => src/libs/db/postgresql_connector/test}/DbTestBase.hpp (96%) create mode 100644 src/libs/db/postgresql_connector/test/sql/categories_tree_test.sql create mode 100644 src/libs/db/postgresql_connector/test/sql/sql_data_base.sql create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp create mode 100644 src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp create mode 100644 src/libs/eedb/CMakeLists.txt rename src/{ => libs/eedb/include}/eedb/EEDB.hpp (100%) rename src/{ => libs/eedb/include}/eedb/Session.hpp (100%) rename src/{ => libs/eedb/include}/eedb/WebSession.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthIdentities.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthIdentitiesConst.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthIdentity.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthIdentityConst.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthInfo.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthInfoConst.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthToken.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthTokenConst.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/AuthTokens.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/Category.hpp (87%) rename src/{ => libs/eedb/include}/eedb/data/Email.hpp (100%) create mode 100644 src/libs/eedb/include/eedb/data/Item.hpp rename src/{ => libs/eedb/include}/eedb/data/Password.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/StatInfo.hpp (100%) create mode 100644 src/libs/eedb/include/eedb/data/Unit.hpp rename src/{ => libs/eedb/include}/eedb/data/User.hpp (100%) rename src/{ => libs/eedb/include}/eedb/data/Users.hpp (100%) create mode 100644 src/libs/eedb/include/eedb/data/Value.hpp rename src/{eedb => libs/eedb/src}/EEDB.cpp (100%) rename src/{eedb => libs/eedb/src}/WebSession.cpp (100%) create mode 100644 src/libs/eedb/src/dummy.cpp create mode 100644 src/libs/widgets/CMakeLists.txt rename src/{eedb/widgets => libs/widgets/include/widget}/AuthPage.hpp (100%) rename src/{eedb/widgets => libs/widgets/include/widget}/BootstrapTheme.hpp (85%) rename src/{eedb/widgets => libs/widgets/include/widget}/CategoryThree.hpp (100%) rename src/{eedb/widgets => libs/widgets/include/widget}/DefaultAuthPage.hpp (96%) rename src/{eedb/widgets => libs/widgets/include/widget}/DefaultCategoryTree.hpp (91%) rename src/{eedb/widgets => libs/widgets/include/widget}/DefaultHomePage.hpp (94%) rename src/{eedb/widgets => libs/widgets/include/widget}/DefaultNavigationBar.hpp (92%) rename src/{eedb/widgets => libs/widgets/include/widget}/HomePage.hpp (100%) rename src/{eedb/widgets => libs/widgets/include/widget}/NavigationBar.hpp (100%) rename src/{eedb/widgets => libs/widgets/include/widget}/Theme.hpp (100%) create mode 100644 src/libs/widgets/include/widget/model/CategoriesModel.cpp rename src/{eedb/widgets/models => libs/widgets/include/widget/model}/CategoriesModel.hpp (100%) rename src/{eedb/widgets => libs/widgets/src}/BootstrapTheme.cpp (89%) rename src/{eedb/widgets => libs/widgets/src}/DefaultAuthPage.cpp (98%) rename src/{eedb/widgets => libs/widgets/src}/DefaultCategoryTree.cpp (93%) rename src/{eedb/widgets => libs/widgets/src}/DefaultHomePage.cpp (94%) rename src/{eedb/widgets => libs/widgets/src}/DefaultNavigationBar.cpp (97%) create mode 100644 tests/unit/test_eedb_Item.cpp create mode 100644 tests/unit/test_eedb_Items.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8918c02..6419fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,5 +23,5 @@ include_directories(${CMAKE_BINARY_DIR}/external/include/date SYSTEM) include_directories(share SYSTEM) add_subdirectory(src) -add_subdirectory(tests) +#add_subdirectory(tests) #add_subdirectory(benchmarks) diff --git a/sql/schema.sql b/sql/schema.sql index d437cca..b4ace09 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -51,7 +51,7 @@ create table "group" ( constraint "pk_group_gid" primary key ("gid"), constraint "ux_group_name" unique ("name") ); -create trigger "update_user_group_last_update" before update on "group" FOR EACH ROW EXECUTE PROCEDURE last_update_column(); +create trigger "update_user_group_last_update" before update on "group" for each row execute PROCEDURE last_update_column(); insert into "group"("name") values ('nogroup'), ('admins'), ('moderators'), ('users'); create or replace function default_group_id() @@ -95,7 +95,7 @@ create table "auth_info" ( constraint "pk_auth_into_id" primary key("id"), constraint "ux_auth_info_email" unique ("email") ); -create trigger "update_auth_info_updated" before update on "auth_info" FOR EACH ROW EXECUTE PROCEDURE last_update_column(); +create trigger "update_auth_info_updated" before update on "auth_info" for each row execute PROCEDURE last_update_column(); comment on table "auth_info" is ''; comment on column "auth_info"."id" is ''; comment on column "auth_info"."group" is 'default user group'; @@ -186,7 +186,7 @@ create table "stat"( constraint "fk_stat_user" foreign key ("owner") references "auth_info" ("id") on delete cascade deferrable initially immediate, constraint "fk_stat_primary_group" foreign key ("group") references "group" ("gid") on delete cascade deferrable initially immediate ); -create trigger update_stat_last_update before update on stat FOR EACH ROW EXECUTE PROCEDURE last_update_column(); +create trigger update_stat_last_update before update on stat for each row execute PROCEDURE last_update_column(); comment on table "stat" is ''; comment on column "stat"."id" is 'unique id for all objects in database'; comment on column "stat"."owner" is 'uid of object''s owner'; @@ -271,7 +271,7 @@ create table "category"( constraint "pk_category_uid" primary key ("id"), constraint "fk_category_parent_id" foreign key ("parent_id") references "category"("id") on delete cascade deferrable initially immediate, constraint "fk_category_stat_owner" foreign key ("owner") references "auth_info"("id") deferrable initially immediate -) INHERITS (stat); +) inherits (stat); create index "ix_category_parent_path" on "category" using GIST ("parent_path"); create unique index "ux_category_name" on "category" ( "parent_id", "name" ); create trigger "update_category_last_update" before update on "category" for each row execute procedure last_update_column(); @@ -283,115 +283,101 @@ comment on column "category"."description" is ''; comment on column "category"."thumbnail" is ''; ---create table "measurand"( --- "id" serial not null unique primary key, --- "name" text not null unique, --- "description" text, --- "dimension_symbol" text +--create table "measurands"( +-- "id" serial not null primary key, +-- "name" VARCHAR(32) not null unique, +-- "description" text --); - --create table "metric_system"( --- "id" serial not null primary key, --- "name" VARCHAR(32) not null unique, --- "description" text +-- "id" serial not null primary key, +-- "name" VARCHAR(32) not null unique, +-- "description" text --); ---comment on table measurand IS 'Information about measured quantity length, time etc.'; - ---create table unit_of_measurement( --- symbol VARCHAR (20) not null, --- description TEXT check(length(description) < 100000), --- measurand_id int REFERENCES measurands(id), --- base_unit int REFERENCES units(uid), --- metric_system int REFERENCES metric_systems(id), +--create table "unit"( +-- "id" serial not null unique primary key, +-- "name" text not null unique, +-- "symbol" VARCHAR (20) not null, +-- "description" text, +-- "dimension_symbol" text +-- "metric_system" int , -- constraint units_pkey primary key (uid), --- constraint unitowner_fk foreign key (owner) REFERENCES users (uid) deferrable initially IMMEDIATE, -- constraint units_unique UNIQUE(name, symbol) +--); + +--create table "parameter"( +-- "unit" int, +-- constraint "pk_parameter" primary key ("id"), +-- constraint "fk_parameter_unit" foreign key ("unit") references "unit"("id") on delete cascade deferrable initially immediate --) inherits(stat); ---comment on table unit_of_measurement IS 'Table holds information about units used in application'; ---comment on column unit_of_measurement.name IS 'Parameter name e.g. Ampere'; ---comment on column unit_of_measurement.symbol IS 'Parameter symbol e.g. A'; ---comment on column unit_of_measurement.description IS 'Simple description'; +--create trigger update_parameter_last_update before update on parameter for each row execute PROCEDURE last_update_column(); + +create table "item"( + "symbol" text not null, + "original_symbol" text, + "producer" text, + "attributes" jsonb not null DEFAULT('{}'), + "short_desc" text, + "description" text, + constraint "pk_items" primary key ("id"), + constraint "fk_item_auth_info" foreign key ("owner") references "auth_info"("id") deferrable initially immediate +) inherits (stat); +create index "ix_item_attributes" on "item" USING GIN ("attributes"); +create unique index "ux_item" on "item"("name", "symbol"); +create trigger update_item_last_update before update on item for each row execute PROCEDURE last_update_column(); +comment on table "item" is ''; +comment on column "item"."symbol" is ''; +comment on column "item"."original_symbol" is ''; +comment on column "item"."producer" is ''; +comment on column "item"."attributes" is ''; +comment on column "item"."short_desc" is ''; +comment on column "item"."description" is ''; ---create table units_conversions( --- from_unit INTEGER not null REFERENCES units(uid), --- to_unit INTEGER not null REFERENCES units(uid), --- equation TEXT not null, --- constraint unit_conversions_unique primary key (from_unit, to_unit) ---); ---comment on table units_conversions IS 'This table contains a mathematical equation for converting one unitl to other'; ---comment on column units_conversions.equation IS 'this equation should be a proper script (mayby chaiscript?)'; - ---create table pointed_values( --- id serial primary key, --- data jsonb default('{}') ---); ---create INDEX items_pointed_values_idx on pointed_values USING GIN (data); - ---create table "item_namespaces"( ---); - ---create table "item"( --- "category_id" int not null, --- "symbol" text not null, --- "original_symbol" text, --- "producer" text, --- "visibility" VARCHAR(64) DEFAULT 'global' not null, --- "attributes" jsonb not null DEFAULT('{}'), --- "description" TEXT, --- constraint "pk_items" primary key ("id"), --- constraint "fk_item_category" foreign key ("category_id") references "category"("id") on delete cascade deferrable initially immediate, --- constraint "fk_item_auth_info" foreign key ("owner") REFERENCES "auth_info"("id") deferrable initially immediate ---) INHERITS (stat); ---create index "ix_item_attributes" on "item" USING GIN ("attributes"); ---create unique index "ux_item" on "item"("name", "symbol"); ---create trigger update_item_last_update before update on item FOR EACH ROW EXECUTE PROCEDURE last_update_column(); ---comment on table "item" is ''; ---comment on column "item"."category_id" is ''; ---comment on column "item"."symbol" is ''; ---comment on column "item"."original_symbol" is ''; ---comment on column "item"."producer" is ''; ---comment on column "item"."visibility" is ''; ---comment on column "item"."attributes" is ''; ---comment on column "item"."description" is ''; +create table "category_items"( + "category_id" integer not null, + "item_id" integer not null, + constraint "pk_category_items" primary key ("category_id", "item_id"), + constraint "fk_category_id" foreign key ("category_id") references "category"("id") on delete cascade deferrable initially immediate, + constraint "fk_item_id" foreign key ("item_id") references "item"("id") on delete cascade deferrable initially immediate +); +comment on table "category_items" is ''; --create table "inventory"( -- "description" TEXT check(length(description)< 100000), -- constraint "pk_inventory" primary key ("id"), --- constraint "fk_inventory_owner" foreign key ("owner") REFERENCES "auth_info" ("id") deferrable initially immediate, +-- constraint "fk_inventory_owner" foreign key ("owner") references "auth_info" ("id") deferrable initially immediate, -- constraint "chk_inventory_name_length" check (length(name) < 100) ---) INHERITS (stat); ---create trigger update_inventory_last_update before update on inventory FOR EACH ROW EXECUTE PROCEDURE last_update_column(); +--) inherits (stat); +--create trigger update_inventory_last_update before update on inventory for each row execute PROCEDURE last_update_column(); --create table "user_inventory"( --- "auth_info_id" INTEGER not null REFERENCES "auth_info" on DELETE CASCADE, --- "inventory_id" INTEGER not null REFERENCES "inventory" on DELETE CASCADE, +-- "auth_info_id" INTEGER not null references "auth_info" on DELETE CASCADE, +-- "inventory_id" INTEGER not null references "inventory" on DELETE CASCADE, -- constraint user_inventory_pk primary key ("inventory_id", "auth_info_id") --); --create table in_stock( --- item_id INTEGER not null REFERENCES items, --- inventory_id INTEGER not null REFERENCES inventory, +-- item_id INTEGER not null references items, +-- inventory_id INTEGER not null references inventory, -- amount numeric(10,10) not null DEFAULT 0 --); - --comment on table in_stock IS 'Table contains information about items being available in storage'; --create table inventory_operations( -- constraint inventory_operations_pkey primary key (uid), --- constraint OperationOwner_fk foreign key (owner) REFERENCES users (uid) deferrable initially IMMEDIATE, +-- constraint OperationOwner_fk foreign key (owner) references users (uid) deferrable initially IMMEDIATE, -- constraint inventory_operation_unique UNIQUE (name) ---) INHERITS(stat); +--) inherits(stat); --create table inventory_history( --- inventory_from_id INTEGER not null REFERENCES inventory on DELETE CASCADE, --- inventory_to_id INTEGER not null REFERENCES inventory on DELETE CASCADE, --- operation_id INTEGER not null REFERENCES inventory_Operations on DELETE CASCADE , +-- inventory_from_id INTEGER not null references inventory on DELETE CASCADE, +-- inventory_to_id INTEGER not null references inventory on DELETE CASCADE, +-- operation_id INTEGER not null references inventory_Operations on DELETE CASCADE , -- amount NUMERIC(10,10), -- date timestamp not null default now() @@ -404,10 +390,10 @@ comment on column "category"."thumbnail" is ''; -- create INDEX files_stat_index on files (uid, owner, group, unixperms, status) with ( FILLFACTOR=100 ); -- create INDEX items_stat_index on items (uid, owner, group, unixperms, status) with ( FILLFACTOR=100 ); --- create trigger update_parameters_last_update before update on parameters FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_files_last_update before update on files FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_packages_last_update before update on packages FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_units_last_update before update on units FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_items_last_update before update on items FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_shelfs_last_update before update on shelfs FOR EACH ROW EXECUTE PROCEDURE last_update_column(); --- create trigger update_inventory_operations_lats_update before update on inventory_operations FOR EACH ROW EXECUTE PROCEDURE last_update_column(); +-- create trigger update_parameters_last_update before update on parameters for each row execute PROCEDURE last_update_column(); +-- create trigger update_files_last_update before update on files for each row execute PROCEDURE last_update_column(); +-- create trigger update_packages_last_update before update on packages for each row execute PROCEDURE last_update_column(); +-- create trigger update_units_last_update before update on units for each row execute PROCEDURE last_update_column(); +-- create trigger update_items_last_update before update on items for each row execute PROCEDURE last_update_column(); +-- create trigger update_shelfs_last_update before update on shelfs for each row execute PROCEDURE last_update_column(); +-- create trigger update_inventory_operations_lats_update before update on inventory_operations for each row execute PROCEDURE last_update_column(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fc7868..a59a264 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,5 +2,5 @@ project( eedb_app ) INCLUDE_DIRECTORIES(.) add_subdirectory(utils) -add_subdirectory(eedb) +add_subdirectory(libs) add_subdirectory(app) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 5eaa7a6..5e5d99a 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,20 +1,18 @@ -set(SOURCES - main.cpp) +#set(SOURCES +# main.cpp) -add_executable(eedb ${SOURCES} ) +#add_executable(eedb_app ${SOURCES}) -include_directories( ${PostgreSQL_INCLUDE_DIRS} ) - -target_link_libraries(eedb - wthttp # or {Wt_HTTP_DEBUG_LIBRARY} - wt # or {Wt_DEBUG_LIBRARY} - eedb_db - eedb_auth - eedb_app - Boost::system - Boost::filesystem - Boost::thread - Boost::program_options - z - ) +#target_link_libraries(eedb_app +# wthttp # or {Wt_HTTP_DEBUG_LIBRARY} +# wt # or {Wt_DEBUG_LIBRARY} +# postgresql_connector +# auth +# eedb +# Boost::system +# Boost::filesystem +# Boost::thread +# Boost::program_options +# z +# ) diff --git a/src/eedb/CMakeLists.txt b/src/eedb/CMakeLists.txt deleted file mode 100644 index 5b47cf6..0000000 --- a/src/eedb/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -file(GLOB AUTH_SOURCE auth/* ) - -file(GLOB SOURCE - EEDB.cpp - WebSession.cpp - - data/* - widgets/* -) - -include_directories(${CMAKE_BINARY_DIR}/external/include SYSTEM) - -include_directories( ${PostgreSQL_INCLUDE_DIRS} ) -add_subdirectory(db) - -add_library(eedb_auth ${AUTH_SOURCE}) -target_link_libraries(eedb_auth PUBLIC nlohmann_json) -set_target_properties(eedb_auth PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) -cotire(eedb_auth) - -add_library(eedb_app ${SOURCE}) -target_link_libraries(eedb_app PUBLIC eedb_auth) -set_target_properties(eedb_app PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) -cotire(eedb_app) diff --git a/src/eedb/db/CMakeLists.txt b/src/eedb/db/CMakeLists.txt deleted file mode 100644 index 8ade1c6..0000000 --- a/src/eedb/db/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -set(SOURCE - data/PgAuthToken.cpp - data/PgAuthIdentity.cpp - data/PgCategory.cpp - data/PgCategories.cpp - data/PgCategoriesRepository.cpp - data/PgUser.cpp - data/PgUsers.cpp - - connection.cpp - config.cpp - RawSql.cpp -) - -file(GLOB INCLUDES - *.h* - data/*.hpp -) - -file(GLOB MODEL - model/* -) - -add_library(eedb_db ${SOURCE} ${MODEL} ${INCLUDES}) -target_link_libraries(eedb_db sqlpp-postgresql) - -set_target_properties(eedb_db PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) -cotire(eedb_db) diff --git a/src/eedb/db/model/all.hpp b/src/eedb/db/model/all.hpp deleted file mode 100644 index d66779a..0000000 --- a/src/eedb/db/model/all.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -constexpr eedb::user_audit t_user_audit; -constexpr eedb::auth_identity t_auth_identity; -constexpr eedb::auth_info t_auth_info; -constexpr eedb::auth_token t_auth_token; -constexpr eedb::group t_group; -constexpr eedb::category t_category; diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt new file mode 100644 index 0000000..33b54aa --- /dev/null +++ b/src/libs/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(eedb) + +add_subdirectory(db) + +add_subdirectory(auth) + +add_subdirectory(widgets) diff --git a/src/libs/auth/CMakeLists.txt b/src/libs/auth/CMakeLists.txt new file mode 100644 index 0000000..03f5e0f --- /dev/null +++ b/src/libs/auth/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LIB auth) + +file(GLOB auth_SOURCE src/*) + +# find packages +find_package(nlohmann_json CONFIG REQUIRED) + +# create library +add_library(${LIB} ${auth_SOURCE}) + +# link all +target_include_directories(${LIB} PUBLIC include) +target_link_libraries(${LIB} PRIVATE eedb) +target_link_libraries(${LIB} PUBLIC nlohmann_json) + +# add cotire +set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) +cotire(${LIB}) diff --git a/src/eedb/auth/PgUserAuth.hpp b/src/libs/auth/include/eedb/auth/PgUserAuth.hpp similarity index 100% rename from src/eedb/auth/PgUserAuth.hpp rename to src/libs/auth/include/eedb/auth/PgUserAuth.hpp diff --git a/src/eedb/auth/Services.hpp b/src/libs/auth/include/eedb/auth/Services.hpp similarity index 100% rename from src/eedb/auth/Services.hpp rename to src/libs/auth/include/eedb/auth/Services.hpp diff --git a/src/eedb/auth/PgUserAuth.cpp b/src/libs/auth/src/PgUserAuth.cpp similarity index 99% rename from src/eedb/auth/PgUserAuth.cpp rename to src/libs/auth/src/PgUserAuth.cpp index c38a97a..011032b 100644 --- a/src/eedb/auth/PgUserAuth.cpp +++ b/src/libs/auth/src/PgUserAuth.cpp @@ -1,4 +1,4 @@ -#include "PgUserAuth.hpp" +#include #include #include diff --git a/src/eedb/auth/Services.cpp b/src/libs/auth/src/Services.cpp similarity index 100% rename from src/eedb/auth/Services.cpp rename to src/libs/auth/src/Services.cpp diff --git a/src/libs/db/CMakeLists.txt b/src/libs/db/CMakeLists.txt new file mode 100644 index 0000000..ed77000 --- /dev/null +++ b/src/libs/db/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(postgresql_connector) diff --git a/src/libs/db/postgresql_connector/CMakeLists.txt b/src/libs/db/postgresql_connector/CMakeLists.txt new file mode 100644 index 0000000..f62b7c7 --- /dev/null +++ b/src/libs/db/postgresql_connector/CMakeLists.txt @@ -0,0 +1,24 @@ +set(LIB postgres_connector) + +file(GLOB_RECURSE postgres_connector_SOURCE src/*) + +# find packages +find_package(nlohmann_json CONFIG REQUIRED) + +# create library +add_library(${LIB} ${postgres_connector_SOURCE}) + +# link all +target_include_directories(${LIB} PRIVATE ${CMAKE_BINARY_DIR}/external/include SYSTEM) +target_include_directories(${LIB} PRIVATE ${PostgreSQL_INCLUDE_DIRS}) + +target_include_directories(${LIB} PUBLIC include) +target_link_libraries(${LIB} PUBLIC nlohmann_json) +target_link_libraries(${LIB} PRIVATE eedb) +target_link_libraries(${LIB} PRIVATE sqlpp-postgresql) + +# add cotire +set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) +cotire(${LIB}) + +add_subdirectory(test) diff --git a/src/eedb/db/RawSql.hpp b/src/libs/db/postgresql_connector/include/RawSql.hpp similarity index 100% rename from src/eedb/db/RawSql.hpp rename to src/libs/db/postgresql_connector/include/RawSql.hpp diff --git a/src/eedb/db/config.hpp b/src/libs/db/postgresql_connector/include/config.hpp similarity index 100% rename from src/eedb/db/config.hpp rename to src/libs/db/postgresql_connector/include/config.hpp diff --git a/src/eedb/db/connection.hpp b/src/libs/db/postgresql_connector/include/connection.hpp similarity index 88% rename from src/eedb/db/connection.hpp rename to src/libs/db/postgresql_connector/include/connection.hpp index 5039180..7b9bd3b 100644 --- a/src/eedb/db/connection.hpp +++ b/src/libs/db/postgresql_connector/include/connection.hpp @@ -21,6 +21,6 @@ class PgConnection { } private: - std::unique_ptr< sqlpp::postgresql::connection > _conn;\ + std::unique_ptr< sqlpp::postgresql::connection > _conn; }; } // namespace eedb::db diff --git a/src/eedb/db/data/PgAuthIdentity.hpp b/src/libs/db/postgresql_connector/include/data/PgAuthIdentity.hpp similarity index 100% rename from src/eedb/db/data/PgAuthIdentity.hpp rename to src/libs/db/postgresql_connector/include/data/PgAuthIdentity.hpp diff --git a/src/eedb/db/data/PgAuthToken.hpp b/src/libs/db/postgresql_connector/include/data/PgAuthToken.hpp similarity index 100% rename from src/eedb/db/data/PgAuthToken.hpp rename to src/libs/db/postgresql_connector/include/data/PgAuthToken.hpp diff --git a/src/eedb/db/data/PgCategories.hpp b/src/libs/db/postgresql_connector/include/data/PgCategories.hpp similarity index 100% rename from src/eedb/db/data/PgCategories.hpp rename to src/libs/db/postgresql_connector/include/data/PgCategories.hpp diff --git a/src/eedb/db/data/PgCategoriesRepository.hpp b/src/libs/db/postgresql_connector/include/data/PgCategoriesRepository.hpp similarity index 100% rename from src/eedb/db/data/PgCategoriesRepository.hpp rename to src/libs/db/postgresql_connector/include/data/PgCategoriesRepository.hpp diff --git a/src/eedb/db/data/PgCategory.hpp b/src/libs/db/postgresql_connector/include/data/PgCategory.hpp similarity index 86% rename from src/eedb/db/data/PgCategory.hpp rename to src/libs/db/postgresql_connector/include/data/PgCategory.hpp index e81e718..7e1b29c 100644 --- a/src/eedb/db/data/PgCategory.hpp +++ b/src/libs/db/postgresql_connector/include/data/PgCategory.hpp @@ -29,8 +29,9 @@ class PgCategory : public Category { std::unique_ptr< Categories > children() const override; - bool detached() const override; - std::unique_ptr< Category > create(std::string name, std::string description, std::optional< path > image = {}) const override; +// bool detached() const override; + + std::unique_ptr< Category > create(std::string name, std::string description) const override; }; } // namespace eedb diff --git a/src/eedb/widgets/models/CategoriesModel.cpp b/src/libs/db/postgresql_connector/include/data/PgItem.hpp similarity index 100% rename from src/eedb/widgets/models/CategoriesModel.cpp rename to src/libs/db/postgresql_connector/include/data/PgItem.hpp diff --git a/src/libs/db/postgresql_connector/include/data/PgItems.hpp b/src/libs/db/postgresql_connector/include/data/PgItems.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/eedb/db/data/PgUser.hpp b/src/libs/db/postgresql_connector/include/data/PgUser.hpp similarity index 100% rename from src/eedb/db/data/PgUser.hpp rename to src/libs/db/postgresql_connector/include/data/PgUser.hpp diff --git a/src/eedb/db/data/PgUsers.hpp b/src/libs/db/postgresql_connector/include/data/PgUsers.hpp similarity index 100% rename from src/eedb/db/data/PgUsers.hpp rename to src/libs/db/postgresql_connector/include/data/PgUsers.hpp diff --git a/src/eedb/db/data/Stats.hpp b/src/libs/db/postgresql_connector/include/data/Stats.hpp similarity index 100% rename from src/eedb/db/data/Stats.hpp rename to src/libs/db/postgresql_connector/include/data/Stats.hpp diff --git a/src/libs/db/postgresql_connector/include/model/all.hpp b/src/libs/db/postgresql_connector/include/model/all.hpp new file mode 100644 index 0000000..3a1c52f --- /dev/null +++ b/src/libs/db/postgresql_connector/include/model/all.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr eedb::user_audit t_user_audit; +constexpr eedb::auth_identity t_auth_identity; +constexpr eedb::auth_info t_auth_info; +constexpr eedb::auth_token t_auth_token; +constexpr eedb::group t_group; +constexpr eedb::category t_category; diff --git a/src/eedb/db/model/auth_identity.h b/src/libs/db/postgresql_connector/include/model/auth_identity.h similarity index 100% rename from src/eedb/db/model/auth_identity.h rename to src/libs/db/postgresql_connector/include/model/auth_identity.h diff --git a/src/eedb/db/model/auth_info.h b/src/libs/db/postgresql_connector/include/model/auth_info.h similarity index 100% rename from src/eedb/db/model/auth_info.h rename to src/libs/db/postgresql_connector/include/model/auth_info.h diff --git a/src/eedb/db/model/auth_token.h b/src/libs/db/postgresql_connector/include/model/auth_token.h similarity index 100% rename from src/eedb/db/model/auth_token.h rename to src/libs/db/postgresql_connector/include/model/auth_token.h diff --git a/src/eedb/db/model/category.h b/src/libs/db/postgresql_connector/include/model/category.h similarity index 100% rename from src/eedb/db/model/category.h rename to src/libs/db/postgresql_connector/include/model/category.h diff --git a/src/eedb/db/model/group.h b/src/libs/db/postgresql_connector/include/model/group.h similarity index 100% rename from src/eedb/db/model/group.h rename to src/libs/db/postgresql_connector/include/model/group.h diff --git a/src/eedb/db/model/stat.h b/src/libs/db/postgresql_connector/include/model/stat.h similarity index 100% rename from src/eedb/db/model/stat.h rename to src/libs/db/postgresql_connector/include/model/stat.h diff --git a/src/eedb/db/model/system_info.h b/src/libs/db/postgresql_connector/include/model/system_info.h similarity index 100% rename from src/eedb/db/model/system_info.h rename to src/libs/db/postgresql_connector/include/model/system_info.h diff --git a/src/eedb/db/model/user_audit.h b/src/libs/db/postgresql_connector/include/model/user_audit.h similarity index 100% rename from src/eedb/db/model/user_audit.h rename to src/libs/db/postgresql_connector/include/model/user_audit.h diff --git a/src/eedb/db/model/user_audit_action.h b/src/libs/db/postgresql_connector/include/model/user_audit_action.h similarity index 100% rename from src/eedb/db/model/user_audit_action.h rename to src/libs/db/postgresql_connector/include/model/user_audit_action.h diff --git a/src/eedb/db/RawSql.cpp b/src/libs/db/postgresql_connector/src/RawSql.cpp similarity index 88% rename from src/eedb/db/RawSql.cpp rename to src/libs/db/postgresql_connector/src/RawSql.cpp index 87c10c3..aa3694b 100644 --- a/src/eedb/db/RawSql.cpp +++ b/src/libs/db/postgresql_connector/src/RawSql.cpp @@ -1,9 +1,9 @@ -#include +#include #include #include -#include +#include #include namespace eedb::db{ diff --git a/src/eedb/db/config.cpp b/src/libs/db/postgresql_connector/src/config.cpp similarity index 97% rename from src/eedb/db/config.cpp rename to src/libs/db/postgresql_connector/src/config.cpp index 508d8b6..3a1562b 100644 --- a/src/eedb/db/config.cpp +++ b/src/libs/db/postgresql_connector/src/config.cpp @@ -1,4 +1,4 @@ -#include +#include "config.hpp" #include #include diff --git a/src/eedb/db/connection.cpp b/src/libs/db/postgresql_connector/src/connection.cpp similarity index 74% rename from src/eedb/db/connection.cpp rename to src/libs/db/postgresql_connector/src/connection.cpp index c098cd7..f5e37e0 100644 --- a/src/eedb/db/connection.cpp +++ b/src/libs/db/postgresql_connector/src/connection.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "config.hpp" +#include "connection.hpp" namespace eedb::db { diff --git a/src/eedb/db/data/PgAuthIdentity.cpp b/src/libs/db/postgresql_connector/src/data/PgAuthIdentity.cpp similarity index 96% rename from src/eedb/db/data/PgAuthIdentity.cpp rename to src/libs/db/postgresql_connector/src/data/PgAuthIdentity.cpp index 4188bdd..ef6eb1a 100644 --- a/src/eedb/db/data/PgAuthIdentity.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgAuthIdentity.cpp @@ -1,8 +1,8 @@ -#include +#include "data/PgAuthIdentity.hpp" #include -#include -#include +#include +#include #include #include diff --git a/src/libs/db/postgresql_connector/src/data/PgAuthIdentity.hpp b/src/libs/db/postgresql_connector/src/data/PgAuthIdentity.hpp new file mode 100644 index 0000000..f2256ee --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgAuthIdentity.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +#include + +namespace eedb { +class User; +} + +namespace eedb::db { +class PgConnection; +} + +namespace eedb { +class PgAuthIdentity final : public AuthIdentity { + public: + PgAuthIdentity(db::PgConnection & db, std::string identity, std::string provider); + // PgAuthIdentity(db::PgConnection & db, nlohmann::json data); + + string_view identity() const override; + + string_view provider() const override; + + private: + struct PgAuthIdentityPriv; + spimpl::unique_impl_ptr< PgAuthIdentityPriv > _priv; +}; + +class PgAuthIdentities final : public AuthIdentities { + public: + PgAuthIdentities(db::PgConnection & db, const User * owner); + // PgAuthIdentities(db::PgConnection & db, nlohmann::json data); + + AuthIdentity * addIdentity(std::unique_ptr< AuthIdentity > identity) override; + + AuthIdentity * byProvider(std::string_view provider) const override; + + void removeProvider(std::string_view provider) override; + + private: + struct PgAuthIdentitysPriv; + spimpl::unique_impl_ptr< PgAuthIdentitysPriv > _priv; +}; +} // namespace eedb diff --git a/src/eedb/db/data/PgAuthToken.cpp b/src/libs/db/postgresql_connector/src/data/PgAuthToken.cpp similarity index 98% rename from src/eedb/db/data/PgAuthToken.cpp rename to src/libs/db/postgresql_connector/src/data/PgAuthToken.cpp index 83d8d61..92a2745 100644 --- a/src/eedb/db/data/PgAuthToken.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgAuthToken.cpp @@ -1,9 +1,9 @@ -#include +#include #include -#include -#include +#include +#include #include diff --git a/src/libs/db/postgresql_connector/src/data/PgAuthToken.hpp b/src/libs/db/postgresql_connector/src/data/PgAuthToken.hpp new file mode 100644 index 0000000..1dd48c6 --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgAuthToken.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +#include + +#include + +namespace eedb { +class User; +} +namespace eedb::db { +class PgConnection; +} + +namespace eedb { + +class PgAuthToken final : public AuthToken { + // AuthToken interface + public: + PgAuthToken(db::PgConnection & con, int64_t uid); + PgAuthToken(db::PgConnection & con, int64_t uid, std::string hash, us_point expirationtime); + + std::string_view token() const override; + + us_point expireTimepoint() const override; + + bool expired() const override; + + void update(std::string newHash) override; + + private: + struct PgAuthTokenPriv; + spimpl::unique_impl_ptr< PgAuthTokenPriv > _priv; +}; + +class PgAuthTokens final : public AuthTokens { + public: + PgAuthTokens(db::PgConnection & con, const User * owner); + + AuthToken * find(std::variant< std::string_view, AuthTokenRole > token) const override; + + void removeToken(std::string_view token) override; + + AuthToken * addToken(std::string hash, AuthTokenRole role) override; + + private: + struct PgAuthTokensPriv; + spimpl::unique_impl_ptr< PgAuthTokensPriv > _priv; +}; +} // namespace eedb diff --git a/src/eedb/db/data/PgCategories.cpp b/src/libs/db/postgresql_connector/src/data/PgCategories.cpp similarity index 89% rename from src/eedb/db/data/PgCategories.cpp rename to src/libs/db/postgresql_connector/src/data/PgCategories.cpp index 3f5fae0..974b018 100644 --- a/src/eedb/db/data/PgCategories.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgCategories.cpp @@ -1,9 +1,9 @@ -#include +#include "data/PgCategories.hpp" -#include +#include -#include -#include +#include +#include #include diff --git a/src/libs/db/postgresql_connector/src/data/PgCategories.hpp b/src/libs/db/postgresql_connector/src/data/PgCategories.hpp new file mode 100644 index 0000000..8259822 --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgCategories.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +namespace eedb::db{ +class PgConnection; +} + +namespace eedb { +class PgCategory; + +class PgCategories : public Categories { + // Categories interface + public: + PgCategories(std::vector > &&data); + + long size() const override; + + Iterable begin() const override; + Iterable end() const override; + + private: + struct PgCategoriesPriv; + spimpl::unique_impl_ptr< PgCategoriesPriv > _priv; +}; +} // namespace eedb diff --git a/src/eedb/db/data/PgCategoriesRepository.cpp b/src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.cpp similarity index 79% rename from src/eedb/db/data/PgCategoriesRepository.cpp rename to src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.cpp index fd527d5..de9ebcc 100644 --- a/src/eedb/db/data/PgCategoriesRepository.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.cpp @@ -1,9 +1,9 @@ -#include +#include -#include +#include -#include -#include +#include +#include namespace eedb { struct PgCategoriesRepository::PgCategoriesRepositoryPriv { diff --git a/src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.hpp b/src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.hpp new file mode 100644 index 0000000..de88009 --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgCategoriesRepository.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +namespace eedb::db { +class PgConnection; +} + +namespace eedb{ +class User; +} + +namespace eedb { +class PgCategoriesRepository : public CategoriesRepository { + public: + // CategoriesRepository interface + public: + PgCategoriesRepository(db::PgConnection & db, User * owner); + + std::unique_ptr< Category > root() const override; + + private: + struct PgCategoriesRepositoryPriv; + spimpl::unique_impl_ptr< PgCategoriesRepositoryPriv > _priv; +}; +} // namespace eedb diff --git a/src/eedb/db/data/PgCategory.cpp b/src/libs/db/postgresql_connector/src/data/PgCategory.cpp similarity index 82% rename from src/eedb/db/data/PgCategory.cpp rename to src/libs/db/postgresql_connector/src/data/PgCategory.cpp index e0e6744..157a7ab 100644 --- a/src/eedb/db/data/PgCategory.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgCategory.cpp @@ -1,8 +1,8 @@ -#include +#include -#include -#include -#include +#include +#include +#include #include @@ -49,12 +49,15 @@ struct PgCategory::PgCategoryPrivate { } public: - PgCategoryPrivate(db::PgConnection & db, User * owner, Category * parent) : _db{db}, _owner{owner}, _self{parent} { + Category * _self{nullptr}; + + PgCategoryPrivate(db::PgConnection & db, User * owner, Category * parent) : _db{db}, _owner{owner}, _parent{parent} { auto row = _db(select(columns()).from(table_list()).where(root_path_match()).limit(0ul)); - if(row.empty()){ + if(row.empty()) { // no root category row = _db(sqlpp::postgresql::insert_into(t_category) - .set(t_category.owner = _owner->uid(), + .set( // + t_category.owner = _owner->uid(), t_category.status = 0, t_category.parent_id = sqlpp::null, t_category.name = "root", @@ -80,15 +83,13 @@ struct PgCategory::PgCategoryPrivate { return _parent == nullptr && _path != "root"; } - auto create(std::string name, std::string description, std::optional< Category::path > image) const { - /// TODO test if image exists on hdd + 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(), t_category.status = 0, t_category.parent_id = _uid, t_category.name = name, - t_category.description = description, - t_category.thumbnail = image.value_or("")) // + t_category.description = description) // .returning(columns())) .front(); @@ -97,6 +98,10 @@ struct PgCategory::PgCategoryPrivate { return std::make_unique< PgCategory >(std::move(priv)); } + auto parent() const { + return _parent; + } + protected: template < typename Row > void init_data(Row & row) { @@ -111,33 +116,36 @@ struct PgCategory::PgCategoryPrivate { User * _owner; int64_t _uid{}; - Category * _self{nullptr}; Category * _parent{nullptr}; std::string _name; std::string _path; std::string _description; }; -PgCategory::PgCategory(db::PgConnection & db, User * user) : _priv{spimpl::make_impl< PgCategoryPrivate >(db, user, this)} {} +PgCategory::PgCategory(db::PgConnection & db, User * user) : _priv{spimpl::make_impl< PgCategoryPrivate >(db, user, nullptr)} { + _priv->_self = this; +} -PgCategory::PgCategory(spimpl::impl_ptr< PgCategoryPrivate > priv) : _priv{std::move(priv)} {} +PgCategory::PgCategory(spimpl::impl_ptr< PgCategoryPrivate > priv) : _priv{std::move(priv)} { + _priv->_self = this; +} Category::string_view PgCategory::displayName() const {} Category * PgCategory::parent() const { - return nullptr; + return _priv->parent(); } std::unique_ptr< Categories > PgCategory::children() const { return std::make_unique< PgCategories >(_priv->categories()); } -bool PgCategory::detached() const { - return _priv->detached(); -} +// bool PgCategory::detached() const { +// return _priv->detached(); +//} -std::unique_ptr< Category > PgCategory::create(std::string name, std::string description, std::optional< Category::path > image) const { - return _priv->create(std::move(name), std::move(description), std::move(image)); +std::unique_ptr< Category > PgCategory::create(std::string name, std::string description) const { + return _priv->create(std::move(name), std::move(description)); } } // namespace eedb diff --git a/src/libs/db/postgresql_connector/src/data/PgCategory.hpp b/src/libs/db/postgresql_connector/src/data/PgCategory.hpp new file mode 100644 index 0000000..7e1b29c --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgCategory.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include + +namespace eedb::db { +class PgConnection; +} + +namespace eedb { +class User; +} + +namespace eedb { + +class PgCategory : public Category { + private: + struct PgCategoryPrivate; + spimpl::impl_ptr< PgCategoryPrivate > _priv; + + public: + PgCategory(db::PgConnection & db, User * user); + PgCategory(spimpl::impl_ptr priv); + + string_view displayName() const override; + + Category * parent() const override; + + std::unique_ptr< Categories > children() const override; + +// bool detached() const override; + + std::unique_ptr< Category > create(std::string name, std::string description) const override; +}; + +} // namespace eedb diff --git a/src/libs/db/postgresql_connector/src/data/PgItem.cpp b/src/libs/db/postgresql_connector/src/data/PgItem.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/db/postgresql_connector/src/data/PgItem.hpp b/src/libs/db/postgresql_connector/src/data/PgItem.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/db/postgresql_connector/src/data/PgItems.cpp b/src/libs/db/postgresql_connector/src/data/PgItems.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/db/postgresql_connector/src/data/PgItems.hpp b/src/libs/db/postgresql_connector/src/data/PgItems.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/eedb/db/data/PgUser.cpp b/src/libs/db/postgresql_connector/src/data/PgUser.cpp similarity index 91% rename from src/eedb/db/data/PgUser.cpp rename to src/libs/db/postgresql_connector/src/data/PgUser.cpp index 0d9b621..e5f9ba8 100644 --- a/src/eedb/db/data/PgUser.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgUser.cpp @@ -1,12 +1,12 @@ -#include +#include -#include -#include -#include +#include +#include +#include #include -#include +#include #include diff --git a/src/libs/db/postgresql_connector/src/data/PgUser.hpp b/src/libs/db/postgresql_connector/src/data/PgUser.hpp new file mode 100644 index 0000000..ad425bd --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgUser.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include + +#include + +namespace eedb::db { +class PgConnection; +} + +namespace eedb { + +class PgUser : public User { + public: + PgUser(db::PgConnection & db, int uid); + + int uid() const override; + + const UserName & name() const override; + + const UserConfig & config() const override; + + void logout() override; + + AuthTokens & authTokens() const override; + + AuthIdentities & authIdentities() const override; + + AuthInfo & authInfo() const override; + + private: + struct PgUserPriv; + spimpl::unique_impl_ptr< PgUserPriv > _priv; +}; +} // namespace eedb diff --git a/src/eedb/db/data/PgUsers.cpp b/src/libs/db/postgresql_connector/src/data/PgUsers.cpp similarity index 96% rename from src/eedb/db/data/PgUsers.cpp rename to src/libs/db/postgresql_connector/src/data/PgUsers.cpp index f6e72b7..4c086a8 100644 --- a/src/eedb/db/data/PgUsers.cpp +++ b/src/libs/db/postgresql_connector/src/data/PgUsers.cpp @@ -1,16 +1,16 @@ -#include +#include -#include +#include #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include diff --git a/src/libs/db/postgresql_connector/src/data/PgUsers.hpp b/src/libs/db/postgresql_connector/src/data/PgUsers.hpp new file mode 100644 index 0000000..e221e43 --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/PgUsers.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include + +namespace eedb::db { +class PgConnection; +} + +namespace eedb { +class PgUsers : public Users { + // Users interface + public: + PgUsers(eedb::db::PgConnection & db); + + unique_ptr< User > findWith(int64_t uid) const override; + unique_ptr< User > findWith(const AuthIdentity & name) const override; + unique_ptr< User > findWith(const Email & email) const override; + unique_ptr< User > findWith(const EmailToken & token) const override; + unique_ptr< User > findWith(const AuthToken & token) const override; + +// unique_ptr< User > createRoot(); + unique_ptr< User > addUser(unique_ptr< AuthInfo >, unique_ptr< AuthIdentity >) override; + void removeUser(std::unique_ptr< User > user) const override; + + private: + struct PgUsersPriv; + spimpl::unique_impl_ptr< PgUsersPriv > _priv; +}; +} // namespace eedb diff --git a/src/libs/db/postgresql_connector/src/data/Stats.hpp b/src/libs/db/postgresql_connector/src/data/Stats.hpp new file mode 100644 index 0000000..672fc07 --- /dev/null +++ b/src/libs/db/postgresql_connector/src/data/Stats.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace eedb::details { + +template < typename Row, typename Data > +auto readStats(Data & data, Row & row) {} +} // namespace eedb::details diff --git a/src/libs/db/postgresql_connector/test/CMakeLists.txt b/src/libs/db/postgresql_connector/test/CMakeLists.txt new file mode 100644 index 0000000..d87fb71 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.0.2) + +#project(Tests LANGUAGES CXX) + +find_package(GMock CONFIG REQUIRED) + +set(TEST_EXECUTABLE_NAME postgres_connector-test ) + +#add test files +file(GLOB_RECURSE TEST_FILES test_*.cpp ) + +add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES}) +target_link_libraries(${TEST_EXECUTABLE_NAME} GMock::main eedb postgres_connector) + +add_test( ${TEST_EXECUTABLE_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_EXECUTABLE_NAME}) diff --git a/tests/utils/DbTestBase.hpp b/src/libs/db/postgresql_connector/test/DbTestBase.hpp similarity index 96% rename from tests/utils/DbTestBase.hpp rename to src/libs/db/postgresql_connector/test/DbTestBase.hpp index a8589e0..9d73697 100644 --- a/tests/utils/DbTestBase.hpp +++ b/src/libs/db/postgresql_connector/test/DbTestBase.hpp @@ -1,8 +1,8 @@ -#include +#include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/libs/db/postgresql_connector/test/sql/categories_tree_test.sql b/src/libs/db/postgresql_connector/test/sql/categories_tree_test.sql new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/db/postgresql_connector/test/sql/sql_data_base.sql b/src/libs/db/postgresql_connector/test/sql/sql_data_base.sql new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp new file mode 100644 index 0000000..287183a --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentities.cpp @@ -0,0 +1,93 @@ +#include + +#include + +#include +#include +#include + +#include +#include + +#include "DbTestBase.hpp" + +namespace { +class UserMock : public eedb::User { + public: + MOCK_CONST_METHOD0(uid, int()); + const eedb::UserName & name() const {} + const eedb::UserConfig & config() const override {} + eedb::AuthTokens & authTokens() const override {} + void logout() override {} + eedb::AuthIdentities & authIdentities() const {} + int64_t _uid; + + // User interface + public: + eedb::AuthInfo & authInfo() const override {} +}; +} // namespace + +class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > { + public: + PgAuthIdentitiesTest() { + using namespace testing; + db().native()->start_transaction(); + + authInfoId = 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; + + EXPECT_CALL(user, uid()).WillRepeatedly(testing::Return(authInfoId)); + sut = std::make_unique< eedb::PgAuthIdentities >(db(), &user); + } + + void createIdentity(const eedb::AuthIdentityConst id) { + db()(insert_into(t_auth_identity) // + .set(t_auth_identity.auth_info_id = authInfoId, + t_auth_identity.provider = std::string{id.provider()}, + t_auth_identity.identity = std::string{id.identity()})); + } + + ~PgAuthIdentitiesTest() { + db().native()->rollback_transaction(false); + } + + protected: + UserMock user; + int64_t authInfoId{0}; + std::unique_ptr< eedb::PgAuthIdentities > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgAuthIdentitiesTest >::_test_db = {}; + +using namespace sqlpp; +using namespace eedb; + +TEST_F(PgAuthIdentitiesTest, searchForFalseIdentity) { + EXPECT_FALSE(sut->byProvider("nonexisting")); +} + +TEST_F(PgAuthIdentitiesTest, findIdentity) { + createIdentity({"identity", "provider"}); + EXPECT_TRUE(sut->byProvider("provider")); +} + +TEST_F(PgAuthIdentitiesTest, addProvider) { + sut->addIdentity(std::make_unique< AuthIdentityConst >("identity2", "provider")); + EXPECT_TRUE(sut->byProvider("provider")); +} + +TEST_F(PgAuthIdentitiesTest, removeIdentity) { + createIdentity({"identity", "provider"}); + sut->removeProvider("provider"); + EXPECT_FALSE(sut->byProvider("provider")); +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp new file mode 100644 index 0000000..b10e915 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthIdentity.cpp @@ -0,0 +1,40 @@ +#include + +#include + +#include "DbTestBase.hpp" + +class PgAuthIdentityTest : public DbTestBase< PgAuthIdentityTest > { + public: + PgAuthIdentityTest() { + using namespace testing; + db().native()->start_transaction(); + } + + void initCached() { + sut = std::make_unique< eedb::PgAuthIdentity >(db(), "identity", "provider"); + } + + ~PgAuthIdentityTest() { + db().native()->rollback_transaction(false); + } + + protected: + std::unique_ptr< eedb::PgAuthIdentity > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgAuthIdentityTest >::_test_db = {}; + +using namespace sqlpp; +using namespace std::chrono; + +TEST_F(PgAuthIdentityTest, hasIdentity) { + initCached(); + EXPECT_TRUE(sut->identity() == "identity"); +} + +TEST_F(PgAuthIdentityTest, hasProvider) { + initCached(); + EXPECT_TRUE(sut->provider() == "provider"); +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp new file mode 100644 index 0000000..6ce1025 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthToken.cpp @@ -0,0 +1,82 @@ +#include + +#include + +#include +#include + +#include +#include + +#include "DbTestBase.hpp" + + +class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > { + public: + PgAuthTokenTest() { + using namespace testing; + db().native()->start_transaction(); + + authInfoId = 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; + + sutId = db()(sqlpp::postgresql::insert_into(t_auth_token) // + .set( // + t_auth_token.auth_info_id = authInfoId, // + t_auth_token.expires = std::chrono::system_clock::now(), // + t_auth_token.role = static_cast< int >(eedb::AuthTokenRole::Auth), // + t_auth_token.value = "empty") // + .returning(t_auth_token.id)) + .front() + .id; + + sut = std::make_unique< eedb::PgAuthToken >(db(), sutId); + } + + void setExpireDate(std::chrono::system_clock::time_point exp) { + using namespace std::chrono; + db()(update(t_auth_token).set(t_auth_token.expires = time_point_cast< microseconds >(exp)).where(t_auth_token.id == sutId)); + } + + ~PgAuthTokenTest() { + db().native()->rollback_transaction(false); + } + + protected: + int64_t authInfoId; + int64_t sutId; + std::unique_ptr< eedb::PgAuthToken > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgAuthTokenTest >::_test_db = {}; + +using namespace sqlpp; +using namespace std::chrono; + +TEST_F(PgAuthTokenTest, isExpired) { + setExpireDate(system_clock::now() - hours{1}); + EXPECT_TRUE(sut->expired()); +} + +TEST_F(PgAuthTokenTest, isNotExpired) { + setExpireDate(system_clock::now() + hours{1}); + EXPECT_FALSE(sut->expired()); +} + +TEST_F(PgAuthTokenTest, validValue) { + EXPECT_EQ(sut->token(), "empty"); +} + +TEST_F(PgAuthTokenTest, updateValue) { + sut->update("NEW"); + EXPECT_EQ(sut->token(), "NEW"); +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp new file mode 100644 index 0000000..1845df8 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgAuthTokens.cpp @@ -0,0 +1,105 @@ +#include + +#include + +#include +#include +#include + +#include +#include + +#include "DbTestBase.hpp" + +namespace { +class UserMock : public eedb::User { + public: + MOCK_CONST_METHOD0(uid, int()); + const eedb::UserName & name() const {} + const eedb::UserConfig & config() const override {} + eedb::AuthTokens & authTokens() const override {} + void logout() override {} + eedb::AuthIdentities & authIdentities() const {} + int64_t _uid; + + // User interface + public: + eedb::AuthInfo & authInfo() const override {} +}; +} // namespace + +class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > { + public: + PgAuthTokensTest() { + using namespace testing; + db().native()->start_transaction(); + + authInfoId = 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; + + EXPECT_CALL(user, uid()).WillRepeatedly(testing::Return(authInfoId)); + sut = std::make_unique< eedb::PgAuthTokens >(db(), &user); + } + + void createToken(std::string hash, eedb::AuthTokenRole role) { + db()(sqlpp::postgresql::insert_into(t_auth_token) // + .set( // + t_auth_token.value = hash, // + t_auth_token.auth_info_id = authInfoId, // + t_auth_token.role = static_cast< int16_t >(role), // + t_auth_token.expires = std::chrono::system_clock::now() + std::chrono::hours{1})); + } + + ~PgAuthTokensTest() { + db().native()->rollback_transaction(false); + } + + protected: + UserMock user; + int64_t authInfoId{0}; + std::unique_ptr< eedb::PgAuthTokens > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgAuthTokensTest >::_test_db = {}; + +using namespace sqlpp; +using namespace eedb; + +TEST_F(PgAuthTokensTest, authTokenFound) { + createToken("token", AuthTokenRole::Auth); + EXPECT_TRUE(sut->find("token")); +} + +TEST_F(PgAuthTokensTest, emailTokenFound) { + createToken("emailtoken", AuthTokenRole::EmailToken); + EXPECT_TRUE(sut->find(AuthTokenRole::EmailToken)); +} + +TEST_F(PgAuthTokensTest, tokenNotFound) { + EXPECT_FALSE(sut->find("token")); +} + +TEST_F(PgAuthTokensTest, addMultipleAuthTokens) { + sut->addToken("authtoken1", eedb::AuthTokenRole::Auth); + sut->addToken("authtoken2", eedb::AuthTokenRole::Auth); + + EXPECT_TRUE(sut->find("authtoken1")); + EXPECT_TRUE(sut->find("authtoken2")); +} + +TEST_F(PgAuthTokensTest, removeToken) { + sut->addToken("authtoken1", eedb::AuthTokenRole::Auth); + sut->addToken("authtoken2", eedb::AuthTokenRole::Auth); + + sut->removeToken("authtoken1"); + EXPECT_FALSE(sut->find("authtoken1")); +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp new file mode 100644 index 0000000..bafd4fa --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategories.cpp @@ -0,0 +1,22 @@ +#include + +#include "DbTestBase.hpp" + +class PgCategoriesTest : public DbTestBase< PgCategoriesTest > { + public: + PgCategoriesTest() { + db().native()->start_transaction(); + +// sut = std::make_unique< eedb::PgCategories >(); + } + + ~PgCategoriesTest() { + db().native()->rollback_transaction(false); + } + + private: + std::unique_ptr< eedb::PgCategories > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesTest >::_test_db = {}; diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp new file mode 100644 index 0000000..90047de --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategoriesRepository.cpp @@ -0,0 +1,30 @@ +#include + +#include + +#include "DbTestBase.hpp" + +class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest > { + public: + PgCategoriesRepositoryTest() { + db().native()->start_transaction(); + sut = std::make_unique< eedb::PgCategoriesRepository >(db(), static_cast< eedb::User * >(nullptr)); + } + + ~PgCategoriesRepositoryTest() { + db().native()->rollback_transaction(false); + } + + protected: + std::unique_ptr< eedb::PgCategoriesRepository > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesRepositoryTest >::_test_db = {}; + +TEST_F(PgCategoriesRepositoryTest, rootNotNull) { + auto root = sut->root(); + ASSERT_TRUE(root); +// EXPECT_FALSE(root->detached()); + EXPECT_FALSE(root->parent()); +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp new file mode 100644 index 0000000..2c3982a --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgCategory.cpp @@ -0,0 +1,75 @@ +#include + +#include "DbTestBase.hpp" +#include + +#include +#include +#include + +#include +#include + +class PgCategoryTest : public DbTestBase< PgCategoryTest > { + public: + PgCategoryTest() { + db().native()->start_transaction(); + + eedb::PgUsers(db()) // + .addUser( // + std::make_unique< eedb::AuthInfoConst >(eedb::Password{"", "", ""}, // + eedb::Email{"root@eedb.pl"}), + std::make_unique< eedb::AuthIdentityConst >("root", "loginname")); + + user = eedb::PgUsers(db()).findWith(eedb::AuthIdentityConst{"root", "loginname"}); + sut = std::make_unique< eedb::PgCategory >(db(), user.get()); + } + + auto insertCategory(std::string name, int64_t parentId) { + db()(sqlpp::postgresql::insert_into(t_category) + .set(t_category.name = name, t_category.parent_id = sqlpp::tvin(parentId)) + .returning(t_category.id)); + } + + ~PgCategoryTest() { + db().native()->rollback_transaction(false); + } + + protected: + std::unique_ptr< eedb::User> user; + std::unique_ptr< eedb::PgCategory > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoryTest >::_test_db = {}; + +TEST_F(PgCategoryTest, rootCategoryHasNoParent) { + EXPECT_FALSE(sut->parent()); +} + +//TEST_F(PgCategoryTest, rootCategoryIsNotDetached) { +// EXPECT_FALSE(sut->detached()); +//} + +TEST_F(PgCategoryTest, createChild) { + sut->create("name", "description"); + + EXPECT_EQ(sut->children()->size(), 1); +} + +TEST_F(PgCategoryTest, getChildren) { + auto children = sut->children(); + ASSERT_TRUE(children); + EXPECT_EQ(children->size(), 0); +} + +TEST_F(PgCategoryTest, childHasParent ) { + sut->create("name1", "description"); + sut->create("name2", "description"); + + auto children = sut->children(); + EXPECT_EQ(children->size(), 2); + for(auto child : *children) { + EXPECT_EQ(child->parent(), sut.get()); + } +} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp new file mode 100644 index 0000000..bfd29c2 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUser.cpp @@ -0,0 +1,70 @@ +#include + +#include +#include +#include + +#include +#include + +#include "DbTestBase.hpp" + +#include + +class PgUserTest : public DbTestBase< PgUserTest > { + public: + PgUserTest() { + db().native()->start_transaction(); + + auto info_ = std::make_unique< eedb::AuthInfoConst >( + eedb::Password{"bcrypt", "OM/Z1c4WBFXvwkxh", "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q"}, + eedb::Email{"email@eedb.pl"}); + auto identity_ = std::make_unique< eedb::AuthIdentityConst >("name", "loginname"); + + const auto & pass = info_->password(); + const auto & email = info_->email(); + + uid = // + db()(sqlpp::postgresql::insert_into(t_auth_info) + .set( // + t_auth_info.password_hash = pass.value(), // + t_auth_info.password_method = pass.function(), // + t_auth_info.password_salt = pass.salt(), // + t_auth_info.email = std::string{email.address()}, + t_auth_info.status = 0) + .returning(t_auth_info.id)) + .front() + .id; + + db()(insert_into(t_auth_identity) + .set( // + t_auth_identity.auth_info_id = uid, // + t_auth_identity.identity = std::string{identity_->identity()}, + t_auth_identity.provider = std::string{identity_->provider()})); + + sut = std::make_unique< eedb::PgUser >(db(), uid); + } + + ~PgUserTest() { + db().native()->rollback_transaction(false); + } + + protected: + int64_t uid; + std::unique_ptr< eedb::PgUser > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgUserTest >::_test_db = {}; + +using namespace sqlpp; + +TEST_F(PgUserTest, readAllAuthInfoData) { + EXPECT_EQ(sut->uid(), uid); +} + +TEST_F(PgUserTest, getIdentities) { + EXPECT_TRUE(sut->authIdentities().byProvider("loginname")); +} + +TEST_F(PgUserTest, getTokens) {} diff --git a/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp new file mode 100644 index 0000000..e0f1b96 --- /dev/null +++ b/src/libs/db/postgresql_connector/test/test_eedb_data_PgUsers.cpp @@ -0,0 +1,132 @@ +#include + +#include +#include + +#include +#include + +#include "DbTestBase.hpp" + +class PgUsersTest : public DbTestBase< PgUsersTest > { + public: + PgUsersTest() { + sut = std::make_unique< eedb::PgUsers >(db()); + db().native()->start_transaction(); + } + + ~PgUsersTest() { + db().native()->rollback_transaction(false); + } + + auto createUser(std::string name, std::string email) { + auto info_ = std::make_unique< eedb::AuthInfoConst >( + eedb::Password{"bcrypt", "OM/Z1c4WBFXvwkxh", "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q"}, eedb::Email{email}); + auto identity_ = std::make_unique< eedb::AuthIdentityConst >(name, "loginname"); + return sut->addUser(std::move(info_), std::move(identity_)); + } + + auto createTestUsers() { + createUser("test_user_1", "test_user_1@eedb.pl"); + createUser("test_user_2", "test_user_2@eedb.pl"); + createUser("test_user_3", "test_user_3@eedb.pl"); + createUser("test_user_4", "test_user_4@eedb.pl"); + createUser("test_user_5", "test_user_5@eedb.pl"); + createUser("test_user_6", "test_user_6@eedb.pl"); + } + + auto idMap() { + std::map< std::string, int64_t > _userIdMap; + auto ids = db()( // + select(t_auth_info.id, t_auth_identity.identity) + .from(t_auth_info // + .inner_join(t_auth_identity) + .on(t_auth_identity.auth_info_id == t_auth_info.id)) + .unconditionally()); + + for(const auto & row : ids) { + _userIdMap[row.identity] = row.id; + } + + return _userIdMap; + } + + protected: + std::unique_ptr< eedb::PgUsers > sut; +}; + +template <> +std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgUsersTest >::_test_db = {}; + +using namespace sqlpp; + +TEST_F(PgUsersTest, createValidUser) { + auto info_ = std::make_unique< eedb::AuthInfoConst >( + eedb::Password{"bcrypt", "OM/Z1c4WBFXvwkxh", "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q"}, + eedb::Email{"none@eedb.pl"}); + auto identity_ = std::make_unique< eedb::AuthIdentityConst >("username", "loginname"); + + auto new_user = sut->addUser(std::move(info_), std::move(identity_)); + ASSERT_TRUE(new_user); + + auto info = db()(select(sqlpp::all_of(t_auth_info)).from(t_auth_info).where(t_auth_info.id == new_user->uid())); + EXPECT_FALSE(info.empty()); + + EXPECT_EQ(info.front().password_hash, "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q"); + EXPECT_EQ(info.front().password_method, "bcrypt"); + EXPECT_EQ(info.front().password_salt, "OM/Z1c4WBFXvwkxh"); + EXPECT_EQ(info.front().email, "none@eedb.pl"); + EXPECT_EQ(info.front().status.value(), 0); /// ODO status:Waiting for verification + EXPECT_EQ(info.front().id.value(), new_user->uid()); + + auto identity = db()(select(t_auth_identity.provider, t_auth_identity.identity) + .from(t_auth_identity) + .where(t_auth_identity.auth_info_id == info.front().id)); + + EXPECT_EQ(identity.front().provider, "loginname"); + EXPECT_EQ(identity.front().identity, "username"); +} + +TEST_F(PgUsersTest, createSameUserMustFail) { + createUser("_test_user_", "test_email@eedb.pl"); + EXPECT_THROW(createUser("_test_user_", "test_email@eedb.pl"), sqlpp::postgresql::integrity_constraint_violation); +} + +TEST_F(PgUsersTest, createWithSameEmailMustFail) { + createUser("_test_user_1", "test_email@eedb.pl"); + EXPECT_THROW(createUser("_test_user_2", "test_email@eedb.pl"), sqlpp::postgresql::integrity_constraint_violation); +} + +TEST_F(PgUsersTest, findById) { + createTestUsers(); + auto id = idMap().at("test_user_1"); + + auto u = sut->findWith(id); + ASSERT_TRUE(u); + EXPECT_EQ(id, u->uid()); +} + +TEST_F(PgUsersTest, findByIdentity) { + createTestUsers(); + + auto u = sut->findWith(eedb::AuthIdentityConst{"test_user_1", "loginname"}); + ASSERT_TRUE(u); + EXPECT_EQ(idMap().at("test_user_1"), u->uid()); +} + +TEST_F(PgUsersTest, findByEmail) { + createTestUsers(); + + auto u = sut->findWith(eedb::Email{"test_user_5@eedb.pl"}); + ASSERT_TRUE(u); + EXPECT_EQ(idMap().at("test_user_5"), u->uid()); +} + +TEST_F(PgUsersTest, removeUser) { + createTestUsers(); + + auto u = sut->findWith(eedb::AuthIdentityConst{"test_user_1", "loginname"}); + ASSERT_TRUE(u); + sut->removeUser(std::move(u)); + EXPECT_FALSE(sut->findWith(eedb::AuthIdentityConst{"test_user_1", "loginname"})); +} diff --git a/src/libs/eedb/CMakeLists.txt b/src/libs/eedb/CMakeLists.txt new file mode 100644 index 0000000..5a82474 --- /dev/null +++ b/src/libs/eedb/CMakeLists.txt @@ -0,0 +1,7 @@ +set(LIB eedb) + +add_library(${LIB} src/dummy.cpp) +target_include_directories(${LIB} PUBLIC include) + +set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) +cotire(${LIB}) diff --git a/src/eedb/EEDB.hpp b/src/libs/eedb/include/eedb/EEDB.hpp similarity index 100% rename from src/eedb/EEDB.hpp rename to src/libs/eedb/include/eedb/EEDB.hpp diff --git a/src/eedb/Session.hpp b/src/libs/eedb/include/eedb/Session.hpp similarity index 100% rename from src/eedb/Session.hpp rename to src/libs/eedb/include/eedb/Session.hpp diff --git a/src/eedb/WebSession.hpp b/src/libs/eedb/include/eedb/WebSession.hpp similarity index 100% rename from src/eedb/WebSession.hpp rename to src/libs/eedb/include/eedb/WebSession.hpp diff --git a/src/eedb/data/AuthIdentities.hpp b/src/libs/eedb/include/eedb/data/AuthIdentities.hpp similarity index 100% rename from src/eedb/data/AuthIdentities.hpp rename to src/libs/eedb/include/eedb/data/AuthIdentities.hpp diff --git a/src/eedb/data/AuthIdentitiesConst.hpp b/src/libs/eedb/include/eedb/data/AuthIdentitiesConst.hpp similarity index 100% rename from src/eedb/data/AuthIdentitiesConst.hpp rename to src/libs/eedb/include/eedb/data/AuthIdentitiesConst.hpp diff --git a/src/eedb/data/AuthIdentity.hpp b/src/libs/eedb/include/eedb/data/AuthIdentity.hpp similarity index 100% rename from src/eedb/data/AuthIdentity.hpp rename to src/libs/eedb/include/eedb/data/AuthIdentity.hpp diff --git a/src/eedb/data/AuthIdentityConst.hpp b/src/libs/eedb/include/eedb/data/AuthIdentityConst.hpp similarity index 100% rename from src/eedb/data/AuthIdentityConst.hpp rename to src/libs/eedb/include/eedb/data/AuthIdentityConst.hpp diff --git a/src/eedb/data/AuthInfo.hpp b/src/libs/eedb/include/eedb/data/AuthInfo.hpp similarity index 100% rename from src/eedb/data/AuthInfo.hpp rename to src/libs/eedb/include/eedb/data/AuthInfo.hpp diff --git a/src/eedb/data/AuthInfoConst.hpp b/src/libs/eedb/include/eedb/data/AuthInfoConst.hpp similarity index 100% rename from src/eedb/data/AuthInfoConst.hpp rename to src/libs/eedb/include/eedb/data/AuthInfoConst.hpp diff --git a/src/eedb/data/AuthToken.hpp b/src/libs/eedb/include/eedb/data/AuthToken.hpp similarity index 100% rename from src/eedb/data/AuthToken.hpp rename to src/libs/eedb/include/eedb/data/AuthToken.hpp diff --git a/src/eedb/data/AuthTokenConst.hpp b/src/libs/eedb/include/eedb/data/AuthTokenConst.hpp similarity index 100% rename from src/eedb/data/AuthTokenConst.hpp rename to src/libs/eedb/include/eedb/data/AuthTokenConst.hpp diff --git a/src/eedb/data/AuthTokens.hpp b/src/libs/eedb/include/eedb/data/AuthTokens.hpp similarity index 100% rename from src/eedb/data/AuthTokens.hpp rename to src/libs/eedb/include/eedb/data/AuthTokens.hpp diff --git a/src/eedb/data/Category.hpp b/src/libs/eedb/include/eedb/data/Category.hpp similarity index 87% rename from src/eedb/data/Category.hpp rename to src/libs/eedb/include/eedb/data/Category.hpp index 95464fc..2c7e130 100644 --- a/src/eedb/data/Category.hpp +++ b/src/libs/eedb/include/eedb/data/Category.hpp @@ -72,17 +72,17 @@ class Category { */ virtual Category * parent() const = 0; - /** - * @brief detached - * @return true if category is in detached state (has no parent and is not root category) - */ - virtual bool detached() const = 0; +// /** +// * @brief detached +// * @return true if category is in detached state (has no parent and is not root category) +// */ +// virtual bool detached() const = 0; /** * @brief create * @return category in detached state (not connected to any root category) */ - virtual std::unique_ptr< Category > create(std::string name, std::string description, std::optional< path > image = {}) const = 0; + virtual std::unique_ptr< Category > create(std::string name, std::string description) const = 0; /** * @brief children diff --git a/src/eedb/data/Email.hpp b/src/libs/eedb/include/eedb/data/Email.hpp similarity index 100% rename from src/eedb/data/Email.hpp rename to src/libs/eedb/include/eedb/data/Email.hpp diff --git a/src/libs/eedb/include/eedb/data/Item.hpp b/src/libs/eedb/include/eedb/data/Item.hpp new file mode 100644 index 0000000..dae2f39 --- /dev/null +++ b/src/libs/eedb/include/eedb/data/Item.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include +#include + +#include + +namespace eedb { + +class Category; +class Item; +class Items; +class Values; +class Units; +/** + * @brief The ItemQueryFilters class + */ +class ItemQueryFilters { + public: + virtual ~ItemQueryFilters() = 0; + + /** + * @brief category + * @return null if category is not taken into consideration + */ + virtual Category * category() const = 0; +}; + +/** + * @brief The ItemsRepository class + */ +class ItemsRepository { + public: + virtual ~ItemsRepository() = default; + + virtual std::unique_ptr< Item > create(std::string name, std::unique_ptr< Values > value, std::string description) const = 0; + + /** + * @brief search + * @param filer + * @return Items based on given query + */ + virtual std::unique_ptr< Items > search(const ItemQueryFilters & filer) const = 0; +}; + +/** + * @brief The Items class + */ +class Items { + using Iterable = IteratorTypeErasure::any_iterator< Item *, std::forward_iterator_tag, Item * >; + + public: + virtual ~Items() = default; + + /** + * @brief size + * @return + */ + virtual long size() const = 0; + + /** + * @brief begin + * @return + */ + virtual Iterable begin() const = 0; + + /** + * @brief end + * @return + */ + virtual Iterable end() const = 0; +}; + +/** + * @brief The Item class + */ +class Item { + public: + virtual ~Item() = default; + + virtual std::string_view displayName() const = 0; + + virtual Values & values() const = 0; +}; +} // namespace eedb diff --git a/src/eedb/data/Password.hpp b/src/libs/eedb/include/eedb/data/Password.hpp similarity index 100% rename from src/eedb/data/Password.hpp rename to src/libs/eedb/include/eedb/data/Password.hpp diff --git a/src/eedb/data/StatInfo.hpp b/src/libs/eedb/include/eedb/data/StatInfo.hpp similarity index 100% rename from src/eedb/data/StatInfo.hpp rename to src/libs/eedb/include/eedb/data/StatInfo.hpp diff --git a/src/libs/eedb/include/eedb/data/Unit.hpp b/src/libs/eedb/include/eedb/data/Unit.hpp new file mode 100644 index 0000000..75561ee --- /dev/null +++ b/src/libs/eedb/include/eedb/data/Unit.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace eedb { + +class Units { + public: + virtual ~Units() = default; +}; + +class Unit { + public: + std::string_view name() const; + Unit toBase() const; +}; + +} // namespace eedb diff --git a/src/eedb/data/User.hpp b/src/libs/eedb/include/eedb/data/User.hpp similarity index 100% rename from src/eedb/data/User.hpp rename to src/libs/eedb/include/eedb/data/User.hpp diff --git a/src/eedb/data/Users.hpp b/src/libs/eedb/include/eedb/data/Users.hpp similarity index 100% rename from src/eedb/data/Users.hpp rename to src/libs/eedb/include/eedb/data/Users.hpp diff --git a/src/libs/eedb/include/eedb/data/Value.hpp b/src/libs/eedb/include/eedb/data/Value.hpp new file mode 100644 index 0000000..a86ba85 --- /dev/null +++ b/src/libs/eedb/include/eedb/data/Value.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace eedb { +class Value; +class Values { + public: + virtual ~Values() = default; + +}; + +class Value { + public: +}; +} // namespace eedb diff --git a/src/eedb/EEDB.cpp b/src/libs/eedb/src/EEDB.cpp similarity index 100% rename from src/eedb/EEDB.cpp rename to src/libs/eedb/src/EEDB.cpp diff --git a/src/eedb/WebSession.cpp b/src/libs/eedb/src/WebSession.cpp similarity index 100% rename from src/eedb/WebSession.cpp rename to src/libs/eedb/src/WebSession.cpp diff --git a/src/libs/eedb/src/dummy.cpp b/src/libs/eedb/src/dummy.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/widgets/CMakeLists.txt b/src/libs/widgets/CMakeLists.txt new file mode 100644 index 0000000..102d687 --- /dev/null +++ b/src/libs/widgets/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LIB widgets) + +file(GLOB widget_SOURCE src/*) + +# find packages +#find_package(Wt REQUIRED) + +# create library +add_library(${LIB} ${widget_SOURCE}) + +# link all +target_include_directories(${LIB} PRIVATE include) +target_link_libraries(${LIB} PRIVATE eedb) +target_link_libraries(${LIB} PRIVATE auth) + +# add cotire +set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) +cotire(${LIB}) diff --git a/src/eedb/widgets/AuthPage.hpp b/src/libs/widgets/include/widget/AuthPage.hpp similarity index 100% rename from src/eedb/widgets/AuthPage.hpp rename to src/libs/widgets/include/widget/AuthPage.hpp diff --git a/src/eedb/widgets/BootstrapTheme.hpp b/src/libs/widgets/include/widget/BootstrapTheme.hpp similarity index 85% rename from src/eedb/widgets/BootstrapTheme.hpp rename to src/libs/widgets/include/widget/BootstrapTheme.hpp index f926032..ee3e552 100644 --- a/src/eedb/widgets/BootstrapTheme.hpp +++ b/src/libs/widgets/include/widget/BootstrapTheme.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace eedb { class BootstrapTheme final : public Theme { diff --git a/src/eedb/widgets/CategoryThree.hpp b/src/libs/widgets/include/widget/CategoryThree.hpp similarity index 100% rename from src/eedb/widgets/CategoryThree.hpp rename to src/libs/widgets/include/widget/CategoryThree.hpp diff --git a/src/eedb/widgets/DefaultAuthPage.hpp b/src/libs/widgets/include/widget/DefaultAuthPage.hpp similarity index 96% rename from src/eedb/widgets/DefaultAuthPage.hpp rename to src/libs/widgets/include/widget/DefaultAuthPage.hpp index eec5562..dbce7c0 100644 --- a/src/eedb/widgets/DefaultAuthPage.hpp +++ b/src/libs/widgets/include/widget/DefaultAuthPage.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/eedb/widgets/DefaultCategoryTree.hpp b/src/libs/widgets/include/widget/DefaultCategoryTree.hpp similarity index 91% rename from src/eedb/widgets/DefaultCategoryTree.hpp rename to src/libs/widgets/include/widget/DefaultCategoryTree.hpp index 92cc6c7..8d3ad68 100644 --- a/src/eedb/widgets/DefaultCategoryTree.hpp +++ b/src/libs/widgets/include/widget/DefaultCategoryTree.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/eedb/widgets/DefaultHomePage.hpp b/src/libs/widgets/include/widget/DefaultHomePage.hpp similarity index 94% rename from src/eedb/widgets/DefaultHomePage.hpp rename to src/libs/widgets/include/widget/DefaultHomePage.hpp index 011461f..3fd2c17 100644 --- a/src/eedb/widgets/DefaultHomePage.hpp +++ b/src/libs/widgets/include/widget/DefaultHomePage.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/eedb/widgets/DefaultNavigationBar.hpp b/src/libs/widgets/include/widget/DefaultNavigationBar.hpp similarity index 92% rename from src/eedb/widgets/DefaultNavigationBar.hpp rename to src/libs/widgets/include/widget/DefaultNavigationBar.hpp index 3c229bc..1812521 100644 --- a/src/eedb/widgets/DefaultNavigationBar.hpp +++ b/src/libs/widgets/include/widget/DefaultNavigationBar.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/eedb/widgets/HomePage.hpp b/src/libs/widgets/include/widget/HomePage.hpp similarity index 100% rename from src/eedb/widgets/HomePage.hpp rename to src/libs/widgets/include/widget/HomePage.hpp diff --git a/src/eedb/widgets/NavigationBar.hpp b/src/libs/widgets/include/widget/NavigationBar.hpp similarity index 100% rename from src/eedb/widgets/NavigationBar.hpp rename to src/libs/widgets/include/widget/NavigationBar.hpp diff --git a/src/eedb/widgets/Theme.hpp b/src/libs/widgets/include/widget/Theme.hpp similarity index 100% rename from src/eedb/widgets/Theme.hpp rename to src/libs/widgets/include/widget/Theme.hpp diff --git a/src/libs/widgets/include/widget/model/CategoriesModel.cpp b/src/libs/widgets/include/widget/model/CategoriesModel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/eedb/widgets/models/CategoriesModel.hpp b/src/libs/widgets/include/widget/model/CategoriesModel.hpp similarity index 100% rename from src/eedb/widgets/models/CategoriesModel.hpp rename to src/libs/widgets/include/widget/model/CategoriesModel.hpp diff --git a/src/eedb/widgets/BootstrapTheme.cpp b/src/libs/widgets/src/BootstrapTheme.cpp similarity index 89% rename from src/eedb/widgets/BootstrapTheme.cpp rename to src/libs/widgets/src/BootstrapTheme.cpp index e3dc438..f9c6198 100644 --- a/src/eedb/widgets/BootstrapTheme.cpp +++ b/src/libs/widgets/src/BootstrapTheme.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/eedb/widgets/DefaultAuthPage.cpp b/src/libs/widgets/src/DefaultAuthPage.cpp similarity index 98% rename from src/eedb/widgets/DefaultAuthPage.cpp rename to src/libs/widgets/src/DefaultAuthPage.cpp index 989a6d7..97008ac 100644 --- a/src/eedb/widgets/DefaultAuthPage.cpp +++ b/src/libs/widgets/src/DefaultAuthPage.cpp @@ -1,6 +1,5 @@ - #include -#include +#include #include #include diff --git a/src/eedb/widgets/DefaultCategoryTree.cpp b/src/libs/widgets/src/DefaultCategoryTree.cpp similarity index 93% rename from src/eedb/widgets/DefaultCategoryTree.cpp rename to src/libs/widgets/src/DefaultCategoryTree.cpp index d5a2de4..0ce2398 100644 --- a/src/eedb/widgets/DefaultCategoryTree.cpp +++ b/src/libs/widgets/src/DefaultCategoryTree.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/eedb/widgets/DefaultHomePage.cpp b/src/libs/widgets/src/DefaultHomePage.cpp similarity index 94% rename from src/eedb/widgets/DefaultHomePage.cpp rename to src/libs/widgets/src/DefaultHomePage.cpp index a215567..a2ec5fb 100644 --- a/src/eedb/widgets/DefaultHomePage.cpp +++ b/src/libs/widgets/src/DefaultHomePage.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include namespace eedb { diff --git a/src/eedb/widgets/DefaultNavigationBar.cpp b/src/libs/widgets/src/DefaultNavigationBar.cpp similarity index 97% rename from src/eedb/widgets/DefaultNavigationBar.cpp rename to src/libs/widgets/src/DefaultNavigationBar.cpp index 45aaf6f..4cb1fbd 100644 --- a/src/eedb/widgets/DefaultNavigationBar.cpp +++ b/src/libs/widgets/src/DefaultNavigationBar.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/tests/unit/db/test_eedb_data_PgCategoriesRepository.cpp b/tests/unit/db/test_eedb_data_PgCategoriesRepository.cpp index ea05d67..bd1cc8a 100644 --- a/tests/unit/db/test_eedb_data_PgCategoriesRepository.cpp +++ b/tests/unit/db/test_eedb_data_PgCategoriesRepository.cpp @@ -25,6 +25,6 @@ std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesRepositoryTest TEST_F(PgCategoriesRepositoryTest, rootNotNull) { auto root = sut->root(); ASSERT_TRUE(root); - EXPECT_FALSE(root->detached()); +// EXPECT_FALSE(root->detached()); EXPECT_FALSE(root->parent()); } diff --git a/tests/unit/db/test_eedb_data_PgCategory.cpp b/tests/unit/db/test_eedb_data_PgCategory.cpp index b8bea9b..d0f1d3f 100644 --- a/tests/unit/db/test_eedb_data_PgCategory.cpp +++ b/tests/unit/db/test_eedb_data_PgCategory.cpp @@ -47,9 +47,9 @@ TEST_F(PgCategoryTest, rootCategoryHasNoParent) { EXPECT_FALSE(sut->parent()); } -TEST_F(PgCategoryTest, rootCategoryIsNotDetached) { - EXPECT_FALSE(sut->detached()); -} +//TEST_F(PgCategoryTest, rootCategoryIsNotDetached) { +// EXPECT_FALSE(sut->detached()); +//} TEST_F(PgCategoryTest, createChild) { sut->create("name", "description"); @@ -62,3 +62,14 @@ TEST_F(PgCategoryTest, getChildren) { ASSERT_TRUE(children); EXPECT_EQ(children->size(), 0); } + +TEST_F(PgCategoryTest, childHasParent ) { + sut->create("name1", "description"); + sut->create("name2", "description"); + + auto children = sut->children(); + EXPECT_EQ(children->size(), 2); + for(auto child : *children) { + EXPECT_EQ(child->parent(), sut.get()); + } +} diff --git a/tests/unit/test_eedb_Item.cpp b/tests/unit/test_eedb_Item.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_eedb_Items.cpp b/tests/unit/test_eedb_Items.cpp new file mode 100644 index 0000000..e69de29