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

  • Before running the container, create a .env file in the project root and specify the environment variables in it, just as you did in .env.example. Otherwise, running the devcontainer will result in an error.
  • 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

Build for ARMv8

To compile dependencies this project to run to-dos-api in the ARMv8 environment, use the command conan install . -pr:h profiles/to-dos-conan-profile-arm64.conf --build=missing instead of the one specified in the previous paragraph in the terminal.

When dependencies are built, use the command conan build . -pr:h profiles/to-dos-conan-profile-arm64.conf to build to-dos-api for running in an ARMv8 environment.

Project run

Before launching web server:

  • Run the database container via docker compose command docker compose up -d from workspace.
  • Import the environment variables defined in the .env file in the project root. The environment variables were automatically exported from .env when the container was built. If the contents of the .env file have been modified after the container was built, run the command export $(grep -v '^#' .env | xargs), but keep in mind that the environment variables will only be visible in the terminal session where the command was executed.

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

cmakeLaunch

Alternatively, you can use make targets.

  • To run the application, use the make run command. When the command is executed, the project's dependencies will be checked and, if necessary, installed and compiled.

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, 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.

Alternatively, you can use make targets.

  • To run the code analyzer, use the make run-tidy command.

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. For generating these files use script ./scripts/generate_odb_files.sh

After executing the script, 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.

Alternatively, you can use make targets.

  • To create a migration, run the command make create-migration name=<name-of-migration>, where name is the name of the migration. You can also use make create-migration, in which case the migration will be named after the current date and time.
  • To apply the migrations, run the make apply-migrations command.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors