Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 27, 2023
1 parent c18a357 commit 6dc7b31
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 159 deletions.
4 changes: 0 additions & 4 deletions .gen/objs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions configs/static_config.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions src/codegen/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/codegen/sql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class Controller final : public userver::components::LoggableComponentBase
std::optional<legacy::models::AdminAccount> GetAccountByAdminId(
const boost::uuids::uuid& admin_id,
utils::SharedTransaction transaction = nullptr) const;

std::optional<legacy::models::AdminAccount> CreateAdmin(
const legacy::models::UserCredentials& user,
utils::SharedTransaction transaction = nullptr) const;

Controller(const userver::components::ComponentConfig& config,
const userver::components::ComponentContext& context);

std::vector<legacy::models::AdminAccount> GetByFilter(
std::optional<legacy::models::AdminFilter>& filter,
utils::SharedTransaction transaction = nullptr) const;

utils::SharedTransaction CreateTransaction() const;

protected:
Expand Down
23 changes: 0 additions & 23 deletions src/legacy/views/timetable/get/Request.hpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/legacy/views/timetable/get/Responses.hpp

This file was deleted.

74 changes: 0 additions & 74 deletions src/legacy/views/timetable/get/view.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions src/legacy/views/timetable/get/view.hpp

This file was deleted.

11 changes: 11 additions & 0 deletions src/models/admin_account/postgre.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <userver/storages/postgres/io/composite_types.hpp>
#include <models/admin_account/type.hpp>
#include "userver/storages/postgres/io/pg_types.hpp"

namespace userver::storages::postgres::io{
template <>
struct CppToPg<models::AdminAccount>{
static constexpr DBTypeName postgres_name = "timetable_vsu.admin_account";
};
}
15 changes: 15 additions & 0 deletions src/models/admin_account/type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <openapi/types/string.hpp>
#include <openapi/types/uuid.hpp>

namespace models{
using namespace openapi::types;
using namespace openapi::preferences;
struct AdminAccount
{
Uuid<Name<"user_id">> user_id;
Uuid<Name<"admin_id">> admin_id;
String<Name<"login">> credentials;
auto operator<=>(const AdminAccount&) const = default;
};
}
27 changes: 21 additions & 6 deletions src/openapi/base/reflective/checks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
#include <boost/pfr/core.hpp>
#include <boost/pfr/tuple_size.hpp>
#include <openapi/base/property_base.hpp>
#include <type_traits>
#include <utility>

namespace openapi
{
namespace checks
{
template <typename T, std::size_t... Indexes>
concept IsReflectiveHelper = requires
namespace details
{
requires(IsProperty<boost::pfr::tuple_element_t<Indexes, T>> && ...);
};
template <typename T, std::size_t... I>
consteval bool is_fields_property_idxs(std::integer_sequence<std::size_t, I...>)
{
return (IsProperty<boost::pfr::tuple_element_t<I, T>> && ...);
}

template <typename T>
requires std::is_aggregate_v<T> consteval bool is_fields_property_helper()
{
auto seq = std::make_index_sequence<boost::pfr::tuple_size_v<T>>{};
return is_fields_property_idxs<T>(seq);
}
} // namespace details

template <typename T>
concept is_fields_property = details::is_fields_property_helper<T>();

template <typename T>
concept IsReflective =
std::is_class_v<T>&& std::is_aggregate_v<T> && !IsProperty<T>;
concept IsReflective = std::is_class_v<T>&& std::is_aggregate_v<T> &&
!IsProperty<T> && is_fields_property<T>;

template <typename T>
constexpr bool is_reflective_v = IsReflective<T>;
Expand Down
4 changes: 2 additions & 2 deletions src/openapi/doc/int.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once
#include <fmt/core.h>

#include <limits>
#include <openapi/doc/base.hpp>
#include <type_traits>

namespace openapi
{
inline void Append(
DocHelper doc_helper, std::type_identity<std::int32_t>)
inline void Append(DocHelper doc_helper, std::type_identity<std::int32_t>)
{
auto& cur = doc_helper.cur_place;
if (cur.IsObject())
Expand Down
8 changes: 8 additions & 0 deletions src/sql/admin/get_admin_account_by_admin_id.sql
Original file line number Diff line number Diff line change
@@ -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
;
17 changes: 17 additions & 0 deletions src/sql/admin/get_admins_by_filter.sql
Original file line number Diff line number Diff line change
@@ -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))
;
1 change: 0 additions & 1 deletion src/utils/constexpr_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <algorithm>
#include <array>
#include <string_view>
#include <fmt/format.h>

namespace utils
{
Expand Down

0 comments on commit 6dc7b31

Please sign in to comment.