Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 21, 2023
1 parent 43ff626 commit 90428ca
Show file tree
Hide file tree
Showing 91 changed files with 709 additions and 292 deletions.
56 changes: 35 additions & 21 deletions .gen/objs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ src/utils/component_list_fwd.hpp
src/utils/component.hpp
src/utils/compilers_macros.hpp
src/utils/common_errors.hpp
src/openapi/types/uuid_type.hpp
src/openapi/types/string_type.hpp
src/openapi/types/optional_type.hpp
src/openapi/types/object_type.hpp
src/openapi/types/array_type.hpp
src/openapi/types/uuid.hpp
src/openapi/types/string.hpp
src/openapi/types/optional.hpp
src/openapi/types/object.hpp
src/openapi/types/datetime.hpp
src/openapi/types/array.hpp
src/openapi/types/all.hpp
src/openapi/to_tuple/vector.hpp
src/openapi/to_tuple/reflective.hpp
Expand All @@ -53,23 +54,28 @@ src/openapi/to_tuple/optional.hpp
src/openapi/to_tuple/default.hpp
src/openapi/to_tuple/all.hpp
src/openapi/postgres/mapping.hpp
src/openapi/postgres/all.hpp
src/openapi/json/serialize/string_property.hpp
src/openapi/json/serialize/reflective.hpp
src/openapi/json/serialize/optional_property.hpp
src/openapi/json/serialize/object_property.hpp
src/openapi/json/serialize/datetime_property.hpp
src/openapi/json/serialize/base_property.hpp
src/openapi/json/serialize/array_property.hpp
src/openapi/json/serialize/all.hpp
src/openapi/json/parse/string_property.hpp
src/openapi/json/parse/reflective.hpp
src/openapi/json/parse/optional_property.hpp
src/openapi/json/parse/object_property.hpp
src/openapi/json/parse/datetime_property.hpp
src/openapi/json/parse/base_property.hpp
src/openapi/json/parse/array_property.hpp
src/openapi/json/parse/all.hpp
src/openapi/json/all.hpp
src/openapi/http/serialize/response.hpp
src/openapi/http/serialize/all.hpp
src/openapi/http/parse/request.hpp
src/openapi/http/parse/all.hpp
src/openapi/http/openapi_descriptor_fwd.hpp
src/openapi/http/openapi_descriptor.hpp
src/openapi/http/openapi_descriptor.cpp
Expand Down Expand Up @@ -104,32 +110,35 @@ src/openapi/doc/path.hpp
src/openapi/doc/optional.hpp
src/openapi/doc/int.hpp
src/openapi/doc/header.hpp
src/openapi/doc/datetime.hpp
src/openapi/doc/cookie.hpp
src/openapi/doc/body.hpp
src/openapi/doc/base.hpp
src/openapi/doc/array.hpp
src/openapi/doc/all.hpp
src/openapi/base/uuid_traits.hpp
src/openapi/base/uuid_property.hpp
src/openapi/base/string_traits.hpp
src/openapi/base/string_property.hpp
src/openapi/base/reflective_uuid_fix.hpp
src/openapi/base/reflective_utils.hpp
src/openapi/base/reflective_preferences.hpp
src/openapi/base/reflective_checks.hpp
src/openapi/base/traits/uuid.hpp
src/openapi/base/traits/string.hpp
src/openapi/base/traits/optional.hpp
src/openapi/base/traits/object.hpp
src/openapi/base/traits/array.hpp
src/openapi/base/traits/all.hpp
src/openapi/base/reflective/uuid_fix.hpp
src/openapi/base/reflective/utils.hpp
src/openapi/base/reflective/preferences.hpp
src/openapi/base/reflective/checks.hpp
src/openapi/base/reflective/all.hpp
src/openapi/base/property_base.hpp
src/openapi/base/properties/uuid.hpp
src/openapi/base/properties/string.hpp
src/openapi/base/properties/optional.hpp
src/openapi/base/properties/object.hpp
src/openapi/base/properties/datetime.hpp
src/openapi/base/properties/array.hpp
src/openapi/base/properties/all.hpp
src/openapi/base/preferences.hpp
src/openapi/base/optional_traits.hpp
src/openapi/base/optional_property.hpp
src/openapi/base/object_traits.hpp
src/openapi/base/object_property.hpp
src/openapi/base/object_field_names.hpp
src/openapi/base/named_traits.hpp
src/openapi/base/is_optional_property.hpp
src/openapi/base/holder.hpp
src/openapi/base/doc.hpp
src/openapi/base/array_traits.hpp
src/openapi/base/array_property.hpp
src/openapi/base/all.hpp
src/openapi/as_tuple/vector.hpp
src/openapi/as_tuple/reflective.hpp
Expand All @@ -142,6 +151,8 @@ src/models/user_credentials/type.hpp
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/error_v1/type.hpp
src/legacy/views/timetable/get/view.hpp
src/legacy/views/timetable/get/view.cpp
Expand Down Expand Up @@ -336,5 +347,8 @@ src/controllers/user/controller.cpp
src/controllers/token/controller_fwd.hpp
src/controllers/token/controller.hpp
src/controllers/token/controller.cpp
src/controllers/lesson/controller_fwd.hpp
src/controllers/lesson/controller.hpp
src/controllers/lesson/controller.cpp
src/codegen/sql.hpp
src/codegen/sql.cpp
1 change: 1 addition & 0 deletions .gen/unittest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ utests/openapi/json/serialize/basic_optional.cpp
utests/openapi/json/serialize/basic_object.cpp
utests/openapi/json/serialize/basic_array.cpp
utests/openapi/json/parse/uuid.cpp
utests/openapi/json/parse/datetime.cpp
utests/openapi/json/parse/basic_string.cpp
utests/openapi/json/parse/basic_object.cpp
utests/openapi/json/parse/basic_array.cpp
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CMAKE_RELEASE_FLAGS ?=
CMAKE_OS_FLAGS ?= -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 -DUSERVER_FEATURE_REDIS_HI_MALLOC=1
FORMAT_INCLUDES_FLAGS ?= userver boost gtest openapi utils codegen
GENERATE_SQL_QUERIES_FLAGS ?= src/sql src/codegen sql sql
GENERATE_ALL_HEADERS_FLAGS ?= src/openapi openapi
NPROCS ?= $(shell nproc)
CLANG_FORMAT ?= clang-format-11

