Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 26, 2023
1 parent 74820eb commit c18a357
Show file tree
Hide file tree
Showing 27 changed files with 573 additions and 76 deletions.
9 changes: 8 additions & 1 deletion .gen/objs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
src/views/timetable/view.hpp
src/views/timetable/view.cpp
src/views/timetable/declarations.hpp
src/views/register/view.hpp
src/views/register/view.cpp
src/views/register/declarations.hpp
Expand All @@ -19,6 +22,7 @@ src/utils/meta.hpp
src/utils/json_type.hpp
src/utils/json_type.cpp
src/utils/is_complete_type.hpp
src/utils/initialize_dependents.hpp
src/utils/formated_exception.hpp
src/utils/convert/json_serialize.hpp
src/utils/convert/json_parse.hpp
Expand All @@ -44,6 +48,7 @@ src/openapi/types/uuid.hpp
src/openapi/types/string.hpp
src/openapi/types/optional.hpp
src/openapi/types/object.hpp
src/openapi/types/field.hpp
src/openapi/types/datetime.hpp
src/openapi/types/array.hpp
src/openapi/types/all.hpp
Expand Down Expand Up @@ -162,7 +167,8 @@ src/models/user_credentials/postgres.hpp
src/models/user/type.hpp
src/models/user/postgres.hpp
src/models/lesson_v1/type.hpp
src/models/lesson_v1/postgres.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
Expand Down Expand Up @@ -241,6 +247,7 @@ src/legacy/models/substring/postgre.hpp
src/legacy/models/substring/parse.hpp
src/legacy/models/substring/parse.cpp
src/legacy/models/substring/fwd.hpp
src/legacy/models/substring/doc.hpp
src/legacy/models/substring/all.hpp
src/legacy/models/subgroup/type.hpp
src/legacy/models/subgroup/postgre.hpp
Expand Down
6 changes: 6 additions & 0 deletions configs/static_config.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ components_manager:
method: POST
task_processor: main-task-processor
handler-timetable-get:
load-enabled: false
path: /timetable/get
method: POST
task_processor: main-task-processor
Expand Down Expand Up @@ -137,6 +138,11 @@ components_manager:
id: $root_id
lesson_details_controller : {}
teacher_controller : {}
new-lesson-controller: {}
timetable-view:
path: /timetable/get
method: POST
task_processor: main-task-processor
handler-ping:
path: /ping
method: GET
Expand Down
19 changes: 15 additions & 4 deletions service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <userver/utils/daemon_run.hpp>
#include <utility>

#include "controllers/lesson/controller_fwd.hpp"
#include "controllers/token/controller_fwd.hpp"
#include "controllers/user/controller.hpp"
#include "controllers/user/controller_fwd.hpp"
Expand All @@ -35,8 +36,10 @@
#include "legacy/views/timetable/get/view.hpp"
#include "views/login/view.hpp"
#include "views/register/view.hpp"
#include "views/timetable/view.hpp"

void AppendPgControllers(userver::components::ComponentList& component_list)
void AppendLegacyPgControllers(
userver::components::ComponentList& component_list)
{
using namespace legacy::components::controllers::postgres;
user::Append(component_list);
Expand All @@ -46,8 +49,6 @@ void AppendPgControllers(userver::components::ComponentList& component_list)
teacher::Append(component_list);
faculty::Append(component_list);
group_stage::Append(component_list);
controllers::token::Append(component_list);
controllers::user::Append(component_list);
}

void AppendLegacyViews(userver::components::ComponentList& component_list)
Expand All @@ -70,6 +71,15 @@ void AppendViews(userver::components::ComponentList& component_list)
using namespace views;
login::Append(component_list);
Register::Append(component_list);
timetable::Append(component_list);
}

void AppendControllers(userver::components::ComponentList& component_list)
{
using namespace controllers;
token::Append(component_list);
user::Append(component_list);
lesson::Append(component_list);
}

int main(int argc, char* argv[])
Expand All @@ -84,7 +94,8 @@ int main(int argc, char* argv[])
.Append<userver::server::handlers::TestsControl>();
openapi::http::AppendOpenApiDescriptor(component_list);
service_template::AppendHello(component_list);
AppendPgControllers(component_list);
AppendLegacyPgControllers(component_list);
AppendControllers(component_list);
AppendLegacyViews(component_list);
AppendViews(component_list);
return userver::utils::DaemonMain(argc, argv, component_list);
Expand Down
24 changes: 17 additions & 7 deletions src/controllers/lesson/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@
#include <boost/uuid/uuid.hpp>
#include <chrono>
#include <codegen/sql.hpp>
#include <cstdint>
#include <models/lesson_filter/postgres.hpp>
#include <openapi/postgres/mapping.hpp>
#include <userver/components/component_config.hpp>
#include <userver/components/component_context.hpp>
#include <userver/components/component_list.hpp>
#include <userver/components/loggable_component_base.hpp>
#include <userver/storages/postgres/component.hpp>
#include <userver/storages/postgres/io/array_types.hpp>
#include <userver/storages/postgres/io/integral_types.hpp>
#include <userver/storages/postgres/io/optional.hpp>
#include <userver/storages/postgres/io/type_mapping.hpp>
#include <userver/storages/postgres/io/type_traits.hpp>
#include <userver/storages/postgres/io/uuid.hpp>
#include <userver/utils/datetime.hpp>
#include <utils/shared_transaction.hpp>

