diff --git a/.gen/objs.txt b/.gen/objs.txt index a7ec2040..4b918fd8 100644 --- a/.gen/objs.txt +++ b/.gen/objs.txt @@ -243,11 +243,7 @@ src/legacy/models/substring/parse.cpp src/legacy/models/substring/fwd.hpp src/legacy/models/substring/all.hpp src/legacy/models/subgroup/type.hpp -src/legacy/models/subgroup/serialize.hpp -src/legacy/models/subgroup/serialize.cpp src/legacy/models/subgroup/postgre.hpp -src/legacy/models/subgroup/parse.hpp -src/legacy/models/subgroup/parse.cpp src/legacy/models/subgroup/all.hpp src/legacy/models/request_privileges/type.hpp src/legacy/models/request_privileges/fwd.hpp diff --git a/src/legacy/components/controllers/postgres/admin/controller.cpp b/src/legacy/components/controllers/postgres/admin/controller.cpp index e3008409..86ab8c03 100644 --- a/src/legacy/components/controllers/postgres/admin/controller.cpp +++ b/src/legacy/components/controllers/postgres/admin/controller.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include "legacy/models/admin_account/postgre.hpp" #include "legacy/models/admin_account/type.hpp" #include "legacy/models/admin_filter/postgre.hpp" -#include "legacy/models/subgroup/serialize.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" diff --git a/src/legacy/components/controllers/postgres/faculty/controller.cpp b/src/legacy/components/controllers/postgres/faculty/controller.cpp index 67051e4b..02031cab 100644 --- a/src/legacy/components/controllers/postgres/faculty/controller.cpp +++ b/src/legacy/components/controllers/postgres/faculty/controller.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include "legacy/models/faculty/type.hpp" #include "legacy/models/faculty_filter/postgre.hpp" #include "legacy/models/request_privileges/type.hpp" -#include "legacy/models/subgroup/serialize.hpp" #include "legacy/models/substring/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" diff --git a/src/legacy/components/controllers/postgres/group_stage/controller.cpp b/src/legacy/components/controllers/postgres/group_stage/controller.cpp index c7cd3c00..87b72f19 100644 --- a/src/legacy/components/controllers/postgres/group_stage/controller.cpp +++ b/src/legacy/components/controllers/postgres/group_stage/controller.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include "legacy/models/group_stage/type.hpp" #include "legacy/models/group_stage_filter/postgre.hpp" #include "legacy/models/request_privileges/type.hpp" -#include "legacy/models/subgroup/serialize.hpp" #include "legacy/models/substring/postgre.hpp" #include "legacy/models/user_credentials/postgre.hpp" #include "sql_queries.hpp" diff --git a/src/legacy/components/controllers/postgres/lesson/controller.cpp b/src/legacy/components/controllers/postgres/lesson/controller.cpp index 5340fb20..3f9f9d97 100644 --- a/src/legacy/components/controllers/postgres/lesson/controller.cpp +++ b/src/legacy/components/controllers/postgres/lesson/controller.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include "legacy/models/lesson_filter/postgre.hpp" #include "legacy/models/lesson_v1/postgre.hpp" #include "legacy/models/lesson_v1/type.hpp" -#include "legacy/models/subgroup/serialize.hpp" #include "sql_queries.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 a8f03dc3..aa46f8d2 100644 --- a/src/legacy/components/controllers/postgres/teacher/controller.cpp +++ b/src/legacy/components/controllers/postgres/teacher/controller.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include "legacy/models/admin_account/postgre.hpp" #include "legacy/models/admin_filter/postgre.hpp" #include "legacy/models/request_privileges/type.hpp" -#include "legacy/models/subgroup/serialize.hpp" #include "legacy/models/substring/postgre.hpp" #include "legacy/models/teacher/postgre.hpp" #include "legacy/models/teacher_filter/postgre.hpp" diff --git a/src/legacy/models/lesson_type/postgre.hpp b/src/legacy/models/lesson_type/postgre.hpp index 260cbe73..2c8a96ea 100644 --- a/src/legacy/models/lesson_type/postgre.hpp +++ b/src/legacy/models/lesson_type/postgre.hpp @@ -6,6 +6,9 @@ namespace userver::storages::postgres::io { template <> -struct CppToUserPg<::legacy::models::LessonType> : openapi::PgMapper<::legacy::models::LessonType, "timetable_vsu.type_lesson"> -{}; +struct CppToUserPg<::legacy::models::LessonType> + : openapi::PgMapper<::legacy::models::LessonType, + "timetable_vsu.type_lesson"> +{ +}; } // namespace userver::storages::postgres::io diff --git a/src/legacy/models/lesson_v1/parse.hpp b/src/legacy/models/lesson_v1/parse.hpp index e80311e9..4062d159 100644 --- a/src/legacy/models/lesson_v1/parse.hpp +++ b/src/legacy/models/lesson_v1/parse.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include "legacy/models/subgroup/parse.hpp" #include "legacy/models/timestring/parse.hpp" #include "type.hpp" diff --git a/src/legacy/models/lesson_v1/serialize.hpp b/src/legacy/models/lesson_v1/serialize.hpp index 2c49c3e8..25523f3e 100644 --- a/src/legacy/models/lesson_v1/serialize.hpp +++ b/src/legacy/models/lesson_v1/serialize.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include "legacy/models/subgroup/serialize.hpp" #include "legacy/models/timestring/serialize.hpp" #include "type.hpp" diff --git a/src/legacy/models/subgroup/all.hpp b/src/legacy/models/subgroup/all.hpp index 80b02848..49861cbc 100644 --- a/src/legacy/models/subgroup/all.hpp +++ b/src/legacy/models/subgroup/all.hpp @@ -1,4 +1,2 @@ #pragma once -#include "legacy/models/subgroup/parse.hpp" #include "legacy/models/subgroup/postgre.hpp" -#include "legacy/models/subgroup/serialize.hpp" diff --git a/src/legacy/models/subgroup/parse.cpp b/src/legacy/models/subgroup/parse.cpp deleted file mode 100644 index 048413b5..00000000 --- a/src/legacy/models/subgroup/parse.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "parse.hpp" - -#include - -#include -#include -#include - -#include "type.hpp" - -namespace legacy::models -{ -Subgroup Parse(std::string_view str, userver::formats::parse::To) -{ - if (str == "all") - { - return Subgroup::kAll; - } - else if (str == "first") - { - return Subgroup::kFirst; - } - else if (str == "second") - { - return Subgroup::kSecond; - } - else - throw std::runtime_error( - fmt::format("Fail parse Subgroup, get unexpected value: {}", str)); -} -Subgroup 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{}); -} -} // namespace legacy::models diff --git a/src/legacy/models/subgroup/parse.hpp b/src/legacy/models/subgroup/parse.hpp deleted file mode 100644 index 4e9ed3fc..00000000 --- a/src/legacy/models/subgroup/parse.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include -#include - -#include "type.hpp" - -namespace legacy::models -{ -Subgroup Parse(std::string_view str, userver::formats::parse::To); -Subgroup Parse(const userver::formats::json::Value& value, - userver::formats::parse::To); -} // namespace legacy::models diff --git a/src/legacy/models/subgroup/postgre.hpp b/src/legacy/models/subgroup/postgre.hpp index 3875a861..3c7ad264 100644 --- a/src/legacy/models/subgroup/postgre.hpp +++ b/src/legacy/models/subgroup/postgre.hpp @@ -1,24 +1,14 @@ #pragma once -#include -#include -#include +#include #include "type.hpp" namespace userver::storages::postgres::io { -using ::legacy::models::Subgroup; template <> -struct CppToUserPg : EnumMappingBase +struct CppToUserPg<::legacy::models::Subgroup> + : openapi::PgMapper<::legacy::models::Subgroup, "timetable_vsu.subgroup"> { - static constexpr userver::storages::postgres::DBTypeName postgres_name = - "timetable_vsu.subgroup"; - static constexpr userver::utils::TrivialBiMap enumerators = - [](auto selector) { - return selector() - .Case("all", Subgroup::kAll) - .Case("first", Subgroup::kFirst) - .Case("second", Subgroup::kSecond); - }; }; + } // namespace userver::storages::postgres::io diff --git a/src/legacy/models/subgroup/serialize.cpp b/src/legacy/models/subgroup/serialize.cpp deleted file mode 100644 index 2f2b9620..00000000 --- a/src/legacy/models/subgroup/serialize.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "serialize.hpp" - -#include - -namespace legacy::models -{ -std::string Serialize(const Subgroup& value, - userver::formats::serialize::To) -{ - switch (value) - { - case Subgroup::kAll: - return "all"; - case Subgroup::kFirst: - return "first"; - case Subgroup::kSecond: - return "second"; - } -} -userver::formats::json::Value Serialize( - const Subgroup& value, - userver::formats::serialize::To) -{ - std::string str = - Serialize(value, userver::formats::serialize::To{}); - return userver::formats::json::ValueBuilder(str).ExtractValue(); -} -} // namespace legacy::models diff --git a/src/legacy/models/subgroup/serialize.hpp b/src/legacy/models/subgroup/serialize.hpp deleted file mode 100644 index ea554e9d..00000000 --- a/src/legacy/models/subgroup/serialize.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -#include "type.hpp" - -namespace legacy::models -{ -userver::formats::json::Value Serialize( - const Subgroup& value, - userver::formats::serialize::To); -std::string Serialize(const Subgroup& value, - userver::formats::serialize::To); -} // namespace legacy::models diff --git a/src/legacy/models/subgroup/type.hpp b/src/legacy/models/subgroup/type.hpp index f668bca4..c167c808 100644 --- a/src/legacy/models/subgroup/type.hpp +++ b/src/legacy/models/subgroup/type.hpp @@ -1,11 +1,7 @@ #pragma once +#include namespace legacy::models { -enum struct Subgroup -{ - kAll, - kFirst, - kSecond -}; +DECLARE_OPENAPI_ENUM(Subgroup, int, all, first, second); }