Expand Down Expand Up @@ -189,10 +190,15 @@ unite-api:
gen-queries:
@python3 scripts/generate_sql_queries.py $(GENERATE_SQL_QUERIES_FLAGS)

.PHONY: gen-all-headers
gen-all-headers:
@python3 scripts/generate_all_headers.py $(GENERATE_ALL_HEADERS_FLAGS)

.PHONY: gen
gen:
$(MAKE) gen-queries
$(MAKE) gen-sources
$(MAKE) gen-all-headers

# # Internal hidden targets that are used only in docker environment
# --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
Expand Down
46 changes: 46 additions & 0 deletions scripts/generate_all_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys


def path(prefix, root_directory, path):
relative = os.path.relpath(path, root_directory)
return prefix + '/' + relative

# Функция для создания файла all.hpp
def create_all_hpp(prefix_path, folder_path, root):
hpp_files = [f for f in os.listdir(folder_path) if (f.endswith(".hpp") and f != "all.hpp")]

with open(os.path.join(folder_path, "all.hpp"), "w") as all_hpp_file:
all_hpp_file.write('#pragma once\n')
for hpp_file in hpp_files:
path_hpp_file = path(prefix_path, root, os.path.join(folder_path, hpp_file))
all_hpp_file.write(f'#include "{path_hpp_file}"\n')

# Поиск вложенных папок
sub_folders = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]

for sub_folder in sub_folders:
path_sub_folder = path(prefix_path, root, os.path.join(folder_path, sub_folder))
all_hpp_file.write(f'#include "{path_sub_folder}/all.hpp"\n')


