From 6dc7b31ab6ea3f79896ac287038b169bc9601956 Mon Sep 17 00:00:00 2001 From: sabudilovskiy Date: Fri, 27 Oct 2023 17:44:31 +0000 Subject: [PATCH] - --- .gen/objs.txt | 4 - configs/static_config.yaml.in | 5 -- service/main.cpp | 2 - src/codegen/sql.cpp | 38 ++++++++++ src/codegen/sql.hpp | 6 ++ .../controllers/postgres/admin/controller.hpp | 4 + src/legacy/views/timetable/get/Request.hpp | 23 ------ src/legacy/views/timetable/get/Responses.hpp | 35 --------- src/legacy/views/timetable/get/view.cpp | 74 ------------------- src/legacy/views/timetable/get/view.hpp | 7 -- src/models/admin_account/postgre.hpp | 11 +++ src/models/admin_account/type.hpp | 15 ++++ src/openapi/base/reflective/checks.hpp | 27 +++++-- src/openapi/doc/int.hpp | 4 +- .../admin/get_admin_account_by_admin_id.sql | 8 ++ src/sql/admin/get_admins_by_filter.sql | 17 +++++ src/utils/constexpr_string.hpp | 1 - 17 files changed, 122 insertions(+), 159 deletions(-) delete mode 100644 src/legacy/views/timetable/get/Request.hpp delete mode 100644 src/legacy/views/timetable/get/Responses.hpp delete mode 100644 src/legacy/views/timetable/get/view.cpp delete mode 100644 src/legacy/views/timetable/get/view.hpp create mode 100644 src/models/admin_account/postgre.hpp create mode 100644 src/models/admin_account/type.hpp create mode 100644 src/sql/admin/get_admin_account_by_admin_id.sql create mode 100644 src/sql/admin/get_admins_by_filter.sql diff --git a/.gen/objs.txt b/.gen/objs.txt index 9e392b7f..7605d78a 100644 --- a/.gen/objs.txt +++ b/.gen/objs.txt @@ -170,10 +170,6 @@ src/models/lesson_v1/type.hpp src/models/lesson_filter/type.hpp src/models/lesson_filter/postgres.hpp src/models/error_v1/type.hpp -src/legacy/views/timetable/get/view.hpp -src/legacy/views/timetable/get/view.cpp -src/legacy/views/timetable/get/Responses.hpp -src/legacy/views/timetable/get/Request.hpp src/legacy/views/teacher/request/list/view.hpp src/legacy/views/teacher/request/list/view.cpp src/legacy/views/teacher/request/list/Responses.hpp diff --git a/configs/static_config.yaml.in b/configs/static_config.yaml.in index 3d628cc4..33139254 100644 --- a/configs/static_config.yaml.in +++ b/configs/static_config.yaml.in @@ -53,11 +53,6 @@ components_manager: path: /tests/{action} method: POST task_processor: main-task-processor - handler-timetable-get: - load-enabled: false - path: /timetable/get - method: POST - task_processor: main-task-processor handler-admin-create: path: /admin/create method: POST diff --git a/service/main.cpp b/service/main.cpp index 7da97994..1cd269f2 100644 --- a/service/main.cpp +++ b/service/main.cpp @@ -33,7 +33,6 @@ #include "legacy/views/teacher/request/approve/link/view.hpp" #include "legacy/views/teacher/request/approve/new/view.hpp" #include "legacy/views/teacher/request/list/view.hpp" -#include "legacy/views/timetable/get/view.hpp" #include "views/login/view.hpp" #include "views/register/view.hpp" #include "views/timetable/view.hpp" @@ -54,7 +53,6 @@ void AppendLegacyPgControllers( void AppendLegacyViews(userver::components::ComponentList& component_list) { using namespace legacy::views; - timetable::get::Append(component_list); admin::create::Append(component_list); admin::list::Append(component_list); teacher::list::Append(component_list); diff --git a/src/codegen/sql.cpp b/src/codegen/sql.cpp index 20adc144..b30e694e 100644 --- a/src/codegen/sql.cpp +++ b/src/codegen/sql.cpp @@ -232,4 +232,42 @@ FROM all_user; userver::storages::postgres::Query::Name("get_user_by_credentials"), userver::storages::postgres::Query::LogMode::kFull}; +// Generated from: src/sql/admin/get_admins_by_filter.sql +const userver::storages::postgres::Query get_admins_by_filter = { + R"-( +WITH admin_info as (SELECT + a.id AS admin_id, + a.id_user AS user_id, + u.login AS login + FROM timetable_vsu.admin AS a + LEFT JOIN timetable_vsu.user AS u ON a.id_user = u.id + ) + SELECT + user_id, + admin_id, + login + FROM admin_info + WHERE + ($1.admin_ids IS null OR admin_id::text ILIKE ANY($1.admin_ids)) and + ($1.user_ids IS null OR user_id::text ILIKE ANY($1.user_ids)) and + ($1.logins IS null OR login ILIKE ANY($1.logins)) + ;)-", + userver::storages::postgres::Query::Name("get_admins_by_filter"), + userver::storages::postgres::Query::LogMode::kFull}; + +// Generated from: src/sql/admin/get_admin_account_by_admin_id.sql +const userver::storages::postgres::Query get_admin_account_by_admin_id = { + R"-( +SELECT + u.id AS user_id, + a.id AS admin_id, + u.login AS user_login +FROM timetable_vsu."admin" AS a +LEFT JOIN timetable_vsu."user" AS u ON u.id = a.id_user +WHERE a.id = $1 +; +)-", + userver::storages::postgres::Query::Name("get_admin_account_by_admin_id"), + userver::storages::postgres::Query::LogMode::kFull}; + } // namespace sql diff --git a/src/codegen/sql.hpp b/src/codegen/sql.hpp index eb3e0556..4d51502c 100644 --- a/src/codegen/sql.hpp +++ b/src/codegen/sql.hpp @@ -39,4 +39,10 @@ extern const userver::storages::postgres::Query add_user; // Generated from: src/sql/user/get_user_by_credentials.sql extern const userver::storages::postgres::Query get_user_by_credentials; +// Generated from: src/sql/admin/get_admins_by_filter.sql +extern const userver::storages::postgres::Query get_admins_by_filter; + +// Generated from: src/sql/admin/get_admin_account_by_admin_id.sql +extern const userver::storages::postgres::Query get_admin_account_by_admin_id; + } // namespace sql diff --git a/src/legacy/components/controllers/postgres/admin/controller.hpp b/src/legacy/components/controllers/postgres/admin/controller.hpp index 925e6262..b81994d2 100644 --- a/src/legacy/components/controllers/postgres/admin/controller.hpp +++ b/src/legacy/components/controllers/postgres/admin/controller.hpp @@ -20,14 +20,18 @@ class Controller final : public userver::components::LoggableComponentBase std::optional GetAccountByAdminId( const boost::uuids::uuid& admin_id, utils::SharedTransaction transaction = nullptr) const; + std::optional CreateAdmin( const legacy::models::UserCredentials& user, utils::SharedTransaction transaction = nullptr) const; + Controller(const userver::components::ComponentConfig& config, const userver::components::ComponentContext& context); + std::vector GetByFilter( std::optional& filter, utils::SharedTransaction transaction = nullptr) const; + utils::SharedTransaction CreateTransaction() const; protected: diff --git a/src/legacy/views/timetable/get/Request.hpp b/src/legacy/views/timetable/get/Request.hpp deleted file mode 100644 index cf4b126f..00000000 --- a/src/legacy/views/timetable/get/Request.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include - -#include "legacy/models/lesson_filter/type.hpp" -#include "legacy/models/substring/parse.hpp" - -namespace legacy::views::timetable::get -{ -using namespace utils::convert; -struct Request -{ - OptionalProperty filter; - static constexpr TypeOfBody kTypeOfBody = TypeOfBody::Json; - static constexpr PolicyFields kPolicyFields = PolicyFields::ConvertAll; -}; -} // namespace legacy::views::timetable::get diff --git a/src/legacy/views/timetable/get/Responses.hpp b/src/legacy/views/timetable/get/Responses.hpp deleted file mode 100644 index 0d5b5483..00000000 --- a/src/legacy/views/timetable/get/Responses.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "http/ErrorV1.hpp" -#include "legacy/models/lesson_v1/type.hpp" -#include "legacy/models/user_type/type.hpp" - -namespace legacy::views::timetable::get -{ -using namespace utils::convert; -struct Response200 -{ - ArrayProperty lessons; - static constexpr TypeOfBody kTypeOfBody = TypeOfBody::Json; - static constexpr PolicyFields kPolicyFields = PolicyFields::ConvertAll; - static constexpr userver::server::http::HttpStatus kStatusCode = - userver::server::http::HttpStatus::kOk; -}; - -static_assert(userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, legacy::models::LessonV1>); -static_assert( - userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, std::vector>); - -} // namespace legacy::views::timetable::get diff --git a/src/legacy/views/timetable/get/view.cpp b/src/legacy/views/timetable/get/view.cpp deleted file mode 100644 index 95222ca6..00000000 --- a/src/legacy/views/timetable/get/view.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "view.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Request.hpp" -#include "Responses.hpp" -#include "http/handler_parsed.hpp" -#include "legacy/components/controllers/postgres/lesson/controller.hpp" -#include "legacy/models/day/all.hpp" -#include "legacy/models/education_type/all.hpp" -#include "legacy/models/lesson_v1/parse.hpp" -#include "legacy/models/lesson_v1/serialize.hpp" -#include "legacy/models/user_type/type.hpp" - -static_assert(userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, ::legacy::models::LessonType>); -namespace legacy::views::timetable::get -{ -namespace -{ -namespace pg = legacy::components::controllers::postgres; -class Handler final : public http::HandlerParsed -{ - public: - static constexpr std::string_view kName = "handler-timetable-get"; - Handler(const userver::components::ComponentConfig& config, - const userver::components::ComponentContext& context) - : HandlerParsed(config, context), - lesson_controller(context.FindComponent()) - { - } - static void ValidateBeginEnd(Request& request) - { - if (request.filter() and request.filter()->begin() and - request.filter()->end() && - request.filter()->begin().value() > request.filter()->end().value()) - { - std::swap(request.filter()->begin().value(), - request.filter()->end().value()); - } - } - Response Handle(Request&& request) const override - { - Response200 resp; - ValidateBeginEnd(request); - resp.lessons() = lesson_controller.Search(request.filter()); - return resp; - } - - private: - const pg::lesson::Controller& lesson_controller; -}; -} // namespace - -void Append(userver::components::ComponentList& component_list) -{ - component_list.Append(); -} - -} // namespace legacy::views::timetable::get diff --git a/src/legacy/views/timetable/get/view.hpp b/src/legacy/views/timetable/get/view.hpp deleted file mode 100644 index ae374732..00000000 --- a/src/legacy/views/timetable/get/view.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include -namespace legacy::views::timetable::get -{ -void Append(userver::components::ComponentList& component_list); - -} diff --git a/src/models/admin_account/postgre.hpp b/src/models/admin_account/postgre.hpp new file mode 100644 index 00000000..1d5753e5 --- /dev/null +++ b/src/models/admin_account/postgre.hpp @@ -0,0 +1,11 @@ +#pragma once +#include +#include +#include "userver/storages/postgres/io/pg_types.hpp" + +namespace userver::storages::postgres::io{ + template <> + struct CppToPg{ + static constexpr DBTypeName postgres_name = "timetable_vsu.admin_account"; + }; +} \ No newline at end of file diff --git a/src/models/admin_account/type.hpp b/src/models/admin_account/type.hpp new file mode 100644 index 00000000..65464437 --- /dev/null +++ b/src/models/admin_account/type.hpp @@ -0,0 +1,15 @@ +#pragma once +#include +#include + +namespace models{ + using namespace openapi::types; + using namespace openapi::preferences; + struct AdminAccount + { + Uuid> user_id; + Uuid> admin_id; + String> credentials; + auto operator<=>(const AdminAccount&) const = default; + }; +} \ No newline at end of file diff --git a/src/openapi/base/reflective/checks.hpp b/src/openapi/base/reflective/checks.hpp index c1e72272..0babeacc 100644 --- a/src/openapi/base/reflective/checks.hpp +++ b/src/openapi/base/reflective/checks.hpp @@ -3,20 +3,35 @@ #include #include #include +#include +#include namespace openapi { namespace checks { -template -concept IsReflectiveHelper = requires +namespace details { - requires(IsProperty> && ...); -}; +template +consteval bool is_fields_property_idxs(std::integer_sequence) +{ + return (IsProperty> && ...); +} + +template +requires std::is_aggregate_v consteval bool is_fields_property_helper() +{ + auto seq = std::make_index_sequence>{}; + return is_fields_property_idxs(seq); +} +} // namespace details + +template +concept is_fields_property = details::is_fields_property_helper(); template -concept IsReflective = - std::is_class_v&& std::is_aggregate_v && !IsProperty; +concept IsReflective = std::is_class_v&& std::is_aggregate_v && + !IsProperty && is_fields_property; template constexpr bool is_reflective_v = IsReflective; diff --git a/src/openapi/doc/int.hpp b/src/openapi/doc/int.hpp index 6226b7d6..e37a1459 100644 --- a/src/openapi/doc/int.hpp +++ b/src/openapi/doc/int.hpp @@ -1,13 +1,13 @@ #pragma once #include + #include #include #include namespace openapi { -inline void Append( - DocHelper doc_helper, std::type_identity) +inline void Append(DocHelper doc_helper, std::type_identity) { auto& cur = doc_helper.cur_place; if (cur.IsObject()) diff --git a/src/sql/admin/get_admin_account_by_admin_id.sql b/src/sql/admin/get_admin_account_by_admin_id.sql new file mode 100644 index 00000000..82a9936d --- /dev/null +++ b/src/sql/admin/get_admin_account_by_admin_id.sql @@ -0,0 +1,8 @@ +SELECT + u.id AS user_id, + a.id AS admin_id, + u.login AS user_login +FROM timetable_vsu."admin" AS a +LEFT JOIN timetable_vsu."user" AS u ON u.id = a.id_user +WHERE a.id = $1 +; diff --git a/src/sql/admin/get_admins_by_filter.sql b/src/sql/admin/get_admins_by_filter.sql new file mode 100644 index 00000000..3dfcbead --- /dev/null +++ b/src/sql/admin/get_admins_by_filter.sql @@ -0,0 +1,17 @@ +WITH admin_info as (SELECT + a.id AS admin_id, + a.id_user AS user_id, + u.login AS login + FROM timetable_vsu.admin AS a + LEFT JOIN timetable_vsu.user AS u ON a.id_user = u.id + ) + SELECT + user_id, + admin_id, + login + FROM admin_info + WHERE + ($1.admin_ids IS null OR admin_id::text ILIKE ANY($1.admin_ids)) and + ($1.user_ids IS null OR user_id::text ILIKE ANY($1.user_ids)) and + ($1.logins IS null OR login ILIKE ANY($1.logins)) + ; diff --git a/src/utils/constexpr_string.hpp b/src/utils/constexpr_string.hpp index 858cf378..a401cf46 100644 --- a/src/utils/constexpr_string.hpp +++ b/src/utils/constexpr_string.hpp @@ -2,7 +2,6 @@ #include #include #include -#include namespace utils {