From c2d1ebb257da185f1a88840047f59a8e938ac634 Mon Sep 17 00:00:00 2001 From: Alexander Goussas Date: Sat, 27 Jun 2026 11:34:25 -0500 Subject: [PATCH] feat: use c++ ranges in fetch questions endpoint --- .clang-format | 2 +- CMakeLists.txt | 2 +- main.cpp | 13 +++++-------- question_repository.cpp | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.clang-format b/.clang-format index 64a22d2..c36b7f1 100644 --- a/.clang-format +++ b/.clang-format @@ -14,7 +14,7 @@ AllowAllParametersOfDeclarationOnNextLine: false BinPackParameters: false AlignAfterOpenBracket: AlwaysBreak AlwaysBreakTemplateDeclarations: Yes -ColumnLimit: 80 +ColumnLimit: 100 AllowShortEnumsOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: Empty diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d87de2..289c3ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/main.cpp b/main.cpp index a82f30f..5b96ae0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +#include #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(); return crow::json::wvalue { dtos }; }); + // TODO: Fetch port from env variable. app.port(18080).multithreaded().run(); return 0; diff --git a/question_repository.cpp b/question_repository.cpp index aa2545e..f851046 100644 --- a/question_repository.cpp +++ b/question_repository.cpp @@ -1,5 +1,6 @@ #include "question_repository.hpp" +// TODO: Implement an external provider for questions. static std::vector questions = { "What does your morning routine look like?", "What do you like the most about your job?" }; -- 2.43.0