Skip to content

Commit

Permalink
Fix api (#9)
Browse files Browse the repository at this point in the history
1) Убраны команды для Docker из readme, так как docker более не поддерживается
2) Добавлены команды для make, позволяющие удобнее работать с тестами, форматированием и запуском 3) сервиса
3) Реализована и покрыта тестами ручка /get-timetable
4) Реализован конвертер структур, использующие Property в кортежи ссылок, поддерживает массивы и опциональные параметры, благодаря этому можно теперь пихать структурки в постгрес и наоборот
5) Добавлено форматирование EOL в конце файлов
6) Наведен порядок в схемах постгреса(используется порядковое нумерование для избежания неоднозначностей)
  • Loading branch information
sabudilovskiy authored May 3, 2023
1 parent 2b91e4a commit d2463b8
Show file tree
Hide file tree
Showing 196 changed files with 3,382 additions and 442 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ ColumnLimit: 80
PointerAlignment: Left
SpaceAfterCStyleCast: true
DerivePointerAlignment: false
AlignTrailingComments: true
AlignTrailingComments: true
SortIncludes: true
85 changes: 76 additions & 9 deletions .gen/objs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ src/views/login/Responses.hpp
src/views/login/Request.hpp
src/views/hello/view.hpp
src/views/hello/view.cpp
src/views/get-timetable/view.hpp
src/views/get-timetable/view.cpp
src/views/get-timetable/Responses.hpp
src/views/get-timetable/Request.hpp
src/utils/type_holder.hpp
src/utils/meta.hpp
src/utils/json_type.hpp
src/utils/json_type.cpp
Expand All @@ -16,11 +21,15 @@ src/utils/convert/json_parse.hpp
src/utils/convert/http_response_serialize.hpp
src/utils/convert/http_response_base.hpp
src/utils/convert/http_request_parse.hpp
src/utils/convert/drop_properties_ref.hpp
src/utils/convert/detail/serialize/converter_json.hpp
src/utils/convert/detail/serialize/converter_http_response.hpp
src/utils/convert/detail/parse/converter_json.hpp
src/utils/convert/detail/parse/converter_http_request.hpp
src/utils/convert/detail/drop_properties/mut_dropper_to_ref.hpp
src/utils/convert/detail/drop_properties/const_dropper_to_ref.hpp
src/utils/convert/base.hpp
src/utils/convert/additional_properties.hpp
src/utils/constexpr_string.hpp
src/utils/component_list_fwd.hpp
src/models/user_type/type.hpp
Expand All @@ -31,17 +40,75 @@ src/models/user_type/parse.hpp
src/models/user_type/parse.cpp
src/models/user/type.hpp
src/models/user/postgre.hpp
src/models/lesson/type.hpp
src/models/timestring/type.hpp
src/models/timestring/serialize.hpp
src/models/timestring/serialize.cpp
src/models/timestring/postgre.hpp
src/models/timestring/parse.hpp
src/models/timestring/parse.cpp
src/models/timestring/fwd.hpp
src/models/timestring/all.hpp
src/models/subgroup/type.hpp
src/models/subgroup/serialize.hpp
src/models/subgroup/serialize.cpp
src/models/subgroup/postgre.hpp
src/models/subgroup/parse.hpp
src/models/subgroup/parse.cpp
src/models/subgroup/all.hpp
src/models/lesson_with_details/type.hpp
src/models/lesson_with_details/serialize.hpp
src/models/lesson_with_details/postgre.hpp
src/models/lesson_with_details/parse.hpp
src/models/lesson_week_type/type.hpp
src/models/lesson_week_type/serialize.hpp
src/models/lesson_week_type/serialize.cpp
src/models/lesson_week_type/postgre.hpp
src/models/lesson_week_type/parse.hpp
src/models/lesson_week_type/parse.cpp
src/models/lesson_week_type/all.hpp
src/models/lesson_v1/type.hpp
src/models/lesson_v1/serialize.hpp
src/models/lesson_v1/postgre.hpp
src/models/lesson_v1/parse.hpp
src/models/lesson_type/type.hpp
src/models/lesson_type/serialize.hpp
src/models/lesson_type/serialize.cpp
src/models/lesson_type/postgre.hpp
src/models/lesson_type/parse.hpp
src/models/lesson_type/parse.cpp
src/models/lesson_type/all.hpp
src/models/lesson_filter/type.hpp
src/models/lesson_filter/postgre.hpp
src/models/lesson_filter/fwd.hpp
src/models/education_type/type.hpp
src/models/education_type/serialize.hpp
src/models/education_type/serialize.cpp
src/models/education_type/postgre.hpp
src/models/education_type/parse.hpp
src/models/education_type/parse.cpp
src/models/education_type/all.hpp
src/models/day/type.hpp
src/models/day/serialize.hpp
src/models/day/serialize.cpp
src/models/day/postgre.hpp
src/models/day/parse.hpp
src/models/day/parse.cpp
src/models/day/all.hpp
src/models/auth_token/type.hpp
src/models/auth_token/serialize.hpp
src/http/legacy_handler_parsed.hpp
src/http/handler_parsed.hpp
src/http/ErrorV1.hpp
src/components/controllers/user_controller_fwd.hpp
src/components/controllers/user_controller_fwd.cpp
src/components/controllers/user_controller.hpp
src/components/controllers/user_controller.cpp
src/components/controllers/token_controller_fwd.hpp
src/components/controllers/token_controller_fwd.cpp
src/components/controllers/token_controller.hpp
src/components/controllers/token_controller.cpp
src/helpers/lesson_converter.hpp
src/components/controllers/postgres/user/fwd.hpp
src/components/controllers/postgres/user/fwd.cpp
src/components/controllers/postgres/user/controller.hpp
src/components/controllers/postgres/user/controller.cpp
src/components/controllers/postgres/token/fwd.hpp
src/components/controllers/postgres/token/fwd.cpp
src/components/controllers/postgres/token/controller.hpp
src/components/controllers/postgres/token/controller.cpp
src/components/controllers/postgres/lesson/fwd.hpp
src/components/controllers/postgres/lesson/fwd.cpp
src/components/controllers/postgres/lesson/controller.hpp
src/components/controllers/postgres/lesson/controller.cpp
2 changes: 2 additions & 0 deletions .gen/unittest.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
utests/hello_test.cpp
utests/dropper_additional.cpp
utests/dropper.cpp
utests/convert_test.cpp
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ jobs:
if: matrix.make == 'test-release'
run: |
make dist-clean
make install PREFIX=`pwd`/local_installation/
sudo make install-release
- name: Test run after install
if: matrix.make == 'test-release'
run: |
./local_installation/bin/timetable_vsu_backend --config=./local_installation/etc/timetable_vsu_backend/static_config.yaml &
make run-release &
- name: Check work run service
if: matrix.make == 'test-release'
run: |
ps aux | grep timetable_vsu_backend | grep config && curl http://localhost:8080/ping -v
ps aux | grep timetable_vsu_backend_release && curl http://localhost:8080/ping -v
- name: Stop all
if: matrix.make == 'test-release'
run: |
killall timetable_vsu_backend
killall timetable_vsu_backend_release
2 changes: 1 addition & 1 deletion .github/workflows/delete_old_runs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
dry_run: ${{ github.event.inputs.dry_run }}
dry_run: ${{ github.event.inputs.dry_run }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ cmake-build-*
Testing/
configs/static_config.yaml
Makefile.local
merged_api.yaml
merged_api.yaml
tests/results
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
94 changes: 69 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,45 @@ cmake-debug cmake-release: cmake-%: build_%/Makefile
build-debug build-release: build-%: cmake-%
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend

# Test
# Test All
.PHONY: test-debug test-release
test-debug test-release: test-%: build-%
@rm -rf tests/results
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend_unittest
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend_benchmark
@cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
@pep8 tests

#run only testsuite tests
#use make testsuite-debug F="some regex" if you want filter tests by regex
.PHONY: testsuite-debug testsuite-release
testsuite-debug testsuite-release: testsuite-%: build-%
@rm -rf tests/results
@cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes -k $(F)" ctest -V -R "testsuite"))

# Start the service (via testsuite service runner)
.PHONY: service-start-debug service-start-release
service-start-debug service-start-release: service-start-%: build-%
@cd ./build_$* && $(MAKE) start-timetable_vsu_backend

.PHONY: add-eol
add-eol:
@find $(P) -type f | while read file; do \
if ! tail -c1 "$$file" | grep -q "^$$"; then \
# echo "Adding EOL to $$file"; \
echo >> "$$file"; \
fi \
done

# Cleanup data
.PHONY: clean-debug clean-release
clean-debug clean-release: clean-%:
cd build_$* && $(MAKE) clean

.PHONY: check-pep8
check-pep8:
@pep8 tests

.PHONY: dist-clean
dist-clean:
@rm -rf build_*
Expand All @@ -64,25 +85,47 @@ dist-clean:
install-debug install-release: install-%: build-%
@cd build_$* && \
cmake --install . -v --component timetable_vsu_backend
mv /usr/local/bin/timetable_vsu_backend /usr/local/bin/timetable_vsu_backend_$*

.PHONY: nothing-debug nothing-release
nothing-debug nothing-release:

.PHONY: run-debug run-release
run-debug run-release: run-%: nothing-%
@/usr/local/bin/timetable_vsu_backend_$* --config /usr/local/etc/timetable_vsu_backend/static_config.yaml

.PHONY: install
install: install-release
.PHONY: install-run-debug install-run-release
install-run-debug install-run-release: install-run-%: install-%
$(MAKE) run-$*

.PHONY: format-cpp
format-cpp:
@find benchs -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
@find service -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
@find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
@find utests -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
$(MAKE) add-eol P=benchs
$(MAKE) add-eol P=service
$(MAKE) add-eol P=src
$(MAKE) add-eol P=utests

# Format the sources
.PHONY: format-all
format-all: format-cpp
@find tests -name '*.py' -type f | xargs autopep8 -i
$(MAKE) add-eol P=tests
$(MAKE) add-eol P=scripts
$(MAKE) add-eol P=postgresql
$(MAKE) add-eol P=configs_testing
$(MAKE) add-eol P=configs
$(MAKE) add-eol P=CMakeLists.txt
$(MAKE) add-eol P=redocly.yaml
$(MAKE) add-eol P=united_api.yaml

# Check format the sources
.PHONY: check-format
check-format: check-format-cpp
$(MAKE) check-pep8

.PHONY: check-git-status
check-git-status:
Expand Down Expand Up @@ -120,30 +163,31 @@ gen:

@find utests -name '*pp' > .gen/unittest.txt
@LC_COLLATE=C sort .gen/unittest.txt -r -o .gen/unittest.txt
$(MAKE) add-eol P=.gen

.PHONY: unite-api
unite-api:
@python3 scripts/merge_yaml.py api/api.yaml united_api.yaml

# Internal hidden targets that are used only in docker environment
--in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
@sed -i 's/config_vars.yaml/config_vars.docker.yaml/g' /home/user/.local/etc/timetable_vsu_backend/static_config.yaml
@psql 'postgresql://user:password@service-postgres:5432/timetable_vsu_backend_db-1' -f ./postgresql/data/initial_data.sql
@/home/user/.local/bin/timetable_vsu_backend \
--config /home/user/.local/etc/timetable_vsu_backend/static_config.yaml

# Build and run service in docker environment
.PHONY: docker-start-service-debug docker-start-service-release
docker-start-service-debug docker-start-service-release: docker-start-service-%:
@docker-compose run -p 8080:8080 --rm timetable_vsu_backend-container $(MAKE) -- --in-docker-start-$*

# Start targets makefile in docker environment
.PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release
docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release: docker-%:
docker-compose run --rm timetable_vsu_backend-container $(MAKE) $*

# Stop docker container and remove PG data
.PHONY: docker-clean-data
docker-clean-data:
@docker-compose down -v
@rm -rf ./.pgdata
# # Internal hidden targets that are used only in docker environment
# --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
# @sed -i 's/config_vars.yaml/config_vars.docker.yaml/g' /home/user/.local/etc/timetable_vsu_backend/static_config.yaml
# @psql 'postgresql://user:password@service-postgres:5432/timetable_vsu_backend_db-1' -f ./postgresql/data/initial_data.sql
# @/home/user/.local/bin/timetable_vsu_backend \
# --config /home/user/.local/etc/timetable_vsu_backend/static_config.yaml

# # Build and run service in docker environment
# .PHONY: docker-start-service-debug docker-start-service-release
# docker-start-service-debug docker-start-service-release: docker-start-service-%:
# @docker-compose run -p 8080:8080 --rm timetable_vsu_backend-container $(MAKE) -- --in-docker-start-$*

# # Start targets makefile in docker environment
# .PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release
# docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release: docker-%:
# docker-compose run --rm timetable_vsu_backend-container $(MAKE) $*

# # Stop docker container and remove PG data
# .PHONY: docker-clean-data
# docker-clean-data:
# @docker-compose down -v
# @rm -rf ./.pgdata
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,27 @@ Makefile contains typicaly useful targets for development:
* `make test-release` - does a `make build-release` and runs all the tests on the result
* `make service-start-debug` - builds the service in debug mode and starts it
* `make service-start-release` - builds the service in release mode and starts it
* `make install-debug` - builds the service in debug mode and install it
* `make install-release` - builds the service in release mode and install it
* `make run-debug` - runs installed debug service
* `make run-release` - runs installed release service
* `make install-run-debug` - builds the service in debug mode install and run it
* `make install-run-release` - builds the service in release mode install and run it
* `make` or `make all` - builds and runs all the tests in release and debug modes
* `make format-all` - autoformat all the C++ and Python sources
* `make format-cpp` - autoformat all the C++ sources
* `make clean-` - cleans the object files
* `make dist-clean` - clean all, including the CMake cached configurations
* `make install` - does a `make build-release` and run install in directory set in environment `PREFIX`
* `make install-debug` - does a `make build-debug` and runs install in directory set in environment `PREFIX`
* `make docker-COMMAND` - run `make COMMAND` in docker environment
* `make docker-build-debug` - debug build of the service with all the assertions and sanitizers enabled in docker environment
* `make docker-test-debug` - does a `make build-debug` and runs all the tests on the result in docker environment
* `make docker-start-service-release` - does a `make install-release` and runs service in docker environment
* `make docker-start-service-debug` - does a `make install-debug` and runs service in docker environment
* `make docker-clean-data` - stop docker containers
* `make gen` - regenerate source lists for CMake in .gen
* `make check-format-cpp` - сheck formatting in C++ sources, if something is not formatted, an error will be returned
* `make check-pep8` - сheck formatting in Python sources, if something is not formatted, an error will be returned
* `make check-format-all` - сheck formatting in all sources, if something is not formatted, an error will be returned
* `make unite-api` - create united api file(merged_api.yaml)
* `make check-git-status` - сheck if there are changes in files
* `make testsuite-debug F='somestring'` - does a `make build-debug` and runs all the python tests on the result which are filtred by 'somestring'
* `make testsuite-release F='somestring'` - does a `make build-debug` and runs all the python tests on the result which are filtred by 'somestring'

Edit `Makefile.local` to change the default configuration and build options.

Expand All @@ -49,4 +52,4 @@ Use `ln -s build_debug/compile_commands.json compile_commands.json`
## License

The original template is distributed under the [Apache-2.0 License](https://github.com/userver-framework/userver/blob/develop/LICENSE)
and [CLA](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md).
and [CLA](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md).
2 changes: 1 addition & 1 deletion api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ paths:
/admin/teacher/link:
$ref: views/admin/teacher/link/view.yaml
/admin/teacher/unlink:
$ref: views/admin/teacher/unlink/view.yaml
$ref: views/admin/teacher/unlink/view.yaml
2 changes: 1 addition & 1 deletion api/types/AuthTokenV1.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
description: 'Используется для аунтефикации пользователя. Передаем строго через куки'
allOf:
- $ref: './Id.yaml'
- $ref: './Id.yaml'
12 changes: 6 additions & 6 deletions api/types/Day.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type: string
enum:
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
- monday
- tuesday
- wednesday
- thursday
- friday
- saturday
Loading

0 comments on commit d2463b8

Please sign in to comment.