Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
cmake-build-*/
.idea/
build/
.vscode/
34 changes: 21 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ execute_process(COMMAND ${CMAKE_COMMAND} --build .
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build)

set(CMAKE_C_FLAGS "-pedantic -fprofile-arcs -ftest-coverage -Wall -Werror -Wpedantic")
set(CMAKE_CXX_FLAGS "-pedantic -fprofile-arcs -ftest-coverage -Wall -Werror -Wpedantic")
set(CMAKE_C_FLAGS "-pedantic -Wall")
set(CMAKE_CXX_FLAGS "-pedantic -Wall")

enable_testing()

Expand All @@ -24,25 +24,33 @@ set(INCLUDE ${PROJECT_SOURCE_DIR}/project/include)
set(SOURCE ${PROJECT_SOURCE_DIR}/project/src)

# adding libs

add_library(Models STATIC
${INCLUDE}/Models.hpp
${SOURCE}/Models.cpp)

add_library(MainDb STATIC
${INCLUDE}/MainDb.hpp
${INCLUDE}/IMainDb.hpp
${SOURCE}/MainDb.cpp)
# end libs

file(GLOB prod_sources
"${INCLUDE}/*.hpp"
"${SOURCE}/main.cpp")

add_executable(main.out ${SOURCE}/main.cpp)
target_link_libraries(main.out MainDb Models cassandra)

file(GLOB tests "${PROJECT_SOURCE_DIR}/project/tests/*.cpp")
list(REMOVE_ITEM tests "${PROJECT_SOURCE_DIR}/project/tests/main.cpp")

foreach(file ${tests})
set(name)
get_filename_component(name ${file} NAME_WE)
add_executable("${name}_tests"
${SOURCE}/${name}.cpp
${file}
"${PROJECT_SOURCE_DIR}/project/tests/main.cpp")
target_link_libraries("${name}_tests" gtest_main)
add_test(NAME ${name} COMMAND "${name}_tests")
endforeach()
# foreach(file ${tests})
# set(name)
# get_filename_component(name ${file} NAME_WE)
# add_executable("${name}_tests"
# ${SOURCE}/${name}.cpp
# ${file}
# "${PROJECT_SOURCE_DIR}/project/tests/main.cpp")
# target_link_libraries("${name}_tests" gtest_main gmock_main cassandra)
# add_test(NAME ${name} COMMAND "${name}_tests")
# endforeach()
30 changes: 30 additions & 0 deletions project/include/IMainDb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef PROJECT_INCLUDE_IMAINDB_HPP_
#define PROJECT_INCLUDE_IMAINDB_HPP_

#include <string>
#include "Models.hpp"

class IMainDb {
public:
virtual ~IMainDb() = default;

virtual User* searchUserLogin(std::string login, std::string password) = 0;
virtual void writeUser(const User& user) = 0;
virtual void changePassword(const User& user) = 0;


virtual std::string getCodeFromMessage(std::string messageId) = 0;
virtual void writeMessage(Message& message) = 0;

virtual std::vector<Message> getNLastMessagesFromDialogue(std::string dialogueId, long count) = 0;
virtual std::vector<std::string> getParticipantsLoginsFromDialogue(std::string dialogueId) = 0;
virtual std::vector<std::string> getAllDialoguesIdByLogin(std::string login) = 0;
virtual std::vector<std::string> getLastNDialoguesIdByLogin(std::string login, long count) = 0;
virtual DialogueList getLastNDialoguesWithLastMessage(User user, long count) = 0;

virtual Dialogue createDialogue(std::string firstId, std::string secondId) = 0;
virtual void deleteMessage(Message& message) = 0;
virtual void deleteDialogue(Dialogue& dialogue) = 0;
};

#endif // PROJECT_INCLUDE_IMAINDB_HPP_
44 changes: 44 additions & 0 deletions project/include/MainDb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef PROJECT_INCLUDE_MAINDB_HPP_
#define PROJECT_INCLUDE_MAINDB_HPP_

#include <vector>
#include <cassandra.h>
#include "IMainDb.hpp"
#include "Models.hpp"

// getAllMessagesFromDialogue with PAGINATION
// updateMessageIsRead, messageText, messageCode
class MainDb : public IMainDb {
public:
MainDb();
~MainDb();

User* searchUserLogin(std::string login, std::string password) override;
void writeUser(const User& user) override;
void changePassword(const User& user) override;

std::string getCodeFromMessage(std::string messageId) override;
void writeMessage(Message& message) override; // проставить айдишник если не проставлен
std::vector<Message> getNLastMessagesFromDialogue(std::string dialogueId, long count) override;
DialogueList getLastNDialoguesWithLastMessage(User user, long count) override;
std::vector<std::string> getParticipantsLoginsFromDialogue(std::string dialogueId) override;

std::vector<std::string> getAllDialoguesIdByLogin(std::string login) override;
std::vector<std::string> getLastNDialoguesIdByLogin(std::string login, long count) override;
Dialogue createDialogue(std::string firstId, std::string secondId) override;

void deleteMessage(Message& message) override;
void deleteDialogue(Dialogue& dialogue) override;

void connectToDb(const char* contactPoints);
void disconnectFromDb();

void migrate();
private:
CassFuture* connect_future_;
CassFuture* close_future_;
CassCluster* cluster_;
CassSession* session_;
};

#endif // PROJECT_INCLUDE_MAINDB_HPP_
Loading