def create_all_hpp_in_directory(prefix_path, root):
for folder_name, sub_folders, filenames in os.walk(root):
create_all_hpp(prefix_path, folder_name, root)

def main():
if len(sys.argv) < 2:
print('Usage: python3 generate_sql.py <directory> <prefix_path>')
return

directory = sys.argv[1]
if len(sys.argv) >= 3:
prefix_path = sys.argv[2]
else:
prefix_path = ''

create_all_hpp_in_directory(prefix_path, directory)


if __name__ == '__main__':
main()
96 changes: 96 additions & 0 deletions src/codegen/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,102 @@

namespace sql{

//Generated from: src/sql/get_lessons_by_filter.sql
const userver::storages::postgres::Query get_lessons_by_filter = {
R"-(
WITH lesson_info as (
SELECT
l.id AS lesson_id,
l.begin AS lesson_begin,
l.end AS lesson_end,
l.number_lesson AS lesson_number,
l.type_lesson AS lesson_type,
l.type_week AS lesson_week_type,
l.subgroup AS lesson_subgroup,
l.day AS lesson_day,
r.id AS room_id,
r.name AS room_name,
s.id AS subject_id,
s.name AS subject_name,
gs.id AS group_stage_id,
gs.begin AS group_stage_begin,
gs.end AS group_stage_end,
gs.course AS group_stage_course,
g.id AS group_id,
g.name AS group_name,
g.type AS group_type,
f.id AS faculty_id,
f.name AS faculty_name,
d.id AS department_id,
d.name AS department_name,
t.id AS teacher_id,
t.fio AS teacher_fio,
t.bio AS teacher_bio
FROM timetable_vsu.lesson AS l
LEFT JOIN timetable_vsu.room AS r ON l.id_room = r.id
LEFT JOIN timetable_vsu.shedule AS sh ON l.id_shedule = sh.id
LEFT JOIN timetable_vsu.subject AS s ON sh.id_subject = s.id
LEFT JOIN timetable_vsu.group_stage AS gs ON sh.id_group_stage = gs.id
LEFT JOIN timetable_vsu.group AS g ON gs.id_group = g.id
LEFT JOIN timetable_vsu.teacher AS t ON sh.id_teacher = t.id
LEFT JOIN timetable_vsu.department AS d ON t.id_department = d.id
LEFT JOIN timetable_vsu.faculty AS f ON d.id_faculty = f.id
)
SELECT
lesson_id,
lesson_begin,
lesson_end,
lesson_number,
lesson_type,
lesson_week_type,
lesson_subgroup,
lesson_day,
room_id,
room_name,
subject_id,
subject_name,
group_stage_id AS group_id,
group_stage_course AS group_course,
group_name,
group_type,
faculty_id,
faculty_name,
department_id,
department_name,
teacher_id,
teacher_fio,
teacher_bio
FROM lesson_info
WHERE
($1.lesson_ids IS null OR lesson_id::text ILIKE ANY($1.lesson_ids)) and
($1.begin IS null OR $1.begin <= lesson_end) and
($1."end" IS null OR $1."end" >= lesson_begin) and
($1.days IS null OR lesson_day = ANY($1.days)) and
($1.department_ids IS null OR department_id::text ILIKE ANY($1.department_ids)) and
($1.department_names IS null OR department_name ILIKE ANY($1.department_names)) and
($1.faculty_ids IS null OR faculty_id::text ILIKE ANY($1.faculty_ids)) and
($1.faculty_names IS null OR faculty_name ILIKE ANY($1.faculty_names)) and
($1.group_ids IS null OR group_stage_id::text ILIKE ANY($1.group_ids)) and
($1.group_names IS null OR group_name ILIKE ANY($1.group_names)) and
($1.group_courses is null OR group_stage_course = ANY($1.group_courses)) and
($1.group_types is null OR group_type = ANY($1.group_types)) and
($1.room_ids IS null OR room_id::text ILIKE ANY($1.room_ids)) and
($1.room_names IS null OR room_name ILIKE ANY($1.room_names)) and
($1.subject_names IS null OR subject_name ILIKE ANY($1.subject_names)) and
($1.subject_ids IS null OR subject_id::text ILIKE ANY($1.subject_ids)) and
($1.teacher_fios IS null OR teacher_fio ILIKE ANY($1.teacher_fios)) and
($1.teacher_bios IS null OR teacher_bio ILIKE ANY($1.teacher_bios)) and
($1.teacher_ids IS null OR teacher_id::text ILIKE ANY($1.teacher_ids)) and
($1.subgroup IS null OR lesson_subgroup = $1.subgroup) and
($1.week IS null OR lesson_week_type = $1.week) and
($1.lesson_type is null OR lesson_type = $1.lesson_type) and
($1.numbers is null OR lesson_number = ANY($1.numbers))
;
)-",
userver::storages::postgres::Query::Name("get_lessons_by_filter"),
userver::storages::postgres::Query::LogMode::kFull
};

//Generated from: src/sql/token/get_user_id_by_token.sql
const userver::storages::postgres::Query get_user_id_by_token = {
R"-(
Expand Down
3 changes: 3 additions & 0 deletions src/codegen/sql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace sql{

//Generated from: src/sql/get_lessons_by_filter.sql
extern const userver::storages::postgres::Query get_lessons_by_filter;

//Generated from: src/sql/token/get_user_id_by_token.sql
extern const userver::storages::postgres::Query get_user_id_by_token;

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/lesson/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ boost::uuids::uuid Controller::CreateNew(
userver::utils::datetime::Now() + std::chrono::hours(24));
return pg_result.AsSingleRow<boost::uuids::uuid>();
}
} // namespace controllers::token
} // namespace controllers::lesson
2 changes: 1 addition & 1 deletion src/controllers/lesson/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ struct Controller : Base
const boost::uuids::uuid& id_user,
utils::SharedTransaction transaction = nullptr) const;
};
} // namespace controllers::token
} // namespace controllers::lesson
2 changes: 1 addition & 1 deletion src/controllers/lesson/controller_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ namespace controllers::lesson
{
struct Controller;
void Append(userver::components::ComponentList& list);
} // namespace controllers::token
} // namespace controllers::lesson
14 changes: 9 additions & 5 deletions src/controllers/user/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ Controller::Controller(const userver::components::ComponentConfig& cfg,
{
}

namespace {
const userver::storages::postgres::Query* GetRequestRihtsType(legacy::models::UserType user_type){
namespace
{
const userver::storages::postgres::Query* GetRequestRihtsType(
legacy::models::UserType user_type)
{
switch (user_type)
{
case legacy::models::UserType::kUser:
Expand All @@ -146,8 +149,8 @@ namespace {
case legacy::models::UserType::kTeacher:
return &sql::create_teacher_request;
}
}
}
} // namespace

std::optional<boost::uuids::uuid> Controller::CreateRequestRights(
const boost::uuids::uuid& user_id, const std::string& description,
Expand All @@ -159,9 +162,10 @@ std::optional<boost::uuids::uuid> Controller::CreateRequestRights(
if (query)
{
return transaction->Execute_R<std::optional<boost::uuids::uuid>>(
*query, user_id, description);
*query, user_id, description);
}
else {
else
{
return std::nullopt;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/error_v1/type.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <openapi/http/base/body.hpp>
#include <openapi/types/string_type.hpp>
#include <openapi/types/string.hpp>

namespace models
{
Expand Down
14 changes: 14 additions & 0 deletions src/models/lesson_v1/postgres.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <userver/storages/postgres/io/composite_types.hpp>

#include "type.hpp"
namespace userver::storages::postgres::io
{
template <>
struct CppToUserPg<models::User>
{
static constexpr DBTypeName postgres_name = "timetable_vsu.user";
};

} // namespace userver::storages::postgres::io
Loading

0 comments on commit 90428ca

Please sign in to comment.