generated from Sithas/conan_template
Compare commits
130 Commits
431b183e01
...
ffad41e92b
| Author | SHA1 | Date | |
|---|---|---|---|
| ffad41e92b | |||
| 5346bb2849 | |||
| 2b5e601387 | |||
| d57e6c3414 | |||
| a5500d4fb3 | |||
| 0042b7e6bc | |||
| 0ef4c7e46c | |||
| 049fcf0f48 | |||
| 3db3778789 | |||
| 4eaf6ab2a1 | |||
| 91afa176dd | |||
| a38b97bea3 | |||
| 02d3f2e3a5 | |||
| 8082a83400 | |||
| a9d75ffb80 | |||
| a715d62961 | |||
| 2acd382f0c | |||
| 7469a61ca4 | |||
| 9eac7d683f | |||
| ad69f8dab6 | |||
| 355d03aaac | |||
| 8ede71fe48 | |||
| 9832034de5 | |||
| d8cbdaf635 | |||
| d4c01cd70c | |||
| 353ff528a8 | |||
| ef05ea511a | |||
| e823186824 | |||
| 5503368b23 | |||
| 5cc24f0592 | |||
| ffd193ea43 | |||
| c6f2240c4d | |||
| 0850286c63 | |||
| b6ddf88a61 | |||
| c7bd64ec9b | |||
| fb0cbd0161 | |||
| bd5b7dd6ac | |||
| 0214deb688 | |||
| 3a5176785e | |||
| 891d67d3d3 | |||
| baacacc230 | |||
| 4df3e4a140 | |||
| d5fa9d53db | |||
| b012faf1b6 | |||
| 0838b96a27 | |||
| cc95543407 | |||
| 7e5970b01f | |||
| 5eb0b9c1e1 | |||
| b99173d959 | |||
| 851023522e | |||
| 04df65aa50 | |||
| af321ff534 | |||
| eb22915b76 | |||
| b632e6e3bb | |||
| c1019b0d5e | |||
| 5c226faf8a | |||
| 203ae876bb | |||
| eea5e42573 | |||
| 07a9bbf9ff | |||
| d303dbf71b | |||
| 799890147e | |||
| c985a87108 | |||
| 64fbe5fcb9 | |||
| 022a262241 | |||
| d6d2f5a331 | |||
| 4e2a97edcb | |||
| e27e908ff7 | |||
| ca18bb9464 | |||
| 61f96c00bb | |||
| 2e9b024d0f | |||
| c541b81fed | |||
| 83a99bbad7 | |||
| 39b1625fb5 | |||
| aaf5701fdb | |||
| f34c875ba4 | |||
| 8cb1023d68 | |||
| 2e830544b1 | |||
| 918db80742 | |||
| 029f9c2fd3 | |||
| d53814c3cc | |||
| 823c6ccfe9 | |||
| 8121534981 | |||
| 20d1c29e9e | |||
| 907b74ad92 | |||
| 36362dc0a4 | |||
| aafd5f58af | |||
| 2dcf3a3f89 | |||
| 3a37f1d68d | |||
| 1fedfb1c2d | |||
| 05038ef65d | |||
| 94b5dd066c | |||
| 457526bd10 | |||
| 7ef9a6a6c1 | |||
| a08a0d9a63 | |||
| 65f68576f8 | |||
| f08071964a | |||
| 333af6d3b4 | |||
| 0edd089a62 | |||
| d7c4eb128f | |||
| b4f0bd348f | |||
| c7b29029d0 | |||
| 7b65cd8c2a | |||
| d5a16f246a | |||
| b7c6498126 | |||
| 6571cad5ff | |||
| f051cdf4b5 | |||
| 4c12c2295a | |||
| 715214b5a0 | |||
| f388a207c2 | |||
| 4018d48f35 | |||
| f65ecf97f2 | |||
| f2c139616a | |||
| c4254c2f6b | |||
| 3d7a7ccc04 | |||
| 321116ac90 | |||
| 8cedc84947 | |||
| b6c914f6f8 | |||
| e6823ce506 | |||
| 8752a8bd85 | |||
| 737e94522c | |||
| 548cfb5668 | |||
| 89617b128e | |||
| 051e5a8747 | |||
| 099a04fd92 | |||
| 76907d3f98 | |||
| d25e9f16a7 | |||
| 49a322b3df | |||
| 51292d1d2e | |||
| 5848ceee3c | |||
| f4b8604267 |
@@ -0,0 +1,53 @@
|
||||
# Generated from CLion C/C++ Code Style settings
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: LLVM
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignOperands: false
|
||||
AlignTrailingComments: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: true
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBraces: Custom
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 100
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ContinuationIndentWidth: 2
|
||||
IncludeCategories:
|
||||
- Regex: '^<.*'
|
||||
Priority: 1
|
||||
- Regex: '^".*'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IndentCaseBlocks: true
|
||||
InsertNewlineAtEOF: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 2
|
||||
PointerAlignment: Left
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
TabWidth: 2
|
||||
...
|
||||
+70
-21
@@ -1,28 +1,77 @@
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
cmake_minimum_required(VERSION 3.29.8)
|
||||
project(UpAndDown)
|
||||
|
||||
project(App CXX)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
find_package(Boost 1.84.0 REQUIRED)
|
||||
if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
if(POLICY CMP0167)
|
||||
cmake_policy(SET CMP0167 OLD)
|
||||
endif()
|
||||
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
|
||||
set(Boost_LIBRARY_DIR "${BOOST_ROOT}/stage/lib")
|
||||
|
||||
find_package(Boost 1.88.0 REQUIRED COMPONENTS filesystem json log)
|
||||
if (Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIR})
|
||||
endif ()
|
||||
|
||||
find_package(mysql-concpp REQUIRED)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
add_executable(application src/main.cpp
|
||||
src/helpers.h
|
||||
src/helper.cpp
|
||||
src/sdk.h
|
||||
src/Session.h
|
||||
src/Session.cpp
|
||||
src/Listener.h
|
||||
src/Listener.cpp
|
||||
src/content_type.h
|
||||
src/RequestHandlers/BasicRequestHandler.cpp
|
||||
src/RequestHandlers/BasicRequestHandler.h)
|
||||
target_link_libraries(application PRIVATE Threads::Threads)
|
||||
add_executable(App ./src/main.cpp
|
||||
./src/helpers/helpers.h
|
||||
./src/helpers/helpers.cpp
|
||||
./src/endpoints_handlers/HandleRequest.h
|
||||
./src/endpoints_handlers/IController.h
|
||||
./src/endpoints_handlers/Controller.h
|
||||
./src/session/HttpSession.h
|
||||
./src/session/HttpSession.cpp
|
||||
./src/session/WebsocketSession.h
|
||||
./src/session/WebsocketSession.cpp
|
||||
./src/listener/Listener.h
|
||||
./src/listener/Listener.cpp
|
||||
./src/db/mysql_connector.cpp
|
||||
./src/db/mysql_connector.h
|
||||
./src/DAO/IUserDAO.h
|
||||
./src/entities/user.h
|
||||
./src/DAO/MySQLUserDAO.cpp
|
||||
./src/DAO/MySQLUserDAO.h
|
||||
./src/endpoints_handlers/IExecutor.h
|
||||
./src/endpoints_handlers/AuthRegistrationExecutor.h
|
||||
./src/endpoints_handlers/RootExecutor.h
|
||||
./src/DAO/IAuthDAO.h
|
||||
./src/DAO/MemoryAuthDAO.cpp
|
||||
./src/DAO/MemoryAuthDAO.h
|
||||
./src/endpoints_handlers/AuthLogoutExecutor.h
|
||||
./src/exceptions/session_exception.cpp
|
||||
./src/exceptions/session_exception.h
|
||||
)
|
||||
|
||||
target_link_libraries(App PRIVATE Boost::boost Boost::json Threads::Threads mysql::concpp)
|
||||
|
||||
if (MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
||||
endif ()
|
||||
|
||||
add_executable(HelpersTests ./tests/helpers/helpers_TEST.cpp
|
||||
./src/helpers/helpers.h
|
||||
./src/helpers/helpers.cpp)
|
||||
target_link_libraries(HelpersTests PRIVATE Boost::boost)
|
||||
add_test(HelpersTests HelpersTests)
|
||||
|
||||
add_executable(ControllerTests ./tests/endpoint_handlers/Controller_TEST.cpp
|
||||
./src/endpoints_handlers/IController.h
|
||||
./src/endpoints_handlers/Controller.h)
|
||||
target_link_libraries(ControllerTests PRIVATE Boost::boost)
|
||||
add_test(ControllerTests ControllerTests)
|
||||
|
||||
if (WIN32)
|
||||
target_compile_definitions(App PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
target_compile_definitions(HelpersTests PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
target_compile_definitions(ControllerTests PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
endif()
|
||||
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<code_scheme name="Nihilus" version="173">
|
||||
<option name="AUTODETECT_INDENTS" value="false" />
|
||||
<option name="RIGHT_MARGIN" value="100" />
|
||||
<Objective-C>
|
||||
<option name="INDENT_CLASS_MEMBERS" value="2" />
|
||||
<option name="INDENT_VISIBILITY_KEYWORDS" value="1" />
|
||||
<option name="NAMESPACE_BRACE_PLACEMENT" value="2" />
|
||||
<option name="METHOD_BRACE_PLACEMENT" value="2" />
|
||||
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
|
||||
<option name="BLOCK_BRACE_PLACEMENT" value="2" />
|
||||
<option name="FUNCTION_PARAMETERS_WRAP" value="0" />
|
||||
<option name="FUNCTION_CALL_ARGUMENTS_WRAP" value="0" />
|
||||
<option name="CLASS_CONSTRUCTOR_INIT_LIST_WRAP" value="0" />
|
||||
<option name="CLASS_CONSTRUCTOR_INIT_LIST_NEW_LINE_BEFORE_COLON" value="1" />
|
||||
<option name="SPACE_WITHIN_EMPTY_BRACES" value="true" />
|
||||
<option name="SPACE_BEFORE_PROTOCOLS_BRACKETS" value="false" />
|
||||
<option name="SPACE_BEFORE_REFERENCE_IN_DECLARATION" value="false" />
|
||||
<option name="SPACE_AFTER_REFERENCE_IN_DECLARATION" value="true" />
|
||||
<option name="HEADER_GUARD_STYLE_PATTERN" value="_${FILE_NAME}_${EXT}_" />
|
||||
</Objective-C>
|
||||
<RiderCodeStyleSettings>
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="2" type="long" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="2" type="long" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Classes_0020and_0020structs/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Classes_0020and_0020structs/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Concepts/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Concepts/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Enums/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Enums/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Unions/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Unions/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Template_0020parameters/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Template_0020parameters/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Parameters/@EntryIndexedValue" value="<NamingElement Priority="2"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aa_bb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Local_0020variables/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Local_0020variables/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020variables/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020variables/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020functions/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020functions/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020fields/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020fields/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020public_0020fields/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020public_0020fields/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Union_0020members/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Union_0020members/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Enumerators/@EntryIndexedValue" value="<NamingElement Priority="8"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="scoped enumerator" /><type Name="unscoped enumerator" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="k" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Other_0020constants/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Other_0020constants/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020constants/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020constants/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Namespaces/@EntryIndexedValue" value="<NamingElement Priority="9"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="namespace" /><type Name="namespace alias" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aa_bb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Typedefs/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Typedefs/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Macros/@EntryIndexedValue" value="<NamingElement Priority="10"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="macro" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Properties/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Properties/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Events/@EntryIndexedValue" value="" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Events/@EntryIndexRemoved" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Types/@EntryIndexedValue" value="<NamingElement Priority="1"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="concept" /><type Name="enum" /><type Name="struct" /><type Name="type alias" /><type Name="type template parameter" /><type Name="typedef" /><type Name="union" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Common_0020Variables/@EntryIndexedValue" value="<NamingElement Priority="3"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /><type Name="local variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aa_bb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Struct_0020Data_0020Members/@EntryIndexedValue" value="<NamingElement Priority="4"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="struct field" /><type Name="union member" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aa_bb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020Data_0020Members/@EntryIndexedValue" value="<NamingElement Priority="5"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="_" Style="aa_bb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Constants/@EntryIndexedValue" value="<NamingElement Priority="6"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="k" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Functions/@EntryIndexedValue" value="<NamingElement Priority="7"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /><type Name="member function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aa_bb" /></Policy></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Non_002DType_0020Template_0020Parameters/@EntryIndexedValue" value="<NamingElement Priority="11"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="non-type template parameter" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInIfStatement/@EntryValue" value="Required" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInForStatement/@EntryValue" value="Required" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesInWhileStatement/@EntryValue" value="Required" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/BracesRedundant/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_CASE/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_LIMIT/@EntryValue" value="100" type="long" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="None" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/ExecutableToUse/@EntryValue" value="Custom" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/ExternalClangFormatPath/@EntryValue" value="C:\CLionProjects\UpAndDown\.clang-format" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=0B82708A1BA7774EB13D27F245698A56/@EntryIndexedValue" value="<NamingElement Priority="1" Title="Classes and structs"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="aa_bb" /></Policy></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=8F69F48E2532F54CBAA0039D4557825E/@EntryIndexedValue" value="<NamingElement Priority="10" Title="Global functions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=B6E900853D6D05429D8C57765B2E546A/@EntryIndexedValue" value="<NamingElement Priority="11" Title="Class and struct methods"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=4203BE6F332C5149B409B4D5F7197E54/@EntryIndexedValue" value="<NamingElement Priority="15" Title="Enumerators"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="scoped enumerator" /><type Name="unscoped enumerator" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=BF0D1AE66D64FE4FAF613448A12051A0/@EntryIndexedValue" value="<NamingElement Priority="17" Title="Global constants"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/CppIncludeDirective/SortIncludeDirectives/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppCodeStyle/SortDefinitions/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINKAGE_SPECIFICATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EXPRESSION_BRACES/@EntryValue" value="OUTSIDE_AND_INSIDE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_FIRST_ARG_BY_PAREN/@EntryValue" value="true" type="bool" />
|
||||
</RiderCodeStyleSettings>
|
||||
<codeStyleSettings language="ObjectiveC">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,254 @@
|
||||
# TODO:
|
||||
|
||||
- ~~Сделать реальные исполнители(executors) для регистрации, авторизации, логаута~~
|
||||
- Посмотреть по поводу блокировок или тред пулла при использовании базы
|
||||
- Посмотреть пулл соединений(Object pool) при использовании базы данных(посмотреть api MySQL-Connector)
|
||||
- Посмотреть, что дает MySQL, какие там есть возможность
|
||||
- Посмотреть и подумать, что лучше - корутины или многопоточность?
|
||||
- Покрыть тестами класс User и AuthRegistrationExecutor
|
||||
- ~~Добавить clang-format(через CLion)~~
|
||||
- ~~Перевести GetByUUID GetByLogin на const ref/string_view в IUserDAO - также не vector, а span(погуглить)~~ - span не применим
|
||||
- ~~Привести к единому виду функции IUserDAO~~
|
||||
- ~~Пройтись по коду и максимально наставить const~~
|
||||
- ~~Указать возможные исключения в интерфейсах DAO - почему может выбросить исключение~~
|
||||
- ~~Вынести User в структуру. Hashed Password структура должна изначально состоять в другой структуре~~
|
||||
- ~~SharedPtr - передавать по константной ссылке.~~
|
||||
- ~~Вынести обработку исключений в RootExecutor~~
|
||||
- ~~Уменьшить дублирование кода в исключениях~~
|
||||
- Покрыть логами
|
||||
- ~~Сделать один класс исключений, имеющих метод HTTP code - код и сообщение записывать уже в ловушке~~
|
||||
- Сделать интеграционный тест по ручкам
|
||||
|
||||
# UseCase'ы приложения:
|
||||
|
||||
# Up And Down - система для учета и отслеживания состояния для людей, больных БАР
|
||||
|
||||
## UseCase №1
|
||||
### 1.Название: Зарегистрировать пользователя
|
||||
### 2.Актор: Пользователь
|
||||
### 3.Цель: Внести данные о новом пользователе в систему
|
||||
### 4.Предусловия:
|
||||
* Пользователь не авторизован в системе
|
||||
* Пользователь с данным login'ом отсутствует в системе
|
||||
### 5.Основной поток:
|
||||
#### А1.Пользователь при входе в систему выбрасывается из системы
|
||||
* Пользователь заходит в приложение на любую страницу
|
||||
* Из-за отсутсвия авторизации приложение перенаправляет его на страницу авторизации и регистрации
|
||||
* Пользователь кликает по ссылке, ведущей на странице регистрации
|
||||
* На странице регистрации пользователь вводит логин и пароль
|
||||
* Пользователь нажимает кнопку "Зарегистрироваться"
|
||||
* Система выводит сообщение, что пользователь зарегистрирован в приложении
|
||||
### 6.Потоки исключений:
|
||||
#### B1.Пользователь с таким логином уже есть в системе
|
||||
* Процедура регистрации проваливается
|
||||
* Выводится нотификация с сообщением об ошибке по причине наличия такого же логина в системе
|
||||
#### B2.Пользователь оставил пустым логин или пустой/неправильный пароль
|
||||
* При попытке регистрации подсвечиваются незаполненные поля, или поле пароля, если пароль неправильный
|
||||
* Выводится сообщение об ошибке
|
||||
### 7.Постусловия
|
||||
* Пользователь с указанным логином сохранен в БД
|
||||
### 8.API-Маршруты
|
||||
* `POST /api/v1/Auth/Register` - Регистрация пользователя
|
||||
### 9.Контракт
|
||||
#### Register-Request
|
||||
```
|
||||
{
|
||||
"login": "ivan_89",
|
||||
"password": "S3cureP@ssw0rd"
|
||||
}
|
||||
```
|
||||
##### Требования к валидации:
|
||||
* login: 3-50 символов, ^[A-Za-z0-9_]+$, уникальное значение
|
||||
* password: ≥ 5 символов
|
||||
|
||||
##### Response - 201 - Created
|
||||
```
|
||||
{
|
||||
"user": {
|
||||
"uuid": "51351bb1-7563-479d-a8e9-201d0ff934c2"
|
||||
"login": "ivan_89"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### Errors
|
||||
* `409 USER_EXISTS` — пользователь с таким логином уже есть(`B1`)
|
||||
* `422 VALIDATION_FAILED` — пустой логин/неправильный пароль(`B2`)
|
||||
* `400 BAD_REQUEST` — сервер не смог десереализовать JSON
|
||||
|
||||
### 10. Используемые сущности ДБ
|
||||
* users(uuid(PK), login(unique), hashed_password)
|
||||
|
||||
## UseCase №2
|
||||
### 1.Название: Авторизация пользователя
|
||||
### 2.Актор: Пользователь
|
||||
### 3.Цель: Предоставить пользователю возможность получить его данные в виде дневника болезни
|
||||
### 4.Предусловия:
|
||||
* Пользователь должен быть зарегистрирован в системе
|
||||
* Пользователь должен быть не авторизован в системе
|
||||
### 5.Основной поток:
|
||||
#### А1.Пользователь при входе в систему выбрасывается из системы
|
||||
* Пользователь заходит в приложение на любую страницу
|
||||
* Из-за отсутствия авторизации приложение перенаправляет его на страницу авторизации
|
||||
* Пользователь вводит свой логин и пароль
|
||||
* Пользователь получает токен, который открывает ему доступ к получению собственных данных
|
||||
#### А2.Пользователь осуществляет выход из системы
|
||||
* Пользователь кликает на кнопку логаута
|
||||
* На сервере происходил отзыв токена
|
||||
* Пользователь вновь считается неавторизованным
|
||||
### 6.Альтернативные потоки:
|
||||
#### B1.Введен неправильный логин или неправильный пароль
|
||||
* Пользователь не получает токен, авторизация провалена
|
||||
* Выводится сообщение об ошибке
|
||||
#### B2.Поле логин или пароль оставлены пустыми
|
||||
* При попытке авторизации не происходит запрос токена. Авторизация провалена
|
||||
* Пустые поля подкрашиваются, как ошибочно заполненные
|
||||
* Выводится сообщение об ошибке
|
||||
#### B3.Пользователь не был зарегистрирован в приложении на момент логаута
|
||||
* Сервер не может отозвать токен и возвращает ошибку
|
||||
### 7.Постусловия
|
||||
* Сессия пользователя в виде токена сохраняется на сервере
|
||||
* Пользователь перенаправлен на основную страницу, где выводится его дневник болезни
|
||||
### 8.API-Маршруты
|
||||
* `POST /api/v1/Auth/Login` - Вход пользователя в систему и получение токена
|
||||
* `POST /api/v1/Auth/Logout` - Отозвать токен и выйти из системы.
|
||||
### 9.Контракт
|
||||
#### Login-Request
|
||||
```
|
||||
{
|
||||
"login": "ivan_89",
|
||||
"password": "S3cureP@ssw0rd"
|
||||
}
|
||||
```
|
||||
##### Response - 200 - OK
|
||||
```
|
||||
{
|
||||
"token": af32df3bas739f272bd109c823
|
||||
}
|
||||
```
|
||||
|
||||
##### Errors
|
||||
* `401 BAD_CREDENTIALS` — неверный логин/пароль (B1)
|
||||
* `422 VALIDATION_FAILED` — пустые поля (B2)
|
||||
* `400 BAD_REQUEST` — сервер не смог десереализовать JSON
|
||||
|
||||
#### Logout-Request
|
||||
```
|
||||
{
|
||||
"token": af32df3bas739f272bd109c823
|
||||
}
|
||||
```
|
||||
##### Response - 200 - OK
|
||||
```
|
||||
null
|
||||
```
|
||||
|
||||
##### Errors
|
||||
* `400 BAD_REQUEST` — Такого токена не существует(B3)
|
||||
|
||||
### 10. Используемые сущности ДБ
|
||||
* users(uuid(PK), login(unique), hashed_password)
|
||||
|
||||
## UseCase №3
|
||||
### 1.Название: Переход на главную страницу
|
||||
### 2.Актор: Пользователь
|
||||
### 3.Цель: Предоставить пользователю поверхностный вывод данных о нем и инструменты для глубокого просмотра данных и их модификации
|
||||
### 4.Предусловия:
|
||||
* Пользователь имеет актуальный токен, подтверждающий его авторизацию в системе
|
||||
* Пользователь тем или иным способом перешел на главную страницу
|
||||
### 5.Основной поток:
|
||||
#### A1.Записи в дневнике есть
|
||||
* Система перенаправляет пользователя на его основную страницу
|
||||
* Система запрашивает и выводит последние записи и схемы лечения его дневника
|
||||
#### A2.Записей в дневнике нет
|
||||
* Заместо вывода записей в дневнике, система выводит заглушку, информирующую пользователя, что дневник пуст
|
||||
* Система делает доступными операции с дневником
|
||||
### 6.Потоки исключений:
|
||||
#### B1.Записи по какой-то причине не подгрузились
|
||||
* Система выводит нотификацию об ошибке и ее причине
|
||||
* Заместо вывода записей, система выводит на этом месте заглушку, информирующую о неправильной работе приложения и предоставляющей для нажатия кнопку перезагрузки страницы
|
||||
### 7.Постусловия
|
||||
* Пользователь видит свои последние записи и может по ним кликнуть, чтобы увидеть подробную информацию
|
||||
* Пользователю доступны операции добавления, модификации и удаления записей, а также схем лечения
|
||||
### 8.API-Маршруты
|
||||
* `GET /api/v1/User/Diaries` - получить кусок дневника пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20)
|
||||
* `GET /api/v1/User/TreatmentSchemes` - получить кусок дневника пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20)
|
||||
|
||||
### 9.Контракт
|
||||
#### Diaries-Request
|
||||
##### Response - 200 - OK
|
||||
```
|
||||
{
|
||||
diaries: [
|
||||
{
|
||||
"uuid": "e89b6a0c-4b0f-4722-a410-1e0c1864bf8a",
|
||||
"time": "10.08.2025",
|
||||
"mania_level": 1,
|
||||
"depression_level": 2,
|
||||
"mood_level": 3,
|
||||
"activity_level": 4,
|
||||
"appetite_level": 5,
|
||||
"dream_level": 6,
|
||||
"anxiety_level": 7,
|
||||
"treatment_scheme": {
|
||||
"uuid": "bf6d1555-39e9-4d73-8928-4763627f4dd5",
|
||||
"treatment_name": "Bipolar I Scheme",
|
||||
"instructions": "Контроль лития в крови раз в 2 месяца. Анализ крови через вену."
|
||||
"medications": [
|
||||
{
|
||||
"uuid": "8af2dfa9-3add-413c-9a0e-ff605088f1d5",
|
||||
"name": "Litii Carbonate",
|
||||
"dose": 1800,
|
||||
"unit": "mg",
|
||||
"is_urgent": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
##### Errors
|
||||
* `401 TOKEN_REQUIRED|TOKEN_EXPIRED` — токен недействителен, либо отсутствует
|
||||
* `500 DATA_LOAD_FAILED` — ошибка при загрузке данных (`B1`)
|
||||
|
||||
#### TreatmentSchemes-Request
|
||||
##### Response - 200 - OK
|
||||
```
|
||||
{
|
||||
"treatment_schemes": [
|
||||
{
|
||||
"uuid": "248313cb-a75e-4331-8379-d3f2fc36b68d"
|
||||
"treatment_name": "Bipolar I Scheme Urgent",
|
||||
"instructions": "Схема для бытрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
||||
"medications": [
|
||||
{
|
||||
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
|
||||
"name": "Aminazin",
|
||||
"dose": 100,
|
||||
"unit": "mg",
|
||||
"is_urgent": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
##### Errors
|
||||
* `401 TOKEN_REQUIRED|TOKEN_EXPIRED` — токен недействителен, либо отсутствует
|
||||
* `500 DATA_LOAD_FAILED` — ошибка при загрузке данных (B1)
|
||||
|
||||
### 10. Используемые сущности ДБ
|
||||
* diaries(uuid(PK), time , mania_level , depression_level , mood_level , activity_level , appetite_level , dream_level , anxiety_level, user_treatment_schemes_uuid)
|
||||
* mania(level(PK))
|
||||
* depressions(level(PK))
|
||||
* moods(level(PK))
|
||||
* activities(level(PK))
|
||||
* appetites(level(PK))
|
||||
* dreams(level(PK))
|
||||
* anxiety(level(PK))
|
||||
* treatment_schemes(user_treatment_schemes_uuid(PK), medication_uuid(PK))
|
||||
* user_treatment_schemes(uuid(PK), user_uuid, treatment_name, instructions)
|
||||
* medications(uuid(PK), name, dose, unit, is_urgent)
|
||||
@@ -1,5 +0,0 @@
|
||||
[requires]
|
||||
boost/1.84.0
|
||||
|
||||
[generators]
|
||||
cmake
|
||||
@@ -0,0 +1,188 @@
|
||||
-- Общая рекомендация - расписать use-case'ы
|
||||
|
||||
CREATE SCHEMA `up_and_down` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
|
||||
|
||||
CREATE TABLE `up_and_down`.`users` (
|
||||
`uuid` CHAR(36) NOT NULL,
|
||||
`login` VARCHAR(128) UNIQUE NOT NULL,
|
||||
`hashed_password` TEXT NOT NULL,
|
||||
PRIMARY KEY (`uuid`),
|
||||
UNIQUE INDEX `uuid_UNIQUE` (`uuid` ASC)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`mania` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`depressions` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`moods` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`activities` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`appetites` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`dreams` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`anxiety` (
|
||||
`level` INT1 NOT NULL,
|
||||
`description` TEXT NOT NULL,
|
||||
PRIMARY KEY (`level`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`user_treatment_schemes` (
|
||||
`uuid` CHAR(36) NOT NULL,
|
||||
`user_uuid` CHAR(36) NOT NULL,
|
||||
`treatment_name` TEXT NOT NULL,
|
||||
`instructions` TEXT,
|
||||
PRIMARY KEY (`uuid`),
|
||||
FOREIGN KEY (`user_uuid`) REFERENCES `users`(`uuid`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`diaries` (
|
||||
`uuid` CHAR(36) NOT NULL,
|
||||
`user_uuid` CHAR(36) NOT NULL,
|
||||
`time` DATETIME NOT NULL,
|
||||
`mania_level` INT1 NOT NULL,
|
||||
`depression_level` INT1 NOT NULL,
|
||||
`mood_level` INT1 NOT NULL,
|
||||
`activity_level` INT1 NOT NULL,
|
||||
`appetite_level` INT1 NOT NULL,
|
||||
`dream_level` INT1 NOT NULL,
|
||||
`anxiety_level` INT1 NOT NULL,
|
||||
`user_treatment_schemes_uuid` CHAR(36),
|
||||
PRIMARY KEY (`uuid`),
|
||||
FOREIGN KEY (`user_uuid`) REFERENCES `users`(`uuid`),
|
||||
FOREIGN KEY (`mania_level`) REFERENCES `mania`(`level`),
|
||||
FOREIGN KEY (`depression_level`) REFERENCES `depressions`(`level`),
|
||||
FOREIGN KEY (`mood_level`) REFERENCES `moods`(`level`),
|
||||
FOREIGN KEY (`activity_level`) REFERENCES `activities`(`level`),
|
||||
FOREIGN KEY (`appetite_level`) REFERENCES `appetites`(`level`),
|
||||
FOREIGN KEY (`dream_level`) REFERENCES `dreams`(`level`),
|
||||
FOREIGN KEY (`anxiety_level`) REFERENCES `anxiety`(`level`),
|
||||
FOREIGN KEY (`user_treatment_schemes_uuid`) REFERENCES `user_treatment_schemes`(`uuid`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`medications` (
|
||||
`uuid` CHAR(36) NOT NULL,
|
||||
`name` TEXT NOT NULL,
|
||||
`dose` int8 NOT NULL,
|
||||
`unit` CHAR(30),
|
||||
`is_urgent` BOOL NOT NULL,
|
||||
PRIMARY KEY (`uuid`)
|
||||
);
|
||||
|
||||
CREATE TABLE `up_and_down`.`treatment_schemes` (
|
||||
`user_treatment_schemes_uuid` CHAR(36) NOT NULL,
|
||||
`medication_uuid` CHAR(36) NOT NULL,
|
||||
PRIMARY KEY (`user_treatment_schemes_uuid`, `medication_uuid`),
|
||||
FOREIGN KEY (`user_treatment_schemes_uuid`) REFERENCES `user_treatment_schemes`(`uuid`),
|
||||
FOREIGN KEY (`medication_uuid`) REFERENCES `medications`(`uuid`)
|
||||
);
|
||||
|
||||
-- insert constants
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (1, 'Полное отсутствие мании');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (2, 'Слегка приподнятое настроение');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (3, 'Хорошее настроение');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (4, 'Очень хорошее настроение, но в рамках разумного');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (5, 'Гипомания I, характерная для циклотимии - приятная эйфория, повышенная активность');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (6, 'Гипомания II, характерная для БАР II - все, что в предыдущем пункте + белеет в глазах');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (7, 'Мания I - периодический не сильный отрыв от реальности');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (8, 'Мания II - сопровождается бредом и галлюцинациями - неадекватная речь');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (9, 'Мания III - сопровождается бредом и галлюцинациями - неадекватное поведение');
|
||||
INSERT INTO `up_and_down`.`mania` (`level`, `description`) VALUES (10, 'Мания IV - сопровождается бредом и галлюцинациями - человек опасен для себя и других');
|
||||
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (1, 'Депрессия I');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (2, 'Депрессия II');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (3, 'Депрессия III');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (4, 'Депрессия IV');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (5, 'Депрессия V');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (6, 'Депрессия VI');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (7, 'Депрессия VII');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (8, 'Депрессия VIII');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (9, 'Депрессия IX');
|
||||
INSERT INTO `up_and_down`.`depressions` (`level`, `description`) VALUES (10, 'Депрессия X');
|
||||
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (1, 'Настроение I');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (2, 'Настроение II');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (3, 'Настроение III');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (4, 'Настроение IV');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (5, 'Настроение V');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (6, 'Настроение VI');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (7, 'Настроение VII');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (8, 'Настроение VIII');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (9, 'Настроение IX');
|
||||
INSERT INTO `up_and_down`.`moods` (`level`, `description`) VALUES (10, 'Настроение X');
|
||||
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (1, 'Активность I');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (2, 'Активность II');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (3, 'Активность III');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (4, 'Активность IV');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (5, 'Активность V');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (6, 'Активность VI');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (7, 'Активность VII');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (8, 'Активность VIII');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (9, 'Активность IX');
|
||||
INSERT INTO `up_and_down`.`activities` (`level`, `description`) VALUES (10, 'Активность X');
|
||||
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (1, 'Аппетит I');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (2, 'Аппетит II');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (3, 'Аппетит III');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (4, 'Аппетит IV');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (5, 'Аппетит V');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (6, 'Аппетит VI');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (7, 'Аппетит VII');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (8, 'Аппетит VIII');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (9, 'Аппетит IX');
|
||||
INSERT INTO `up_and_down`.`appetites` (`level`, `description`) VALUES (10, 'Аппетит X');
|
||||
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (1, 'Сон I');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (2, 'Сон II');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (3, 'Сон III');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (4, 'Сон IV');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (5, 'Сон V');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (6, 'Сон VI');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (7, 'Сон VII');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (8, 'Сон VIII');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (9, 'Сон IX');
|
||||
INSERT INTO `up_and_down`.`dreams` (`level`, `description`) VALUES (10, 'Сон X');
|
||||
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (1, 'Тревога I');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (2, 'Тревога II');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (3, 'Тревога III');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (4, 'Тревога IV');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (5, 'Тревога V');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (6, 'Тревога VI');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (7, 'Тревога VII');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (8, 'Тревога VIII');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (9, 'Тревога IX');
|
||||
INSERT INTO `up_and_down`.`anxiety` (`level`, `description`) VALUES (10, 'Тревога X');
|
||||
|
||||
-- Заполнение пользователями
|
||||
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('ab555fcb-b9ee-45f4-9de8-8f16daa5d03b', 'login1', 'Qwerty12345');
|
||||
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('56b7c993-392f-41f8-adb1-9766842dc5fd', 'login2', 'AVALON123456');
|
||||
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('a243b5f2-e265-4c25-82a9-dde4cc70643f', 'login3', 'Zxcvb123456');
|
||||
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('51351bb1-7563-479d-a8e9-201d0ff934c2', 'login4', 'Sadly846612');
|
||||
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b6', 'login5', 'Qwerty12345');
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "../entities/user.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IAuthDAO
|
||||
{
|
||||
public:
|
||||
virtual std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) = 0;
|
||||
|
||||
virtual bool HasAuthorized(const std::string& auth_token) = 0;
|
||||
|
||||
virtual bool Logout(const std::string& user_token) = 0;
|
||||
|
||||
virtual ~IAuthDAO() = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "../entities/user.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IUserDAO
|
||||
{
|
||||
public:
|
||||
virtual std::string Create(const user& created_user) = 0;
|
||||
|
||||
virtual std::optional<user> GetByUUID(const std::string& uuid) = 0;
|
||||
|
||||
virtual std::optional<user> GetByLogin(const std::string& login) = 0;
|
||||
|
||||
virtual std::pair<bool, std::vector<user>> GetAll(size_t limit, size_t offset) = 0;
|
||||
|
||||
virtual bool Update(const user& u) = 0;
|
||||
|
||||
virtual bool Delete(const std::string& uuid) = 0;
|
||||
|
||||
virtual ~IUserDAO() = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include "MemoryAuthDAO.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
MemoryAuthDAO::MemoryAuthDAO(mysqlx::Session& session): session_(session)
|
||||
{
|
||||
}
|
||||
|
||||
std::string MemoryAuthDAO::Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token)
|
||||
{
|
||||
users_uuids_to_auth_tokens_[registrated_user_uuid] = auth_token;
|
||||
auth_tokens_to_users_uuids_[auth_token] = registrated_user_uuid;
|
||||
|
||||
return auth_token;
|
||||
}
|
||||
|
||||
bool MemoryAuthDAO::HasAuthorized(const std::string& auth_token)
|
||||
{
|
||||
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
|
||||
}
|
||||
|
||||
bool MemoryAuthDAO::Logout(const std::string& auth_token)
|
||||
{
|
||||
if (!HasAuthorized(auth_token)) return false;
|
||||
|
||||
string user_uuid = auth_tokens_to_users_uuids_[auth_token];
|
||||
|
||||
users_uuids_to_auth_tokens_.erase(user_uuid);
|
||||
auth_tokens_to_users_uuids_.erase(auth_token);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <mysqlx/xdevapi.h>
|
||||
|
||||
#include "IAuthDAO.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class MemoryAuthDAO : public uad::IAuthDAO
|
||||
{
|
||||
std::unordered_map<std::string, std::string> users_uuids_to_auth_tokens_;
|
||||
std::unordered_map<std::string, std::string> auth_tokens_to_users_uuids_;
|
||||
|
||||
mysqlx::Session& session_;
|
||||
public:
|
||||
explicit MemoryAuthDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) override;
|
||||
|
||||
bool HasAuthorized(const std::string& auth_token) override;
|
||||
|
||||
bool Logout(const std::string& auth_token) override;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include "MySQLUserDAO.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace string_literals;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) :
|
||||
session_(session)
|
||||
{
|
||||
}
|
||||
|
||||
string MySQLUserDAO::Create(const user& created_user)
|
||||
{
|
||||
boost::uuids::random_generator generator;
|
||||
boost::uuids::uuid uuid = generator();
|
||||
const std::string uuid_str = boost::uuids::to_string(uuid);
|
||||
|
||||
|
||||
static const string sql_script =
|
||||
"INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES (?, ?, ?);"s;
|
||||
|
||||
session_.
|
||||
sql(sql_script)
|
||||
.bind(uuid_str, created_user.login, created_user.hashed_password).execute();
|
||||
|
||||
return uuid_str;
|
||||
}
|
||||
|
||||
optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||
{
|
||||
static const string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (uuid = ?) LIMIT 1;"s;
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
sql(sql_script)
|
||||
.bind(uuid)
|
||||
.execute();
|
||||
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
||||
{
|
||||
static const std::string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (login = ?) LIMIT 1;"s;
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
sql(sql_script)
|
||||
.bind(login)
|
||||
.execute();
|
||||
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
{
|
||||
static const string sql_script = "SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s;
|
||||
|
||||
mysqlx::SqlResult sql_result = session_
|
||||
.sql(sql_script)
|
||||
.bind(limit, offset)
|
||||
.execute();
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
pair<bool, vector<user>> ret;
|
||||
|
||||
if (!rows.size())
|
||||
{
|
||||
ret.first = true;
|
||||
ret.second = vector<user>{};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.first = rows.size() < limit + 1;
|
||||
ret.second = vector<user>{};
|
||||
|
||||
ret.second.reserve(limit);
|
||||
|
||||
for (const auto& row : rows)
|
||||
{
|
||||
if (!limit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
user user;
|
||||
|
||||
const string user_uuid = row[0].get<string>();
|
||||
const string user_login = row[1].get<string>();
|
||||
|
||||
ret.second.push_back({.uuid = user_uuid, .login = user_login});
|
||||
--limit;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool MySQLUserDAO::Update(const user& u)
|
||||
{
|
||||
static const string sql_script = "UPDATE `up_and_down`.`users` SET `login` = ? WHERE `uuid` = ?;"s;
|
||||
|
||||
auto schema = session_.sql(sql_script)
|
||||
.bind(u.login, u.uuid)
|
||||
.execute();
|
||||
|
||||
return !!schema.getAffectedItemsCount();
|
||||
}
|
||||
|
||||
bool MySQLUserDAO::Delete(const string& uuid)
|
||||
{
|
||||
static const string sql_script = "DELETE FROM `up_and_down`.`users` WHERE `uuid` = ?;";
|
||||
|
||||
auto schema = session_.sql(sql_script)
|
||||
.bind(uuid)
|
||||
.execute();
|
||||
|
||||
return !!schema.getAffectedItemsCount();
|
||||
}
|
||||
|
||||
std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
||||
{
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
|
||||
if (!rows.size())
|
||||
{
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
auto row_data = *rows.begin();
|
||||
|
||||
const string user_uuid = row_data[0].get<string>();
|
||||
const string user_login = row_data[1].get<string>();
|
||||
const string user_hashed_password = row_data[2].get<string>();
|
||||
|
||||
return optional<user>({
|
||||
.uuid = user_uuid,
|
||||
.login = user_login,
|
||||
.hashed_password = user_hashed_password
|
||||
});
|
||||
}
|
||||
} // uad
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <mysqlx/xdevapi.h>
|
||||
|
||||
#include "IUserDAO.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class MySQLUserDAO : public IUserDAO
|
||||
{
|
||||
mysqlx::Session& session_;
|
||||
public:
|
||||
explicit MySQLUserDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Create(const user& created_user) override;
|
||||
|
||||
std::optional<user> GetByUUID(const std::string& uuid) override;
|
||||
|
||||
std::optional<user> GetByLogin(const std::string& login) override;
|
||||
|
||||
std::pair<bool, std::vector<user>> GetAll(size_t limit, size_t offset) override;
|
||||
|
||||
bool Update(const user& u) override;
|
||||
|
||||
bool Delete(const std::string& uuid) override;
|
||||
|
||||
private:
|
||||
std::optional<user> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <string>
|
||||
|
||||
#include "mysql_connector.h"
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
static mysqlx::Session* mysql_session = nullptr;
|
||||
|
||||
void SetMySqlSession(mysqlx::Session* ptr)
|
||||
{
|
||||
mysql_session = ptr;
|
||||
}
|
||||
|
||||
mysqlx::Session& GetMySqlSession()
|
||||
{
|
||||
return *mysql_session;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <mysqlx/xdevapi.h>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
void SetMySqlSession(mysqlx::Session* ptr);
|
||||
|
||||
mysqlx::Session& GetMySqlSession();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <regex>
|
||||
#include <boost/json.hpp>
|
||||
#include <mysqlx/xdevapi.h>
|
||||
#include <mysqlx/common/api.h>
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include "IExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "../helpers/helpers.h"
|
||||
#include "../exceptions/session_exception.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class AuthLoginExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||
{
|
||||
mysqlx::Session& session_;
|
||||
const std::shared_ptr<IUserDAO>& user_dao_;
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
||||
|
||||
public:
|
||||
AuthLoginExecutor(mysqlx::Session& session,
|
||||
const std::shared_ptr<IUserDAO>& user_dao,
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao)
|
||||
: session_(session), user_dao_(user_dao), auth_dao_(auth_dao)
|
||||
{
|
||||
}
|
||||
|
||||
boost::beast::http::response<ResponseType> operator ()(
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::json;
|
||||
using namespace boost::beast;
|
||||
using namespace std::string_literals;
|
||||
|
||||
const auto body = req.body();
|
||||
value req_json;
|
||||
|
||||
try
|
||||
{
|
||||
req_json = json::parse(body);
|
||||
}
|
||||
catch (const system::system_error& err)
|
||||
{
|
||||
throw session_exception(http::status::bad_request, "cannot deserialize json");
|
||||
}
|
||||
|
||||
|
||||
const std::string login = req_json.as_object().at("login").as_string().c_str();
|
||||
const std::string password = req_json.as_object().at("password").as_string().c_str();
|
||||
|
||||
if (login.empty() || password.empty())
|
||||
{
|
||||
throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s);
|
||||
}
|
||||
|
||||
const std::optional<user> maybe_user = user_dao_->GetByLogin(login);
|
||||
|
||||
if (!maybe_user.has_value() && maybe_user.value().hashed_password != HashPassword(password))
|
||||
{
|
||||
throw session_exception(http::status::forbidden,"Incorrect login or password");
|
||||
}
|
||||
const std::string token = GenerateUUID();
|
||||
auth_dao_->Login(maybe_user.value().uuid, token);
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
value response_body;
|
||||
|
||||
response_body.emplace_object();
|
||||
response_body.as_object().emplace("token", token);
|
||||
|
||||
res.body() = serialize(response_body);
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <regex>
|
||||
#include <boost/json.hpp>
|
||||
#include <mysqlx/xdevapi.h>
|
||||
#include <mysqlx/common/api.h>
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include "IExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class AuthLogoutExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||
{
|
||||
mysqlx::Session& session_;
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
||||
|
||||
public:
|
||||
AuthLogoutExecutor(mysqlx::Session& session,
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao) :
|
||||
session_(session), auth_dao_(auth_dao)
|
||||
{
|
||||
}
|
||||
|
||||
boost::beast::http::response<ResponseType> operator ()(
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::json;
|
||||
using namespace boost::beast;
|
||||
using namespace std::string_literals;
|
||||
|
||||
const auto body = req.body();
|
||||
value req_json;
|
||||
|
||||
try
|
||||
{
|
||||
req_json = json::parse(body);
|
||||
}
|
||||
catch (const system::system_error& err)
|
||||
{
|
||||
throw session_exception(http::status::internal_server_error, "cannot deserialize json"s);
|
||||
}
|
||||
|
||||
const std::string token = req_json.as_object().at("token").as_string().c_str();
|
||||
|
||||
if (!auth_dao_->Logout(token))
|
||||
{
|
||||
throw session_exception(http::status::bad_request, "token is not authorized"s);
|
||||
}
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
|
||||
res.body() = "null"s;
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include <regex>
|
||||
#include <boost/json.hpp>
|
||||
#include <mysqlx/xdevapi.h>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "IExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../exceptions/session_exception.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class AuthRegistrationExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||
{
|
||||
mysqlx::Session& session_;
|
||||
const std::shared_ptr<IUserDAO>& user_dao_;
|
||||
|
||||
public:
|
||||
AuthRegistrationExecutor(mysqlx::Session& session,
|
||||
const std::shared_ptr<IUserDAO>& user_dao)
|
||||
: session_(session), user_dao_(user_dao)
|
||||
{
|
||||
}
|
||||
|
||||
boost::beast::http::response<ResponseType> operator ()(
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::json;
|
||||
using namespace boost::beast;
|
||||
using namespace std::string_literals;
|
||||
|
||||
const auto& body = req.body();
|
||||
value req_json;
|
||||
|
||||
try
|
||||
{
|
||||
req_json = json::parse(body);
|
||||
}
|
||||
catch (const system::system_error& err)
|
||||
{
|
||||
throw session_exception(http::status::bad_request, "cannot deserialize json");
|
||||
}
|
||||
|
||||
const std::string login = req_json.as_object().at("login").as_string().c_str();
|
||||
const std::string password = req_json.as_object().at("password").as_string().c_str();
|
||||
|
||||
if (!ValidateLogin(login) || !ValidatePassword(password))
|
||||
{
|
||||
throw session_exception(
|
||||
http::status::unprocessable_entity,
|
||||
"Validations failed. Login should have length from 3 to 50. Password from 5 characters length."s
|
||||
);
|
||||
}
|
||||
|
||||
if (user_dao_->GetByLogin(login).has_value())
|
||||
{
|
||||
throw session_exception(http::status::conflict, "user with login "s + login + " exists"s);
|
||||
}
|
||||
|
||||
user user;
|
||||
|
||||
user.login = login;
|
||||
user.hashed_password = HashPassword(password);
|
||||
|
||||
const std::string uuid_stringified = user_dao_->Create(user);
|
||||
|
||||
http::response<ResponseType> res{
|
||||
http::status::created, req.version()
|
||||
};
|
||||
value response_body;
|
||||
|
||||
response_body.emplace_object();
|
||||
|
||||
response_body.as_object().emplace(
|
||||
"uuid",
|
||||
uuid_stringified
|
||||
);
|
||||
response_body.as_object().emplace(
|
||||
"login",
|
||||
user.login
|
||||
);
|
||||
|
||||
res.body() = serialize(response_body);
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
bool ValidateLogin(const std::string& login)
|
||||
{
|
||||
if (login.size() < 3 || login.size() > 50) return false;
|
||||
|
||||
std::regex pattern(std::string("^[A-Za-z0-9_]+$"));
|
||||
|
||||
return std::regex_match(login, pattern);
|
||||
}
|
||||
|
||||
bool ValidatePassword(const std::string& password)
|
||||
{
|
||||
return password.size() >= 5;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
#include "./IController.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class Controller : public IController<Body, Allocator, ResponseType>
|
||||
{
|
||||
public:
|
||||
using HTTPMethodsToExecutors = std::unordered_map<boost::beast::http::verb, std::shared_ptr<IExecutor<Body, Allocator, ResponseType>>>;
|
||||
|
||||
private:
|
||||
HTTPMethodsToExecutors executors_;
|
||||
public:
|
||||
Controller() = default;
|
||||
|
||||
explicit Controller(HTTPMethodsToExecutors&& executors): executors_(std::move(executors)) {}
|
||||
|
||||
std::optional<std::shared_ptr<IExecutor<Body, Allocator, ResponseType>>> FindExecutor(
|
||||
boost::beast::http::verb method
|
||||
) override
|
||||
{
|
||||
if (!executors_.count(method)) return std::nullopt;
|
||||
|
||||
return std::make_optional(executors_.at(method));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
#include "../db/mysql_connector.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "AuthRegistrationExecutor.h"
|
||||
#include "RootExecutor.h"
|
||||
#include "../DAO/MemoryAuthDAO.h"
|
||||
#include "../DAO/MySQLUserDAO.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class Send>
|
||||
void HandleRequest(
|
||||
boost::beast::string_view doc_root,
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
static std::shared_ptr<IUserDAO> user_dao = std::make_shared<MySQLUserDAO>(GetMySqlSession());
|
||||
static std::shared_ptr<IAuthDAO> auth_dao = std::make_shared<MemoryAuthDAO>(GetMySqlSession());
|
||||
|
||||
static RootExecutor<Body, Allocator, boost::beast::http::string_body, Send> root_executor(
|
||||
GetMySqlSession(),
|
||||
user_dao,
|
||||
auth_dao
|
||||
);
|
||||
|
||||
root_executor(doc_root, std::move(req), std::forward<Send>(send));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
#include "IExecutor.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class IController
|
||||
{
|
||||
public:
|
||||
virtual std::optional<std::shared_ptr<IExecutor<Body, Allocator, ResponseType>>> FindExecutor(
|
||||
boost::beast::http::verb method
|
||||
) = 0;
|
||||
virtual ~IController() = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class IExecutor
|
||||
{
|
||||
public:
|
||||
virtual boost::beast::http::response<ResponseType> operator ()(
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) = 0;
|
||||
virtual ~IExecutor() = default;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
#include <mysqlx/xdevapi.h>
|
||||
#include <mysqlx/common/api.h>
|
||||
|
||||
#include "IExecutor.h"
|
||||
#include "IController.h"
|
||||
#include "Controller.h"
|
||||
#include "AuthRegistrationExecutor.h"
|
||||
#include "AuthLoginExecutor.h"
|
||||
#include "AuthLogoutExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "./../helpers/helpers.h"
|
||||
#include "./../exceptions/session_exception.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType, class Send>
|
||||
class RootExecutor
|
||||
{
|
||||
using IRouteExecutor = IExecutor<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthRegistrationExecutor = AuthRegistrationExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthLoginExecutor = AuthLoginExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthLogoutExecutor = AuthLogoutExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using IRouteController = IController<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
||||
using Request = boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>;
|
||||
using StringResponse = boost::beast::http::response<boost::beast::http::string_body>;
|
||||
using EmptyResponse = boost::beast::http::response<boost::beast::http::empty_body>;
|
||||
using FileResponse = boost::beast::http::response<boost::beast::http::file_body>;
|
||||
|
||||
private:
|
||||
RoutesPathes routes_pathes_;
|
||||
mysqlx::Session& session_;
|
||||
const std::shared_ptr<IUserDAO>& user_dao_;
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
||||
|
||||
public:
|
||||
RootExecutor(
|
||||
mysqlx::Session& session,
|
||||
const std::shared_ptr<IUserDAO>& user_dao,
|
||||
const std::shared_ptr<IAuthDAO>& auth_dao) :
|
||||
session_(session), user_dao_(user_dao), auth_dao_(auth_dao)
|
||||
{
|
||||
routes_pathes_["/api/v1/Auth/Register"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(
|
||||
session_,
|
||||
user_dao_
|
||||
)}
|
||||
}
|
||||
);
|
||||
|
||||
routes_pathes_["/api/v1/Auth/Login"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLoginExecutor>(session_, user_dao_, auth_dao_)}
|
||||
}
|
||||
);
|
||||
|
||||
routes_pathes_["/api/v1/Auth/Logout"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLogoutExecutor>(session_, auth_dao_)}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void operator ()(
|
||||
boost::beast::string_view doc_root,
|
||||
Request&& req,
|
||||
Send&& send
|
||||
)
|
||||
{
|
||||
const std::string& route = req.target();
|
||||
const bool is_match_route = routes_pathes_.count(route);
|
||||
|
||||
if (is_match_route)
|
||||
{
|
||||
std::optional<std::shared_ptr<IRouteExecutor>> maybe_executor_ptr = routes_pathes_
|
||||
.at(route)
|
||||
->FindExecutor(req.method());
|
||||
|
||||
if (maybe_executor_ptr.has_value())
|
||||
{
|
||||
IRouteExecutor& executor = *maybe_executor_ptr.value();
|
||||
|
||||
try
|
||||
{
|
||||
boost::beast::http::response<ResponseType> res = executor(std::move(req));
|
||||
|
||||
return send(std::move(res));
|
||||
}
|
||||
catch (const session_exception& e)
|
||||
{
|
||||
boost::beast::http::response<ResponseType> res{e.code, req.version()};
|
||||
boost::json::value response_body;
|
||||
|
||||
response_body.emplace_object();
|
||||
response_body.as_object().emplace("Result", e.what());
|
||||
|
||||
res.body() = serialize(response_body);
|
||||
res.set(boost::beast::http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return send(std::move(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (req.method() != boost::beast::http::verb::get &&
|
||||
req.method() != boost::beast::http::verb::head)
|
||||
return send(SendBadRequest(std::move(req), "Unknown boost::beast::HTTP-method"));
|
||||
|
||||
if (req.target().empty() || req.target()[0] != '/' ||
|
||||
req.target().find("..") != boost::beast::string_view::npos)
|
||||
return send(SendBadRequest(std::move(req), "Illegal request-target"));
|
||||
|
||||
std::string path = PathCat(doc_root, req.target());
|
||||
if (req.target().back() == '/')
|
||||
path.append("index.html");
|
||||
|
||||
boost::beast::error_code ec;
|
||||
boost::beast::http::file_body::value_type body;
|
||||
body.open(path.c_str(), boost::beast::file_mode::scan, ec);
|
||||
|
||||
if (ec == boost::beast::errc::no_such_file_or_directory)
|
||||
return send(SendNotFound(std::move(req), req.target()));
|
||||
|
||||
if (ec)
|
||||
return send(SendServerError(std::move(req), ec.message()));
|
||||
|
||||
auto const size = body.size();
|
||||
|
||||
if (req.method() == boost::beast::http::verb::head)
|
||||
{
|
||||
EmptyResponse res{
|
||||
boost::beast::http::status::ok,
|
||||
req.version()
|
||||
};
|
||||
res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(boost::beast::http::field::content_type, MimeType(path));
|
||||
res.content_length(size);
|
||||
res.keep_alive(req.keep_alive());
|
||||
return send(std::move(res));
|
||||
}
|
||||
|
||||
FileResponse res{
|
||||
std::piecewise_construct, std::make_tuple(std::move(body)),
|
||||
std::make_tuple(boost::beast::http::status::ok, req.version())
|
||||
};
|
||||
res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(boost::beast::http::field::content_type, MimeType(path));
|
||||
res.content_length(size);
|
||||
res.keep_alive(req.keep_alive());
|
||||
return send(std::move(res));
|
||||
}
|
||||
|
||||
private:
|
||||
StringResponse SendBadRequest(
|
||||
Request&& req,
|
||||
boost::beast::string_view why
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::bad_request, req.version()
|
||||
};
|
||||
res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.keep_alive(req.keep_alive());
|
||||
res.body() = std::string(why);
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
}
|
||||
|
||||
StringResponse SendNotFound(
|
||||
Request&& req,
|
||||
boost::beast::string_view target
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::not_found, req.version()
|
||||
};
|
||||
res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.keep_alive(req.keep_alive());
|
||||
res.body() = "The resource '" + std::string(target) + "' was not found.";
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
}
|
||||
|
||||
StringResponse SendServerError(
|
||||
Request&& req,
|
||||
boost::beast::string_view what
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::internal_server_error, req.version()
|
||||
};
|
||||
res.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
res.set(boost::beast::http::field::content_type, "text/html");
|
||||
res.keep_alive(req.keep_alive());
|
||||
res.body() = "An error occurred: '" + std::string(what) + "'";
|
||||
res.prepare_payload();
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
struct user
|
||||
{
|
||||
std::string uuid;
|
||||
std::string login;
|
||||
std::string hashed_password;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "session_exception.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
char const* session_exception::what() const
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast/http/status.hpp>
|
||||
#include <string>
|
||||
#include <boost/exception/to_string.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
struct session_exception : std::exception
|
||||
{
|
||||
const boost::beast::http::status code;
|
||||
const std::string comment;
|
||||
const std::string message;
|
||||
|
||||
session_exception(const boost::beast::http::status ec, const std::string info)
|
||||
: code(ec), comment(info), message(std::to_string(static_cast<uint64_t>(ec)) + " - " + comment)
|
||||
{}
|
||||
char const* what() const override;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
boost::beast::string_view MimeType(boost::beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if (pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
if (iequals(ext, ".htm"))
|
||||
return "text/html";
|
||||
if (iequals(ext, ".html"))
|
||||
return "text/html";
|
||||
if (iequals(ext, ".php"))
|
||||
return "text/html";
|
||||
if (iequals(ext, ".css"))
|
||||
return "text/css";
|
||||
if (iequals(ext, ".txt"))
|
||||
return "text/plain";
|
||||
if (iequals(ext, ".js"))
|
||||
return "application/javascript";
|
||||
if (iequals(ext, ".json"))
|
||||
return "application/json";
|
||||
if (iequals(ext, ".xml"))
|
||||
return "application/xml";
|
||||
if (iequals(ext, ".swf"))
|
||||
return "application/x-shockwave-flash";
|
||||
if (iequals(ext, ".flv"))
|
||||
return "video/x-flv";
|
||||
if (iequals(ext, ".png"))
|
||||
return "image/png";
|
||||
if (iequals(ext, ".jpe"))
|
||||
return "image/jpeg";
|
||||
if (iequals(ext, ".jpeg"))
|
||||
return "image/jpeg";
|
||||
if (iequals(ext, ".jpg"))
|
||||
return "image/jpeg";
|
||||
if (iequals(ext, ".gif"))
|
||||
return "image/gif";
|
||||
if (iequals(ext, ".bmp"))
|
||||
return "image/bmp";
|
||||
if (iequals(ext, ".ico"))
|
||||
return "image/vnd.microsoft.icon";
|
||||
if (iequals(ext, ".tiff"))
|
||||
return "image/tiff";
|
||||
if (iequals(ext, ".tif"))
|
||||
return "image/tiff";
|
||||
if (iequals(ext, ".svg"))
|
||||
return "image/svg+xml";
|
||||
if (iequals(ext, ".svgz"))
|
||||
return "image/svg+xml";
|
||||
return "application/text";
|
||||
}
|
||||
|
||||
std::string PathCat(boost::beast::string_view base, boost::beast::string_view path)
|
||||
{
|
||||
if (base.empty())
|
||||
return std::string(path);
|
||||
std::string result(base);
|
||||
#ifdef BOOST_MSVC
|
||||
char constexpr path_separator = '\\';
|
||||
if (result.back() == path_separator)
|
||||
result.resize(result.size() - 1);
|
||||
result.append(path.data(), path.size());
|
||||
for (auto& c : result)
|
||||
if (c == '/')
|
||||
c = path_separator;
|
||||
#else
|
||||
char constexpr path_separator = '/';
|
||||
if (result.back() == path_separator)
|
||||
result.resize(result.size() - 1);
|
||||
result.append(path.data(), path.size());
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void Fail(boost::beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
|
||||
std::string ToHex(std::byte* src, size_t len)
|
||||
{
|
||||
if (!src || !len) return "";
|
||||
|
||||
string ret;
|
||||
ret.reserve(len * 2);
|
||||
boost::format formatter = boost::format("%02X");
|
||||
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
byte target_byte = src[i];
|
||||
|
||||
formatter % static_cast<int32_t>(target_byte);
|
||||
ret += formatter.str();
|
||||
|
||||
formatter.clear();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string HashPassword(const std::string& password)
|
||||
{
|
||||
size_t calculated_hash = std::hash<string>{}(password);
|
||||
return ToHex((byte*)&calculated_hash, sizeof(calculated_hash));
|
||||
}
|
||||
|
||||
std::string GenerateUUID()
|
||||
{
|
||||
uuids::random_generator generator;
|
||||
|
||||
return uuids::to_string(generator());
|
||||
}
|
||||
|
||||
uint64_t Random()
|
||||
{
|
||||
std::random_device device;
|
||||
std::mt19937_64 random_generator(device());
|
||||
std::uniform_int_distribution<std::mt19937_64::result_type> dist(0,UINT64_MAX);
|
||||
|
||||
return dist(random_generator);
|
||||
}
|
||||
} // namespace uad
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
boost::beast::string_view MimeType(boost::beast::string_view path);
|
||||
|
||||
std::string PathCat(boost::beast::string_view base, boost::beast::string_view path);
|
||||
|
||||
void Fail(boost::beast::error_code ec, char const* what);
|
||||
|
||||
std::string ToHex(std::byte* src, size_t len);
|
||||
|
||||
std::string HashPassword(const std::string& password);
|
||||
|
||||
std::string GenerateUUID();
|
||||
|
||||
uint64_t Random();
|
||||
} // namespace uad
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <boost/asio/strand.hpp>
|
||||
|
||||
#include "Listener.h"
|
||||
|
||||
#include "./../helpers/helpers.h"
|
||||
#include "./../session/HttpSession.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
Listener::Listener(boost::asio::io_context& ioc, boost::asio::ip::tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root) :
|
||||
ioc_(ioc), acceptor_(boost::asio::make_strand(ioc)), doc_root_(doc_root)
|
||||
{
|
||||
boost::beast::error_code ec;
|
||||
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
if (ec)
|
||||
{
|
||||
Fail(ec, "open");
|
||||
return;
|
||||
}
|
||||
|
||||
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec);
|
||||
if (ec)
|
||||
{
|
||||
Fail(ec, "set_option");
|
||||
return;
|
||||
}
|
||||
|
||||
acceptor_.bind(endpoint, ec);
|
||||
if (ec)
|
||||
{
|
||||
Fail(ec, "bind");
|
||||
return;
|
||||
}
|
||||
|
||||
acceptor_.listen(boost::asio::socket_base::max_listen_connections, ec);
|
||||
if (ec)
|
||||
{
|
||||
Fail(ec, "listen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Listener::Run()
|
||||
{
|
||||
boost::asio::dispatch(
|
||||
acceptor_.get_executor(),
|
||||
boost::beast::bind_front_handler(&Listener::DoAccept, this->shared_from_this()));
|
||||
}
|
||||
|
||||
void Listener::DoAccept()
|
||||
{
|
||||
acceptor_.async_accept(boost::asio::make_strand(ioc_),
|
||||
boost::beast::bind_front_handler(&Listener::OnAccept, shared_from_this()));
|
||||
}
|
||||
|
||||
void Listener::OnAccept(boost::beast::error_code ec, boost::asio::ip::tcp::socket socket)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
Fail(ec, "accept");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::make_shared<HttpSession>(std::move(socket), doc_root_)->Run();
|
||||
}
|
||||
|
||||
DoAccept();
|
||||
}
|
||||
} // namespace uad
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class Listener : public std::enable_shared_from_this<Listener>
|
||||
{
|
||||
boost::asio::io_context& ioc_;
|
||||
boost::asio::ip::tcp::acceptor acceptor_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
|
||||
public:
|
||||
Listener(boost::asio::io_context& ioc, boost::asio::ip::tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
void DoAccept();
|
||||
|
||||
void OnAccept(boost::beast::error_code ec, boost::asio::ip::tcp::socket socket);
|
||||
};
|
||||
}
|
||||
+32
-21
@@ -1,8 +1,13 @@
|
||||
#include "sdk.h"
|
||||
#ifdef WIN32
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <algorithm>
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <mysqlx/xdevapi.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@@ -10,46 +15,52 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "RequestHandlers/BasicRequestHandler.h"
|
||||
#include "Listener.h"
|
||||
#include "./session/WebsocketSession.h"
|
||||
#include "./listener/Listener.h"
|
||||
#include "./db/mysql_connector.h"
|
||||
#include "entities/user.h"
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace http = beast::http;
|
||||
namespace websocket = beast::websocket;
|
||||
namespace net = boost::asio;
|
||||
using tcp = boost::asio::ip::tcp;
|
||||
using namespace uad;
|
||||
using namespace std;
|
||||
using namespace std::string_literals;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 5)
|
||||
if (argc != 6)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-server-async <address> <port> <doc_root> <threads>\n" <<
|
||||
"Example:\n" <<
|
||||
" http-server-async 0.0.0.0 8080 . 1\n";
|
||||
std::cerr << "Usage: advanced-server <address> <port> <doc_root> <threads> <mysqlx://user:password@localhost:3306>\n"
|
||||
<< "Example:\n"
|
||||
<< " advanced-server 0.0.0.0 8080 . 1\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto const address = net::ip::make_address(argv[1]);
|
||||
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
auto const doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
string mysql_credentials = argv[5];
|
||||
|
||||
net::io_context ioc {threads};
|
||||
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
|
||||
|
||||
std::make_shared<Listener>(
|
||||
ioc,
|
||||
tcp::endpoint {address, port},
|
||||
doc_root)->Run();
|
||||
net::io_context ioc{threads};
|
||||
|
||||
std::make_shared<Listener>(ioc, tcp::endpoint{address, port}, doc_root)->Run();
|
||||
|
||||
net::signal_set signals(ioc, SIGINT, SIGTERM);
|
||||
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
|
||||
|
||||
std::vector<std::thread> v;
|
||||
v.reserve(threads - 1);
|
||||
for (auto i = threads - 1; i > 0; --i)
|
||||
v.emplace_back(
|
||||
[&ioc]
|
||||
{
|
||||
ioc.run();
|
||||
});
|
||||
v.emplace_back([&ioc] { ioc.run(); });
|
||||
ioc.run();
|
||||
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include "HttpSession.h"
|
||||
#include "WebsocketSession.h"
|
||||
#include "./../endpoints_handlers/HandleRequest.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
HttpSession::Queue::Queue(HttpSession& self) : self_(self)
|
||||
{
|
||||
static_assert(limit > 0, "Queue limit must be positive");
|
||||
items_.reserve(limit);
|
||||
}
|
||||
|
||||
bool HttpSession::Queue::IsFull() const { return items_.size() >= limit; }
|
||||
|
||||
bool HttpSession::Queue::OnWrite()
|
||||
{
|
||||
BOOST_ASSERT(!items_.empty());
|
||||
auto const was_full = IsFull();
|
||||
items_.erase(items_.begin());
|
||||
if (!items_.empty())
|
||||
(*items_.front())();
|
||||
return was_full;
|
||||
}
|
||||
|
||||
HttpSession::HttpSession(boost::asio::ip::tcp::socket&& socket,
|
||||
std::shared_ptr<std::string const> const& doc_root) :
|
||||
stream_(std::move(socket)), doc_root_(doc_root), queue_(*this)
|
||||
{
|
||||
}
|
||||
|
||||
void HttpSession::Run()
|
||||
{
|
||||
boost::asio::dispatch(
|
||||
stream_.get_executor(),
|
||||
boost::beast::bind_front_handler(&HttpSession::DoRead, this->shared_from_this()));
|
||||
}
|
||||
|
||||
void HttpSession::DoRead()
|
||||
{
|
||||
parser_.emplace();
|
||||
|
||||
parser_->body_limit(10000);
|
||||
|
||||
stream_.expires_after(std::chrono::seconds(30));
|
||||
|
||||
boost::beast::http::async_read(
|
||||
stream_, buffer_, *parser_,
|
||||
boost::beast::bind_front_handler(&HttpSession::OnRead, shared_from_this()));
|
||||
}
|
||||
|
||||
void HttpSession::OnRead(boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
if (ec == boost::beast::http::error::end_of_stream)
|
||||
return DoClose();
|
||||
|
||||
if (ec)
|
||||
return Fail(ec, "read");
|
||||
|
||||
if (boost::beast::websocket::is_upgrade(parser_->get()))
|
||||
{
|
||||
std::make_shared<WebsocketSession>(stream_.release_socket())->DoAccept(parser_->release());
|
||||
return;
|
||||
}
|
||||
|
||||
HandleRequest(*doc_root_, parser_->release(), queue_);
|
||||
|
||||
if (!queue_.IsFull())
|
||||
DoRead();
|
||||
}
|
||||
|
||||
void HttpSession::OnWrite(bool close, boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
if (ec)
|
||||
return Fail(ec, "write");
|
||||
|
||||
if (close)
|
||||
{
|
||||
return DoClose();
|
||||
}
|
||||
|
||||
if (queue_.OnWrite())
|
||||
{
|
||||
DoRead();
|
||||
}
|
||||
}
|
||||
|
||||
void HttpSession::DoClose()
|
||||
{
|
||||
boost::beast::error_code ec;
|
||||
stream_.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
|
||||
}
|
||||
} // namespace uad
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <boost/beast.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class HttpSession : public std::enable_shared_from_this<HttpSession>
|
||||
{
|
||||
class Queue
|
||||
{
|
||||
enum
|
||||
{
|
||||
limit = 8
|
||||
};
|
||||
|
||||
struct work
|
||||
{
|
||||
virtual void operator()() = 0;
|
||||
virtual ~work() = default;
|
||||
};
|
||||
|
||||
HttpSession& self_;
|
||||
std::vector<std::unique_ptr<work>> items_;
|
||||
|
||||
public:
|
||||
explicit Queue(HttpSession& self);
|
||||
|
||||
bool IsFull() const;
|
||||
|
||||
bool OnWrite();
|
||||
|
||||
template <bool isRequest, class Body, class Fields>
|
||||
void operator()(boost::beast::http::message<isRequest, Body, Fields>&& msg)
|
||||
{
|
||||
struct work_impl : work
|
||||
{
|
||||
HttpSession& self_;
|
||||
boost::beast::http::message<isRequest, Body, Fields> msg_;
|
||||
|
||||
work_impl(HttpSession& self, boost::beast::http::message<isRequest, Body, Fields>&& msg) :
|
||||
self_(self), msg_(std::move(msg))
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
boost::beast::http::async_write(self_.stream_, msg_,
|
||||
boost::beast::bind_front_handler(&HttpSession::OnWrite,
|
||||
self_.shared_from_this(), msg_.need_eof()));
|
||||
}
|
||||
};
|
||||
|
||||
items_.push_back(boost::make_unique<work_impl>(self_, std::move(msg)));
|
||||
|
||||
if (items_.size() == 1)
|
||||
(*items_.front())();
|
||||
}
|
||||
};
|
||||
|
||||
boost::beast::tcp_stream stream_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
Queue queue_;
|
||||
boost::optional<boost::beast::http::request_parser<boost::beast::http::string_body>> parser_;
|
||||
|
||||
public:
|
||||
HttpSession(boost::asio::ip::tcp::socket&& socket, std::shared_ptr<std::string const> const& doc_root);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
void DoRead();
|
||||
|
||||
void OnRead(boost::beast::error_code ec, std::size_t bytes_transferred);
|
||||
|
||||
void OnWrite(bool close, boost::beast::error_code ec, std::size_t bytes_transferred);
|
||||
|
||||
void DoClose();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "WebsocketSession.h"
|
||||
|
||||
#include "./../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
WebsocketSession::WebsocketSession(boost::asio::ip::tcp::socket&& socket) : ws_(std::move(socket))
|
||||
{
|
||||
}
|
||||
|
||||
void WebsocketSession::OnAccept(boost::beast::error_code ec)
|
||||
{
|
||||
if (ec)
|
||||
return Fail(ec, "accept");
|
||||
|
||||
DoRead();
|
||||
}
|
||||
|
||||
void WebsocketSession::DoRead()
|
||||
{
|
||||
ws_.async_read(buffer_,
|
||||
boost::beast::bind_front_handler(&WebsocketSession::OnRead, shared_from_this()));
|
||||
}
|
||||
|
||||
void WebsocketSession::OnRead(boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
if (ec == boost::beast::websocket::error::closed)
|
||||
return;
|
||||
|
||||
if (ec)
|
||||
Fail(ec, "read");
|
||||
|
||||
ws_.text(ws_.got_text());
|
||||
ws_.async_write(buffer_.data(),
|
||||
boost::beast::bind_front_handler(&WebsocketSession::OnWrite, shared_from_this()));
|
||||
}
|
||||
|
||||
void WebsocketSession::OnWrite(boost::beast::error_code ec, std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
if (ec)
|
||||
return Fail(ec, "write");
|
||||
|
||||
buffer_.consume(buffer_.size());
|
||||
|
||||
DoRead();
|
||||
}
|
||||
} // namespace uad
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <boost/beast.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class WebsocketSession : public std::enable_shared_from_this<WebsocketSession>
|
||||
{
|
||||
boost::beast::websocket::stream<boost::beast::tcp_stream> ws_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
explicit WebsocketSession(boost::asio::ip::tcp::socket&& socket);
|
||||
|
||||
template <class Body, class Allocator>
|
||||
void DoAccept(boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>> req)
|
||||
{
|
||||
ws_.set_option(boost::beast::websocket::stream_base::timeout::suggested(boost::beast::role_type::server));
|
||||
|
||||
ws_.set_option(boost::beast::websocket::stream_base::decorator(
|
||||
[](boost::beast::websocket::response_type& res)
|
||||
{
|
||||
res.set(boost::beast::http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " advanced-server");
|
||||
}));
|
||||
|
||||
ws_.async_accept(req,
|
||||
boost::beast::bind_front_handler(&WebsocketSession::OnAccept, shared_from_this()));
|
||||
}
|
||||
|
||||
private:
|
||||
void OnAccept(boost::beast::error_code ec);
|
||||
|
||||
void DoRead();
|
||||
|
||||
void OnRead(boost::beast::error_code ec, std::size_t bytes_transferred);
|
||||
|
||||
void OnWrite(boost::beast::error_code ec, std::size_t bytes_transferred);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#ifdef WIN32
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE Controllers
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include "./../../src/endpoints_handlers/Controller.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
using namespace uad;
|
||||
|
||||
using IControllerMock = Controller<beast::http::string_body,
|
||||
std::allocator<char>,
|
||||
beast::http::string_body>;
|
||||
|
||||
class MockExecutor : public IExecutor<beast::http::string_body,
|
||||
std::allocator<char>,
|
||||
beast::http::string_body>
|
||||
{
|
||||
public:
|
||||
beast::http::response<beast::http::string_body> operator ()(
|
||||
beast::http::request<beast::http::string_body, beast::http::basic_fields<std::allocator<char>>>&& req
|
||||
) override
|
||||
{
|
||||
boost::beast::http::response<boost::beast::http::string_body> res{
|
||||
boost::beast::http::status::not_found, req.version()};
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_No_Executors)
|
||||
{
|
||||
IControllerMock my_controller;
|
||||
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::get).has_value());
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::post).has_value());
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::put).has_value());
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::delete_).has_value());
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::head).has_value());
|
||||
BOOST_CHECK(!my_controller.FindExecutor(beast::http::verb::options).has_value());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Should_Be_Initiated_With_Unordered_Map_HTTP_Methods_To_Executors)
|
||||
{
|
||||
IControllerMock::HTTPMethodsToExecutors executors;
|
||||
|
||||
executors[beast::http::verb::get] = make_shared<MockExecutor>();
|
||||
executors[beast::http::verb::post] = make_shared<MockExecutor>();
|
||||
executors[beast::http::verb::put] = make_shared<MockExecutor>();
|
||||
executors[beast::http::verb::delete_] = make_shared<MockExecutor>();
|
||||
executors[beast::http::verb::head] = make_shared<MockExecutor>();
|
||||
executors[beast::http::verb::options] = make_shared<MockExecutor>();
|
||||
|
||||
IControllerMock my_controller(std::move(executors));
|
||||
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::get).has_value());
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::post).has_value());
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::put).has_value());
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::delete_).has_value());
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::head).has_value());
|
||||
BOOST_CHECK(my_controller.FindExecutor(beast::http::verb::options).has_value());
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#ifdef WIN32
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE Helpers
|
||||
|
||||
#include "./../../src/helpers/helpers.h"
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
using namespace uad;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ToHex_should_cast_single_byte_to_hex_string)
|
||||
{
|
||||
byte a1 = byte(0);
|
||||
byte a2 = byte(1);
|
||||
byte a3 = byte(2);
|
||||
byte a4 = byte(3);
|
||||
byte a5 = byte(4);
|
||||
byte a6 = byte(5);
|
||||
byte a7 = byte(6);
|
||||
byte a8 = byte(15);
|
||||
byte a9 = byte(64);
|
||||
byte a10 = byte(97);
|
||||
byte a11 = byte(127);
|
||||
byte a12 = byte(255);
|
||||
|
||||
BOOST_CHECK_EQUAL(ToHex(&a1, 1), "00"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a2, 1), "01"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a3, 1), "02"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a4, 1), "03"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a5, 1), "04"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a6, 1), "05"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a7, 1), "06"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a8, 1), "0F"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a9, 1), "40"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a10, 1), "61"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a11, 1), "7F"s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a12, 1), "FF"s);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ToHex_should_return_empty_string_if_no_arr_or_no_length)
|
||||
{
|
||||
byte a1 = byte(0);
|
||||
|
||||
BOOST_CHECK_EQUAL(ToHex(nullptr, 0), ""s);
|
||||
BOOST_CHECK_EQUAL(ToHex(&a1, 0), ""s);
|
||||
BOOST_CHECK_EQUAL(ToHex(nullptr, 1), ""s);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Random_should_return_different_numbers_on_multiple_calls)
|
||||
{
|
||||
auto a1 = Random();
|
||||
auto a2 = Random();
|
||||
auto a3 = Random();
|
||||
auto a4 = Random();
|
||||
auto a5 = Random();
|
||||
auto a6 = Random();
|
||||
auto a7 = Random();
|
||||
auto a8 = Random();
|
||||
auto a9 = Random();
|
||||
auto a10 = Random();
|
||||
|
||||
auto b1 = Random();
|
||||
auto b2 = Random();
|
||||
auto b3 = Random();
|
||||
auto b4 = Random();
|
||||
auto b5 = Random();
|
||||
auto b6 = Random();
|
||||
auto b7 = Random();
|
||||
auto b8 = Random();
|
||||
auto b9 = Random();
|
||||
auto b10 = Random();
|
||||
|
||||
BOOST_CHECK(a1 != b1);
|
||||
BOOST_CHECK(a2 != b2);
|
||||
BOOST_CHECK(a3 != b3);
|
||||
BOOST_CHECK(a4 != b4);
|
||||
BOOST_CHECK(a5 != b5);
|
||||
BOOST_CHECK(a6 != b6);
|
||||
BOOST_CHECK(a7 != b7);
|
||||
BOOST_CHECK(a8 != b8);
|
||||
BOOST_CHECK(a9 != b9);
|
||||
BOOST_CHECK(a10 != b10);
|
||||
}
|
||||
Reference in New Issue
Block a user