diff --git a/Makefile b/Makefile index fa74fe33..0bc67446 100644 --- a/Makefile +++ b/Makefile @@ -200,8 +200,8 @@ gen: $(MAKE) gen-sources $(MAKE) gen-all-headers -.PHONY: build-log -build-log: +.PHONY: log-build +log-build: $(MAKE) -s test-debug > log_build.txt 2>&1 # # Internal hidden targets that are used only in docker environment diff --git a/src/controllers/lesson/controller.cpp b/src/controllers/lesson/controller.cpp index 9665f1c3..8b10815b 100644 --- a/src/controllers/lesson/controller.cpp +++ b/src/controllers/lesson/controller.cpp @@ -27,6 +27,7 @@ #include "legacy/models/lesson_week_type/postgre.hpp" #include "legacy/models/subgroup/postgre.hpp" #include "models/user_credentials/postgres.hpp" +#include "legacy/models/substring/postgre.hpp" namespace controllers::lesson { diff --git a/src/legacy/components/controllers/postgres/admin/controller.cpp b/src/legacy/components/controllers/postgres/admin/controller.cpp index 86ab8c03..c1364e8f 100644 --- a/src/legacy/components/controllers/postgres/admin/controller.cpp +++ b/src/legacy/components/controllers/postgres/admin/controller.cpp @@ -24,6 +24,7 @@ #include "legacy/models/admin_account/type.hpp" #include "legacy/models/admin_filter/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" +#include "legacy/models/substring/postgre.hpp" #include "sql_queries.hpp" namespace legacy::components::controllers::postgres::admin diff --git a/src/legacy/components/controllers/postgres/faculty/controller.cpp b/src/legacy/components/controllers/postgres/faculty/controller.cpp index 02031cab..e134b0d8 100644 --- a/src/legacy/components/controllers/postgres/faculty/controller.cpp +++ b/src/legacy/components/controllers/postgres/faculty/controller.cpp @@ -31,6 +31,7 @@ #include "legacy/models/substring/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::faculty { diff --git a/src/legacy/components/controllers/postgres/group_stage/controller.cpp b/src/legacy/components/controllers/postgres/group_stage/controller.cpp index 87b72f19..997d0d5e 100644 --- a/src/legacy/components/controllers/postgres/group_stage/controller.cpp +++ b/src/legacy/components/controllers/postgres/group_stage/controller.cpp @@ -31,6 +31,7 @@ #include "legacy/models/substring/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::group_stage { diff --git a/src/legacy/components/controllers/postgres/lesson/controller.cpp b/src/legacy/components/controllers/postgres/lesson/controller.cpp index 3f9f9d97..2c14290f 100644 --- a/src/legacy/components/controllers/postgres/lesson/controller.cpp +++ b/src/legacy/components/controllers/postgres/lesson/controller.cpp @@ -23,6 +23,7 @@ #include "legacy/models/lesson_v1/postgre.hpp" #include "legacy/models/lesson_v1/type.hpp" #include "sql_queries.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::lesson { diff --git a/src/legacy/components/controllers/postgres/teacher/controller.cpp b/src/legacy/components/controllers/postgres/teacher/controller.cpp index aa46f8d2..e7fa6e77 100644 --- a/src/legacy/components/controllers/postgres/teacher/controller.cpp +++ b/src/legacy/components/controllers/postgres/teacher/controller.cpp @@ -32,6 +32,7 @@ #include "legacy/models/teacher_info/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::teacher { diff --git a/src/legacy/components/controllers/postgres/token/controller.cpp b/src/legacy/components/controllers/postgres/token/controller.cpp index d35ca916..012d03d0 100644 --- a/src/legacy/components/controllers/postgres/token/controller.cpp +++ b/src/legacy/components/controllers/postgres/token/controller.cpp @@ -20,6 +20,7 @@ #include "legacy/models/user/type.hpp" #include "legacy/models/user_type/postgre.hpp" #include "sql_queries.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::token { diff --git a/src/legacy/components/controllers/postgres/user/controller.cpp b/src/legacy/components/controllers/postgres/user/controller.cpp index 3fefd674..211684ef 100644 --- a/src/legacy/components/controllers/postgres/user/controller.cpp +++ b/src/legacy/components/controllers/postgres/user/controller.cpp @@ -26,6 +26,7 @@ #include "legacy/models/user/postgre.hpp" #include "legacy/models/user/type.hpp" #include "legacy/models/user_credentials/postgre.hpp" +#include "legacy/models/substring/postgre.hpp" namespace legacy::components::controllers::postgres::user { diff --git a/src/legacy/models/substring/parse.cpp b/src/legacy/models/substring/parse.cpp index 22f8109f..77801bd6 100644 --- a/src/legacy/models/substring/parse.cpp +++ b/src/legacy/models/substring/parse.cpp @@ -11,22 +11,16 @@ namespace legacy::models { -SubString Parse(const std::string& str, userver::formats::parse::To) -{ - SubString result; - result.GetUnderlying().reserve(str.size() + 2); - result.GetUnderlying().append("%").append(str).append("%"); - return result; -} +// SubString Parse(const std::string& str, userver::formats::parse::To) +// { +// SubString result; +// result.GetUnderlying().reserve(str.size() + 2); +// result.GetUnderlying().append("%").append(str).append("%"); +// return result; +// } SubString Parse(const userver::formats::json::Value& value, userver::formats::parse::To) { - if (!value.IsString()) - { - throw std::runtime_error(fmt::format( - "Expected string type, but got: {}", utils::GetType(value))); - } - auto raw_value = value.As(); - return Parse(raw_value, userver::formats::parse::To{}); + return SubString{value.As()}; } } // namespace legacy::models diff --git a/src/legacy/models/substring/parse.hpp b/src/legacy/models/substring/parse.hpp index b0dcb48f..688939bb 100644 --- a/src/legacy/models/substring/parse.hpp +++ b/src/legacy/models/substring/parse.hpp @@ -7,7 +7,7 @@ namespace legacy::models { -SubString Parse(const std::string& str, userver::formats::parse::To); +// SubString Parse(const std::string& str, userver::formats::parse::To); SubString Parse(const userver::formats::json::Value& value, userver::formats::parse::To); } // namespace legacy::models diff --git a/src/legacy/models/substring/postgre.hpp b/src/legacy/models/substring/postgre.hpp index 0facfacd..d2da681a 100644 --- a/src/legacy/models/substring/postgre.hpp +++ b/src/legacy/models/substring/postgre.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include "type.hpp" @@ -11,4 +11,29 @@ template <> struct CppToSystemPg : PredefinedOid { }; + +template <> +struct BufferFormatter { + using CharFormatter = BufferFormatter; + const SubString& value; + + explicit BufferFormatter(const SubString& val) : value{val} {} + template + void operator()(const UserTypes&, Buffer& buf) const { + CharFormatter::WriteN(buf, "%", 1); + CharFormatter::WriteN(buf, value.data(), value.size()); + CharFormatter::WriteN(buf, "%", 1); + } +}; + +template <> +struct BufferParser { + SubString& value; + + explicit BufferParser(SubString& val) : value{val} {} + + void operator()(const FieldBuffer& buffer){ + value.GetUnderlying() = buffer.ToString(); + } +}; } // namespace userver::storages::postgres::io diff --git a/src/legacy/models/substring/serialize.cpp b/src/legacy/models/substring/serialize.cpp index 48c2670e..caff9541 100644 --- a/src/legacy/models/substring/serialize.cpp +++ b/src/legacy/models/substring/serialize.cpp @@ -5,17 +5,15 @@ namespace legacy::models { -std::string Serialize(const SubString& value, - userver::formats::serialize::To) -{ - return value.GetUnderlying().substr(1, value.GetUnderlying().size() - 2); -} +// std::string Serialize(const SubString& value, +// userver::formats::serialize::To) +// { +// return value.GetUnderlying().substr(1, value.GetUnderlying().size() - 2); +// } userver::formats::json::Value Serialize( const SubString& value, userver::formats::serialize::To) { - std::string str = - Serialize(value, userver::formats::serialize::To{}); - return userver::formats::json::ValueBuilder(str).ExtractValue(); + return userver::formats::json::ValueBuilder{value.GetUnderlying()}.ExtractValue(); } } // namespace legacy::models diff --git a/src/legacy/models/substring/serialize.hpp b/src/legacy/models/substring/serialize.hpp index daa8f5de..0d939a24 100644 --- a/src/legacy/models/substring/serialize.hpp +++ b/src/legacy/models/substring/serialize.hpp @@ -8,6 +8,6 @@ namespace legacy::models userver::formats::json::Value Serialize( const SubString& value, userver::formats::serialize::To); -std::string Serialize(const SubString& value, - userver::formats::serialize::To); +// std::string Serialize(const SubString& value, +// userver::formats::serialize::To); } // namespace legacy::models diff --git a/src/legacy/models/substring/type.hpp b/src/legacy/models/substring/type.hpp index 38c2a33a..dbcfac04 100644 --- a/src/legacy/models/substring/type.hpp +++ b/src/legacy/models/substring/type.hpp @@ -1,10 +1,44 @@ #pragma once -#include +#include +#include +#include #include namespace legacy::models { //расставляет % с обоих сторон строки, чтобы запросы в постгресе с //использованием ILIKE работали как поиск подстроки -using SubString = - userver::utils::StrongTypedef; +class SubString{ + public: + using UnderlyingType = std::string; + SubString() = default; + SubString(const SubString&) = default; + SubString(SubString&&) noexcept = default; + SubString& operator=(const SubString&) = default; + SubString& operator=(SubString&&) noexcept = default; + template + SubString(Args&&... args) noexcept(std::is_nothrow_constructible_v) : data_(std::forward(args)...){} + + template + SubString& operator=(Arg&& args) noexcept(std::is_nothrow_assignable_v){ + data_ = std::forward(args); + } + + std::string& GetUnderlying(){ + return data_; + } + const std::string& GetUnderlying() const{ + return data_; + } + + std::size_t size() const{ + return data_.size(); + } + auto data() const { + return data_.data(); + } + auto operator<=>(const SubString&) const= default; + + private: + std::string data_{}; +}; } // namespace legacy::models diff --git a/src/legacy/views/admin/list/view.cpp b/src/legacy/views/admin/list/view.cpp index 92462f8f..b1ee772c 100644 --- a/src/legacy/views/admin/list/view.cpp +++ b/src/legacy/views/admin/list/view.cpp @@ -18,6 +18,7 @@ #include "legacy/components/controllers/postgres/admin/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" #include "legacy/models/auth_token/serialize.hpp" +#include "legacy/models/substring/parse.hpp" #include "legacy/models/user/serialize.hpp" namespace legacy::views::admin::list { diff --git a/src/legacy/views/faculty/list/view.cpp b/src/legacy/views/faculty/list/view.cpp index 6c8f68ed..c30609b2 100644 --- a/src/legacy/views/faculty/list/view.cpp +++ b/src/legacy/views/faculty/list/view.cpp @@ -17,6 +17,7 @@ #include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/faculty/controller.hpp" #include "legacy/models/auth_token/serialize.hpp" +#include "legacy/models/substring/parse.hpp" #include "legacy/models/user/serialize.hpp" namespace legacy::views::faculty::list { diff --git a/src/legacy/views/group-stage/list/view.cpp b/src/legacy/views/group-stage/list/view.cpp index e440febc..582bbcf5 100644 --- a/src/legacy/views/group-stage/list/view.cpp +++ b/src/legacy/views/group-stage/list/view.cpp @@ -21,6 +21,7 @@ #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/education_type/all.hpp" #include "legacy/models/user/serialize.hpp" +#include "legacy/models/substring/parse.hpp" namespace legacy::views::group::stage::list { namespace diff --git a/src/legacy/views/teacher/list/view.cpp b/src/legacy/views/teacher/list/view.cpp index c174523f..809114e9 100644 --- a/src/legacy/views/teacher/list/view.cpp +++ b/src/legacy/views/teacher/list/view.cpp @@ -18,6 +18,7 @@ #include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" +#include "legacy/models/substring/parse.hpp" namespace legacy::views::teacher::list { namespace