forked from Allaeddineattia/Valravn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
86 lines (55 loc) · 2.47 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <RestServer/AppComponent.h>
#include "oatpp-swagger/Controller.hpp"
#include "src/RestServer/Controller/ImageController.h"
#include "oatpp/network/Server.hpp"
#include <iostream>
#include <Entity/Contract/DependencyInjector.h>
void init_imagerepo(){
string fileName = "test.db";
shared_ptr<DependencyInjector> di = make_shared<DependencyInjector> ();
di->install_data_base(fileName);
di->install_multimedia_repo(di);
di->install_image_repo(di);
auto db = di->get_data_base(di);
db->init_db();
auto multimedia_repo = di->get_multimedia_repo(di);
Multimedia::installRepo(multimedia_repo);
auto image_repo = di->get_image_repo(di);
Image::installRepo(image_repo);
}
void run() {
AppComponent components; // Create scope Environment components
/* create ApiControllers and add endpoints to router */
auto router = components.httpRouter.getObject();
auto docEndpoints = oatpp::swagger::Controller::Endpoints::createShared();
auto userController = ImageController::createShared();
userController->addEndpointsToRouter(router);
docEndpoints->pushBackAll(userController->getEndpoints());
auto swaggerController = oatpp::swagger::Controller::createShared(docEndpoints);
swaggerController->addEndpointsToRouter(router);
/* Get connection handler component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
/* Get connection provider component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
/* create server */
oatpp::network::Server server(connectionProvider,
connectionHandler);
OATPP_LOGD("Server", "Running on port %s...", connectionProvider->getProperty("port").toString()->c_str());
server.run();
}
/**
* main
*/
int main(int argc, const char * argv[]) {
init_imagerepo();
oatpp::base::Environment::init();
run();
/* Print how much objects were created during app running, and what have left-probably leaked */
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
std::cout << "\nEnvironment:\n";
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
oatpp::base::Environment::destroy();
return 0;
}