Skip to content

TourmalineCore/to-dos-api-cpp

Repository files navigation

to-dos-api-cpp

How to build this project

It is recommended to build library and run tests using Dev containers in Visual Studio Code. For development purposes use a devcontainer named developing.

Prerequisites

  • Install WSL
  • Install the Docker client (Windows / Mac / Linux)
    • Make sure Docker client is the latest version

    dockerVersion

    - Make sure Docker uses WSL 2 based engine

    dockerSettings

  • Microsoft VS Code
    • VS Code should also have the "Dev Containers" extension installed. To check it, open "View: Extensions" with Ctrl + Shift + X or as shown in the screenshot below:

    vscodeExtensions

  • Make sure Docker daemon is running before opening the dev container (Ctrl + Shift + P -> "Reopen in container" or click here + "Reopen in container")

vscodeContainer

Project building

To build this project, open the VS Code terminal (Ctrl + Shift + ~) and run conan install . --build=missing. After the Conan install process, open the CMake extension and click Configure.

cmakeConfigure

In the configuration options, select the `'conan-debug' config`.

When the project configuration is finished, click Build to build the project.

cmakeBuild

Project run

Before launching web server:

  • Run the database container via docker compose command docker compose up -d from workspace.
  • Import environment variables declared in the .env file while in the dev container and using the command export $(grep -v '^#' .env | xargs). If the file containing the environment variables is named something other than .env, you should modify the command to specify the correct name.

To launch the executable, click Launch in the CMake extension.

cmakeLaunch

Linters

The project includes the clang-tidy code analyzer and the clang-format formatter. Configuration files are located in the project root: .clang-tidy and .clang-format, respectively.

To use linters you need to install:

Clang-format

Clang-format code formatting occurs automatically when saving a file using the CodeAnalysis C/C++ extension.

To start manually, you need to run the command find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run, while in the root of the project.

To automatically fix errors, run find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format -i from the project root.

Clang-tidy

Clang-tidy code checking occurs in the background using the CodeAnalysis C/C++ extension.

To start manually, you need to run the command find ./src -name "*.cpp" -o -name "*.h" | xargs clang-tidy -p ./build/Debug | grep "error:", while in the root of the project.

Tests run

The project presents an example of test implementation using GTest tools. Test files are located in the test directory at the root of the project. Inside the test directory there is a CMakeLists.txt file created specifically for building a separate executable file for tests.

How to run tests

To run tests, go to the build/Debug directory, and then run the ctest command in the terminal (Ctrl + Shift + ~).

Alternatively, use the CMake Tools Extension in VS Code. To do this, open the CMake Tools Extension and click Test, after configuring and building the project.

cmakeTests

Working with ORM+Migration.

ORM:

After creating the database or model, it is necessary to generate the auxiliary ODB files with the command odb --std c++20 -d pgsql --generate-query -o odb-gen <model header file> from the folder src/data/models.

After executing the command, files will be created or updated in the folder `src/data/models/odb-gen'. Please do not modify or transfer these files for the correct operation of the application.

Migrations:

The alembic tool is used to work with migrations. To work with it, you need to modify or create a python model according to the cpp version of the model.

  • Create/change python model according declared cpp model.
  • Change terminal workspace to src/data.
  • Use the alembic command alembic revision --autogenerate -m '<name of migration>' for create new migration to database.
  • If its needed upgrade local database with latest migration with commnd alembic upgrade head.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •