oatpp / example-postgresql

A complete example of a "CRUD" service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.
https://oatpp.io/
Apache License 2.0
38 stars 18 forks source link
cpp microservices oatpp orm postgresql swagger-ui

example-postgresql Build Status

A complete example of a "CRUD" service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.

In this example:

More about Oat++:

Overview

This project is using the following oatpp modules:

Project layout

|- CMakeLists.txt                        // projects CMakeLists.txt
|- src/
|    |
|    |- controller/                      // Folder containing Controller where all endpoints are declared
|    |- db/                              // Folder containing the database client
|    |- dto/                             // DTOs are declared here
|    |- service/                         // Service business logic classes (UserService)
|    |- ServiceComponent.hpp             // Service configuration (port, ObjectMapper, Database)
|    |- SwaggerComponent.hpp             // Configuration for swagger-ui
|    |- AppComponent.hpp                 // Service configuration is loaded here
|    |- DatabaseComponent.hpp            // Database config
|    |- App.cpp                          // main() is here
|    
|- test/                                 // test folder
|- utility/install-oatpp-modules.sh      // utility script to install required oatpp-modules.
|- resources/config.json                 // configuration file with configuration profiles
|- Dockerfile                            // Dockerfile
|- docker-compose.yaml                   // Docker-compose with this service and postgresql

Build and Run

Using CMake

Requires

$ mkdir build && cd build
$ cmake ..
$ make 
$ ./example-postgresql-exe  # - run application.

PostgreSQL is expected running as for dev config profile

In Docker

Dockerfile

$ docker build -t example-postgresql .
$ docker run -p 8000:8000 -e CONFIG_PROFILE='dev' -t example-postgresql

docker-compose

$ docker-compose up

docker-compose will run service with local-docker config profile

After run

Go to http://localhost:8000/swagger/ui to try endpoints.