-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frame and tests for the database #2
Open
RozeQz
wants to merge
16
commits into
main
Choose a base branch
from
database
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cc4e745
Add the frame for the database
RozeQz 524937f
Add tests
RozeQz 839e271
Configure cmake
RozeQz f0d4730
Add main abd gitignore
RozeQz fe93fbd
Divide files into src and include
RozeQz c86c3c0
Add methods for registration in UsersTable
RozeQz c2c0f21
Add tests for registration methods
RozeQz 9ed5a92
Add getAllRooms method for RoomsTable
RozeQz 40c4856
Add tests for getAllRooms method
RozeQz 3efc793
Add new table - 'films' and new role - 'left'
RozeQz 3729701
Add new class - FilmsTable
RozeQz e1fa5aa
Add methods in RoomTable to know current films
RozeQz 4b741c7
Fix cmake to run tests
RozeQz fec90f4
Add films tests
RozeQz ac18c1f
Remove string literals as path parameters
RozeQz 88c1b86
Fix return type of a checkCurrentFilm method
RozeQz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build/ | ||
|
||
.vscode | ||
|
||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(syncview) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(LIBCONFIG REQUIRED IMPORTED_TARGET libconfig++) | ||
|
||
add_subdirectory(database) | ||
|
||
add_executable(${PROJECT_NAME} main.cpp) | ||
|
||
add_compile_options(--coverage) | ||
add_link_options(--coverage) | ||
|
||
option(BUILD_TESTS "build tests" OFF) | ||
if(BUILD_TESTS) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage -lgcov" ) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${DATABASE_INCLUDE_DIRS}) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${DATABASE_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.0.0) | ||
project(database) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpqxx -lpq") | ||
|
||
find_library(PQXX_LIB pqxx) | ||
find_library(PQ_LIB pq) | ||
|
||
add_library(${PROJECT_NAME} src/PostgreSQL.cpp src/PostgreConnection.cpp src/UsersTable.cpp src/RoomsTable.cpp src/ViewersTable.cpp src/BidsTable.cpp src/VotesTable.cpp src/FilmsTable.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${PQXX_LIB} ${PQ_LIB} PkgConfig::LIBCONFIG) | ||
target_include_directories(${PROJECT_NAME} PUBLIC include) | ||
|
||
set(DATABASE_LIBRARIES ${PROJECT_NAME} PARENT_SCOPE) | ||
set(DATABASE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class BidsTable | ||
{ | ||
public: | ||
BidsTable() = default; | ||
BidsTable(std::shared_ptr<IDatabase> client); | ||
|
||
json addBid(const json &info) const; | ||
json deleteBid(const size_t id) const; | ||
json updateBid(const json &info) const; | ||
json isEnded(const size_t id) const; | ||
json getVotesFor(const size_t id) const; | ||
json getVotesAgainst(const size_t id) const; | ||
json getVotesCount(const size_t id) const; | ||
json getPointsFor(const size_t id) const; | ||
json getPointsAgainst(const size_t id) const; | ||
json getPointsSum(const size_t id) const; | ||
json getWinners(const size_t id, const bool answer) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class FilmsTable | ||
{ | ||
public: | ||
FilmsTable() = default; | ||
FilmsTable(std::shared_ptr<IDatabase> client); | ||
|
||
json addFilm(const json &info) const; | ||
json deleteFilm(const size_t id) const; | ||
json updateFilm(const json &info) const; | ||
json getFilmInfo(const size_t id) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "json.hpp" | ||
#include "constants.hpp" | ||
|
||
using json = nlohmann::json; | ||
|
||
class IDatabase | ||
{ | ||
public: | ||
virtual json createTable(json) = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. кажется немного странно конвернтировать из представления базы данных в json, чтобы потом json cконвертировать уже в классы вашей бизнес логики. возможно было бы лучше возвращать тут std::string |
||
virtual json dropTable(std::string) = 0; | ||
virtual json select(json) = 0; | ||
virtual json insert(json) = 0; | ||
virtual json remove(json) = 0; | ||
virtual json update(json) = 0; | ||
|
||
virtual ~IDatabase() = default; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <map> | ||
|
||
#include <libconfig.h++> | ||
|
||
#include "constants.hpp" | ||
|
||
using libconfig::Config; | ||
|
||
class PostgreConnection | ||
{ | ||
public: | ||
PostgreConnection(std::string config_path); | ||
|
||
PostgreConnection(std::string dbname, std::string user, std::string password = "postgres", | ||
std::string host = "127.0.0.1", std::string hostaddr = "", std::string port = "5432"); | ||
|
||
std::map<std::string, std::string> reformat() const; | ||
|
||
private: | ||
std::string dbname; | ||
std::string user; | ||
std::string password; | ||
std::string host; | ||
std::string hostaddr; | ||
std::string port; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include <pqxx/pqxx> | ||
#include <string> | ||
|
||
#include "IDatabase.hpp" | ||
#include "PostgreConnection.hpp" | ||
|
||
class PostgreSQL : public IDatabase | ||
{ | ||
public: | ||
PostgreSQL() = default; | ||
PostgreSQL(std::shared_ptr<PostgreConnection> _connectionParams); | ||
|
||
json createTable(json) override; | ||
json dropTable(std::string) override; | ||
json update(json) override; | ||
json insert(json) override; | ||
json select(json) override; | ||
json remove(json) override; | ||
|
||
~PostgreSQL() = default; | ||
|
||
private: | ||
std::shared_ptr<PostgreConnection> connectionParams; | ||
std::shared_ptr<pqxx::connection> connection; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class RoomsTable | ||
{ | ||
public: | ||
RoomsTable() = default; | ||
RoomsTable(std::shared_ptr<IDatabase> client); | ||
|
||
json addRoom(const json &info) const; | ||
json deleteRoom(const size_t id) const; | ||
json updateRoom(const json &info) const; | ||
bool checkRoom(const size_t id) const; | ||
json getRoomInfo(const size_t id) const; | ||
json getAllRooms() const; | ||
json getCurrentFilm(const size_t id) const; | ||
json checkCurrentFilm(const size_t id) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class UsersTable | ||
{ | ||
public: | ||
UsersTable() = default; | ||
UsersTable(std::shared_ptr<IDatabase> client); | ||
|
||
json addUser(const json &info) const; | ||
json deleteUser(const size_t id) const; | ||
json updateUser(const json &info) const; | ||
bool checkUserByID(const size_t id) const; | ||
bool checkUserByEmail(const std::string &email) const; | ||
bool checkUserByUsername(const std::string &username) const; | ||
json getUserInfo(const size_t id) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class ViewersTable | ||
{ | ||
public: | ||
ViewersTable() = default; | ||
ViewersTable(std::shared_ptr<IDatabase> client); | ||
|
||
json getUserRooms(const size_t id_user) const; | ||
json getRoomUsers(const size_t id_room) const; | ||
|
||
json addUserToRoom(const size_t id_user, const size_t id_room) const; | ||
json getUserPointsInRoom(const size_t id_user, const size_t id_room) const; | ||
json setUserPointsInRoom(const size_t id_user, const size_t id_room, const size_t points) const; | ||
json getUserRoleInRoom(const size_t id_user, const size_t id_room) const; | ||
json setUserRoleInRoom(const size_t id_user, const size_t id_room, const std::string &role) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "PostgreSQL.hpp" | ||
|
||
class VotesTable | ||
{ | ||
public: | ||
VotesTable() = default; | ||
VotesTable(std::shared_ptr<IDatabase> client); | ||
|
||
json addVote(const json &info) const; | ||
json deleteVote(const size_t id) const; | ||
json updateVote(const json &info) const; | ||
|
||
private: | ||
std::shared_ptr<IDatabase> client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
const std::string STATUS_FIELD = "status"; | ||
const std::string PARAMS_FIELD = "parameters"; | ||
const std::string ERROR_STATUS = "error"; | ||
const std::string SUCCESS_STATUS = "ok"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в объявлении обычно const у value не пишут