#include "controller_fwd.hpp"
#include "legacy/models/day/postgre.hpp"
#include "legacy/models/education_type/postgre.hpp"
#include "legacy/models/lesson_type/postgre.hpp"
#include "legacy/models/lesson_week_type/postgre.hpp"
#include "legacy/models/subgroup/postgre.hpp"
#include "models/user_credentials/postgres.hpp"

namespace controllers::lesson
Expand All @@ -27,14 +39,12 @@ Controller::Controller(const userver::components::ComponentConfig& cfg,
: Base(cfg, ctx)
{
}
boost::uuids::uuid Controller::CreateNew(
const boost::uuids::uuid& id_user,
std::vector<models::LessonV1> Controller::FindLessons(
const std::optional<models::LessonFilter>& filter,
utils::SharedTransaction transaction) const
{
utils::FillSharedTransaction(transaction, pg_cluster_);
auto pg_result = transaction->transaction_.Execute(
sql::add_token_to_user, id_user,
userver::utils::datetime::Now() + std::chrono::hours(24));
return pg_result.AsSingleRow<boost::uuids::uuid>();
FillTransaction(transaction);
return transaction->Execute_R<std::vector<models::LessonV1>>(
sql::get_lessons_by_filter, filter);
}
} // namespace controllers::lesson
8 changes: 5 additions & 3 deletions src/controllers/lesson/controller.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#pragma once

#include <boost/uuid/uuid.hpp>
#include <userver/components/loggable_component_base.hpp>
#include <utils/component_list_fwd.hpp>
#include <utils/pg_controller.hpp>
#include <utils/shared_transaction.hpp>

#include "models/lesson_filter/type.hpp"
#include "models/lesson_v1/type.hpp"

namespace controllers::lesson
{
using Base = utils::PgController<"new-lesson-controller", "postgres-db-1">;
struct Controller : Base
{
Controller(const userver::components::ComponentConfig& cfg,
const userver::components::ComponentContext& ctx);
boost::uuids::uuid CreateNew(
const boost::uuids::uuid& id_user,
std::vector<models::LessonV1> FindLessons(
const std::optional<models::LessonFilter>& filter,
utils::SharedTransaction transaction = nullptr) const;
};
} // namespace controllers::lesson
13 changes: 13 additions & 0 deletions src/legacy/models/substring/doc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <legacy/models/substring/type.hpp>
#include <openapi/doc/base.hpp>
#include <type_traits>
namespace openapi
{
inline void Append(DocHelper doc_helper,
std::type_identity<legacy::models::SubString>)
{
doc_helper.cur_place["type"] = "string";
}
} // namespace openapi
16 changes: 16 additions & 0 deletions src/models/lesson_filter/postgres.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <openapi/enum/pg_mapper.hpp>
#include <userver/storages/postgres/io/pg_types.hpp>

#include "type.hpp"

namespace userver::storages::postgres::io
{
template <>
struct CppToUserPg<::models::LessonFilter>
{
static constexpr DBTypeName postgres_name =
"timetable_vsu.lesson_filter_v2";
};

} // namespace userver::storages::postgres::io
61 changes: 61 additions & 0 deletions src/models/lesson_filter/type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once
#include <openapi/base/properties/datetime.hpp>
#include <openapi/base/property_base.hpp>
#include <openapi/types/datetime.hpp>
#include <openapi/types/optional.hpp>
#include <vector>

#include "legacy/models/day/type.hpp"
#include "legacy/models/education_type/type.hpp"
#include "legacy/models/lesson_type/type.hpp"
#include "legacy/models/lesson_week_type/type.hpp"
#include "legacy/models/subgroup/type.hpp"
#include "legacy/models/substring/type.hpp"

namespace models
{
using namespace openapi::types;
using namespace openapi::preferences;

struct LessonFilter
{
Optional<std::vector<legacy::models::SubString>, Name<"lesson_ids">>
lesson_ids;
Optional<Datetime<>, Name<"begin">> begin;
Optional<Datetime<>, Name<"end">> end;
Optional<std::vector<legacy::models::Day>, Name<"days">> days;
Optional<std::vector<legacy::models::SubString>, Name<"department_ids">>
department_ids;
Optional<std::vector<legacy::models::SubString>, Name<"department_names">>
department_names;
Optional<std::vector<legacy::models::SubString>, Name<"faculty_ids">>
faculty_ids;
Optional<std::vector<legacy::models::SubString>, Name<"faculty_names">>
faculty_names;
Optional<std::vector<legacy::models::SubString>, Name<"group_ids">>
group_ids;
Optional<std::vector<legacy::models::SubString>, Name<"group_names">>
group_names;
Optional<std::vector<short>, Name<"group_courses">> group_courses;
Optional<std::vector<legacy::models::EducationType>, Name<"group_types">>
group_types;
Optional<std::vector<legacy::models::SubString>, Name<"room_ids">> room_ids;
Optional<std::vector<legacy::models::SubString>, Name<"room_names">>
room_names;
Optional<legacy::models::Subgroup, Name<"subgroup">> subgroup;
Optional<std::vector<legacy::models::SubString>, Name<"subject_ids">>
subject_ids;
Optional<std::vector<legacy::models::SubString>, Name<"subject_names">>
subject_names;
Optional<std::vector<legacy::models::SubString>, Name<"teacher_ids">>
teacher_ids;
Optional<std::vector<legacy::models::SubString>, Name<"teacher_fios">>
teacher_fios;
Optional<std::vector<legacy::models::SubString>, Name<"teacher_bios">>
teacher_bios;
Optional<legacy::models::LessonWeekType, Name<"week_type">> week;
Optional<legacy::models::LessonType, Name<"lesson_type">> type;
Optional<std::vector<short>, Name<"numbers">> numbers;
auto operator<=>(const LessonFilter&) const = default;
};
} // namespace models
14 changes: 0 additions & 14 deletions src/models/lesson_v1/postgres.hpp

This file was deleted.

37 changes: 21 additions & 16 deletions src/models/lesson_v1/type.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#pragma once
#include <openapi/base/named_traits.hpp>
#include <openapi/types/datetime.hpp>
#include <openapi/types/field.hpp>
#include <openapi/types/string.hpp>
#include <openapi/types/uuid.hpp>

#include "legacy/models/day/type.hpp"
#include "legacy/models/education_type/type.hpp"
#include "legacy/models/lesson_type/type.hpp"
#include "legacy/models/lesson_week_type/type.hpp"
#include "legacy/models/subgroup/type.hpp"
#include "legacy/models/user_type/type.hpp"

namespace models
Expand All @@ -12,31 +19,29 @@ using namespace openapi::preferences;
struct LessonV1
{
Uuid<Name<"id">> lesson_id;
convert::Property<TimeString, "begin"> lesson_begin;
convert::Property<TimeString, "end"> lesson_end;
convert::Property<short, "number"> lesson_number;
convert::Property<LessonType, "type"> lesson_type;
convert::Property<LessonWeekType, "week_type"> lesson_week_type;
convert::Property<Subgroup, "subgroup"> lesson_subgroup;
convert::Property<Day, "day"> lesson_day;
Datetime<Name<"begin">> lesson_begin;
Datetime<Name<"end">> lesson_end;
Field<short, Name<"number">> lesson_number;
Field<legacy::models::LessonType, Name<"type">> lesson_type;
Field<legacy::models::LessonWeekType, Name<"week_type">> lesson_week_type;
Field<legacy::models::Subgroup, Name<"subgroup">> lesson_subgroup;
Field<legacy::models::Day, Name<"day">> lesson_day;
Uuid<Name<"room_id">> room_id;
String<Name<"room_name">> room_name;
Uuid<Name<"subject_id">> subject_id;
String < Name<"subject_name"> subject_name;
String<Name<"subject_name">> subject_name;
Uuid<Name<"group_id">> group_id;
convert::Property<short, "group_course"> group_stage_course;
String < Name<"group_name"> group_name;
convert::Property<EducationType, "group_type"> group_type;
Field<short, Name<"group_course">> group_stage_course;
String<Name<"group_name">> group_name;
Field<legacy::models::EducationType, Name<"group_type">> group_type;
Uuid<Name<"faculty_id">> faculty_id;
String < Name<"faculty_name"> faculty_name;
String<Name<"faculty_name">> faculty_name;
Uuid<Name<"department_id">> department_id;
String < Name<"department_name"> department_name;
String<Name<"department_name">> department_name;
Uuid<Name<"teacher_id">> teacher_id;
String<Name<"teacher_fio">> teacher_fio;
String<Name<"teacher_bio">> teacher_bio;
static constexpr utils::convert::PolicyFields kPolicyFields =
utils::convert::PolicyFields::ConvertAll;
};
auto operator<=>(const LessonV1&) const = default;
};

} // namespace models
Loading

0 comments on commit c18a357

Please sign in to comment.