|
10 | 10 |
|
11 | 11 | int main() |
12 | 12 | { |
13 | | - try |
14 | | - { |
15 | | - // TODO(https://github.com/TourmalineCore/to-dos-api-cpp/issues/27): add migration update on startup |
16 | | - |
17 | | - const std::string user = std::getenv("POSTGRES_USER"); |
18 | | - const std::string password = std::getenv("POSTGRES_PASSWORD"); |
19 | | - const std::string db_name = std::getenv("POSTGRES_DB"); |
20 | | - const std::string host = std::getenv("POSTGRES_HOST"); |
21 | | - const std::string port = std::getenv("POSTGRES_PORT"); |
22 | | - |
23 | | - std::string conninfo = "host=" + host + " port=" + port + " dbname=" + db_name + " user=" + user + " password=" + password; |
24 | | - |
25 | | - std::unique_ptr<odb::database> db(new odb::pgsql::database(conninfo)); |
26 | | - |
27 | | - ToDoQueries todo_queries(*db); |
28 | | - ToDoCommands todo_commands(*db); |
29 | | - const std::time_t now_utc = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); |
30 | | - uint64_t added_todo = todo_commands.create_todo("random_todo", now_utc); |
31 | | - std::cout << "Added TODO:" << added_todo << std::endl; |
32 | | - uint64_t soft_removed_todo = todo_commands.soft_delete_todo(added_todo); |
33 | | - std::cout << "Soft Removed TODO:" << soft_removed_todo << std::endl; |
34 | | - uint64_t removed_todo = todo_commands.delete_todo(added_todo); |
35 | | - std::cout << "Removed TODO:" << removed_todo << std::endl; |
36 | | - |
37 | | - std::shared_ptr<std::vector<ToDo>> todos = todo_queries.get_all_todos(); |
38 | | - std::shared_ptr<ToDo> todo = todo_queries.get_todo_by_id(1); |
39 | | - |
40 | | - |
41 | | - if (todos && todo) |
42 | | - { |
43 | | - std::cout << "Found TODOs:" << todos->size() << std::endl; |
44 | | - const std::time_t t = todo->createdAtUtc(); |
45 | | - std::tm tm {}; |
46 | | - gmtime_r(&t, &tm); |
47 | | - std::cout << "Found TODO id:" << todo->id() << " createdAtUtc: " << std::put_time(&tm, "%Y-%m-%d %H:%M:%S UTC") << std::endl; |
48 | | - } |
49 | | - else |
50 | | - { |
51 | | - std::cout << "TODO or TODOs not founded" << std::endl; |
52 | | - } |
53 | | - } |
54 | | - catch (const odb::exception& e) |
55 | | - { |
56 | | - std::cerr << "Error ODB: " << e.what() << std::endl; |
57 | | - return 1; |
58 | | - } |
59 | | - catch (const std::exception& e) |
60 | | - { |
61 | | - std::cerr << "Error: " << e.what() << std::endl; |
62 | | - return 1; |
63 | | - } |
64 | | - |
65 | 13 | drogon::app().addListener("127.0.0.1", 8080); |
66 | 14 | drogon::app().run(); |
67 | 15 |
|
|
0 commit comments