]> git.frustrated-labs.net Git - open-the-box.git/commitdiff
feat: use c++ ranges in fetch questions endpoint
authorAlexander Goussas <[email protected]>
Sat, 27 Jun 2026 16:34:25 +0000 (11:34 -0500)
committerAlexander Goussas <[email protected]>
Sat, 27 Jun 2026 16:34:25 +0000 (11:34 -0500)
.clang-format
CMakeLists.txt
main.cpp
question_repository.cpp

index 64a22d28c5e6c093d3c51193e1ce44f80d9102c2..c36b7f11967de01adcfa13c0453728c983cdfaa3 100644 (file)
@@ -14,7 +14,7 @@ AllowAllParametersOfDeclarationOnNextLine: false
 BinPackParameters: false
 AlignAfterOpenBracket: AlwaysBreak
 AlwaysBreakTemplateDeclarations: Yes
-ColumnLimit: 80
+ColumnLimit: 100
 AllowShortEnumsOnASingleLine: true
 AllowShortCaseLabelsOnASingleLine: true
 AllowShortFunctionsOnASingleLine: Empty
index 1d87de2d6f64f6b85d07a49980b3009a239f8fa7..289c3ecb3e7d7e024ea629b9ed8678313a293bf9 100644 (file)
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18)
 
 project(open-the-box)
 
-set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD 23)
 
 set(DCROW_BUILD_EXAMPLES OFF)
 set(CROW_BUILD_TESTS OFF)
index a82f30ff59543f86a0209b3b18779f3eeb5531f4..5b96ae04bf2359c82e134bb285ed3ec0d2d26e74 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,5 @@
 #include <crow.h>
+#include <ranges>
 
 #include "question.hpp"
 #include "question_dto.hpp"
@@ -7,20 +8,16 @@
 auto main() -> int
 {
     crow::SimpleApp app;
-
     InMemoryQuestionRepository questions;
 
     CROW_ROUTE(app, "/questions")([&]() {
-        auto qs = questions.list_questions();
-        crow::json::wvalue::list dtos;
-        for (auto q : qs)
-        {
-            dtos.push_back(QuestionDto(q).json());
-        }
-
+        auto dtos = questions.list_questions()
+            | std::views::transform([](auto q) { return QuestionDto(q).json(); })
+            | std::ranges::to<std::vector>();
         return crow::json::wvalue { dtos };
     });
 
+    // TODO: Fetch port from env variable.
     app.port(18080).multithreaded().run();
 
     return 0;
index aa2545ea5e3d18f62810fe791a7d5bf58195eacb..f8510466437819e63723685c1745d463614b5207 100644 (file)
@@ -1,5 +1,6 @@
 #include "question_repository.hpp"
 
+// TODO: Implement an external provider for questions.
 static std::vector<Question> questions
     = { "What does your morning routine look like?",
         "What do you like the most about your job?" };