Skip to content
Merged
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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches: [main, Development]
pull_request:
branches: [main, Development]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake libpqxx-dev libgtest-dev

- name: Build
run: |
cd librarybuilder
mkdir -p build
cd build
cmake ..
make

- name: Run unit tests
run: |
cd librarybuilder/build
./tests --gtest_filter="-CollectionLoadingTest.*"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
scrapwork/*
recommendermodel/.venv/*
recommendermodel/Data/title.basics.tsv.gz
recommendermodel/Data/title.basics.tsv.gz
librarybuilder/build/
recommendermodel/src/__pycache__/*
*.pyc
15 changes: 0 additions & 15 deletions librarybuilder/.vscode/CMakeLists.txt

This file was deleted.

49 changes: 49 additions & 0 deletions librarybuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required (VERSION 3.10)
project(librarybuilder VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Test Coverage
option(COVERAGE "Enable test coverage" OFF)
if(COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()

find_package(PkgConfig REQUIRED)
pkg_check_modules(PQXX REQUIRED libpqxx)

set(LIB_SOURCES
src/Media.cpp
src/MediaCollection.cpp
src/Movie.cpp
src/MovieCollection.cpp
src/Book.cpp
src/BookCollection.cpp
src/DataBaseConnection.cpp
src/SQLQueryUtil.cpp
src/Util.cpp)

# Main Exectuable
add_executable(main src/main.cpp ${LIB_SOURCES})
target_include_directories(main PRIVATE include ${PQXX_INCLUDE_DIRS})
target_link_libraries(main ${PQXX_LIBRARIES})


# Test Exectuable
find_package(GTest REQUIRED)
add_executable(tests
test/MovieCollectionTest.cpp
test/BookCollectionTest.cpp
test/CollectionLoadingTest.cpp
test/UtilTest.cpp
${LIB_SOURCES}
)

target_include_directories(tests PRIVATE include ${PQXX_INCLUDE_DIRS})
target_link_libraries(tests GTest::GTest GTest::Main ${PQXX_LIBRARIES})

enable_testing()
add_test(NAME AllTests COMMAND tests)
Binary file removed librarybuilder/build/main
Binary file not shown.
24 changes: 12 additions & 12 deletions librarybuilder/include/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ class Book: public Media{
std::string author;
public:
// Constructors
Book(std::string title, int times_consumed=def_times_consumed,
int user_rating=def_user_rating, std::string isbn=def_string_val,
std::string genre=def_string_val, std::string sub_genre = def_string_val,
std::string author=def_author);
Book(const std::string&title, int times_consumed=def_times_consumed,
int user_rating=def_user_rating, const std::string &isbn=def_string_val,
const std::string &genre=def_string_val, const std::string &sub_genre = def_string_val,
const std::string &author=def_author);

// Getters and Setters
int get_times_read() const;
std::string get_isbn() const;
std::string get_genre() const;
std::string get_sub_genre() const;
std::string get_author() const;
const std::string &get_isbn() const;
const std::string &get_genre() const;
const std::string &get_sub_genre() const;
const std::string &get_author() const;
void set_times_read(int times_read);
void set_isbn(std::string isbn);
void set_genre(std::string genre);
void set_sub_genre(std::string sub_genre);
void set_author(std::string author);
void set_isbn(const std::string &isbn);
void set_genre(const std::string &genre);
void set_sub_genre(const std::string &sub_genre);
void set_author(const std::string &author);

// Custom Methods
void increment_read(){Media::increment_times_consumed();} // Wrapper method to provide more intuitive naming
Expand Down
18 changes: 12 additions & 6 deletions librarybuilder/include/BookCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ class BookCollection: public MediaCollection{
std::vector<Book> *books;
public:
// Constructor
BookCollection(std::string name);
// Copy Constructor
BookCollection(const std::string &name);
// Deep Copy Constructor
BookCollection(const BookCollection &source);
// Copy Assignment Operator
BookCollection &operator=(const BookCollection &source);
// Move Constructor
BookCollection(BookCollection &&source) noexcept;
// Move Assignment Operator
BookCollection &operator=(BookCollection &&source) noexcept;
// Destructor
~BookCollection();

// Getters and Setters
std::vector<Book> get_books() const;
const std::vector<Book> &get_books() const;

// Check if book exist in collection, if it doesn't add it
bool add_book(std::string title, int times_read, int user_rating,
std::string isbn, std::string genre, std::string sub_genre, std::string author);
bool add_book(const std::string &title, int times_read, int user_rating,
const std::string &isbn, const std::string &genre, const std::string &sub_genre, const std::string &author);
// If book exists, increment times watched
bool increment_read(std::string book);
bool increment_read(const std::string &book);
// Display's Book collection
virtual void display() const override;
};
Expand Down
7 changes: 4 additions & 3 deletions librarybuilder/include/DataBaseConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

class DataBaseConnection{
private:
std::string connectionString = "dbname=movie_book_database user=postgres host=localhost password=password port=5432";
std::string connectionString;
public:
pqxx::connection* conn;

DataBaseConnection();
void set_connection();
void disconnect();
pqxx::result query(std::string strSQL);
std::string load_sql_query(std::string sql_file_path);
pqxx::result query(const std::string &strSQL);
std::string load_sql_query(const std::string &sql_file_path);

};

Expand Down
6 changes: 3 additions & 3 deletions librarybuilder/include/Media.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Media{
int user_rating;
public:
// Constructors
Media(std::string title, int times_consumed=def_times_consumed, int user_rating=def_user_rating);
Media(const std::string &title, int times_consumed=def_times_consumed, int user_rating=def_user_rating);

// Operator Overloading
bool operator==(const Media &rhs) const;
bool operator<(const Media &rhs) const;
bool operator>(const Media &rhs) const;

// Getters and Setters
std::string get_title() const;
const std::string &get_title() const;
int get_times_consumed() const;
int get_user_rating() const;
void set_title(std::string title);
void set_title(const std::string &title);
void set_times_consumed(int times_consumed);
void set_user_rating(int rating);

Expand Down
4 changes: 2 additions & 2 deletions librarybuilder/include/MediaCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class MediaCollection{
std::string name;
public:
// Constructor
MediaCollection(std::string name);
MediaCollection(const std::string &name);
// Destructor
virtual ~MediaCollection(){}

// Getters and Setters
std::string get_name() const;
void set_name(std::string name);
void set_name(const std::string &name);

virtual void display() const = 0;

Expand Down
8 changes: 4 additions & 4 deletions librarybuilder/include/Movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Movie: public Media {

public:
// Constructors
Movie(std::string title, int times_consumed=def_times_consumed,
int user_rating=def_user_rating, std::string mpa_rating=def_mpa_rating);
Movie(const std::string &title, int times_consumed=def_times_consumed,
int user_rating=def_user_rating, const std::string &mpa_rating=def_mpa_rating);


// Getters and Setters
std::string get_mpa_rating() const;
const std::string &get_mpa_rating() const;
int get_times_watched() const;
void set_mpa_rating(std::string mpa_rating);
void set_mpa_rating(const std::string &mpa_rating);
void set_times_watched(int times_watched);

// Custom Methods
Expand Down
16 changes: 11 additions & 5 deletions librarybuilder/include/MovieCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ class MovieCollection: public MediaCollection{
std::vector<Movie> *movies;
public:
// Constructor
MovieCollection(std::string name);
// Copy Constructor
MovieCollection(const std::string &name);
// Deep Copy Constructor
MovieCollection(const MovieCollection &source);
// Copy Assignment Operator
MovieCollection &operator=(const MovieCollection &source);
// Move Constructor
MovieCollection(MovieCollection &&source) noexcept;
// Move Assignment Operator
MovieCollection &operator=(MovieCollection &&source) noexcept;
// Destructor
~MovieCollection();

// Getters and Setters
std::vector<Movie> get_movies() const;
const std::vector<Movie> &get_movies() const;

// Check if movie exist in collection, if it doesn't add it
bool add_movie(std::string title, std::string mpa_rating, int times_watched, int rating);
bool add_movie(const std::string &title, const std::string &mpa_rating, int times_watched, int rating);
// If movie exists, increment times watched
bool increment_watched(std::string movie);
bool increment_watched(const std::string &movie);
// Display's Movie collection
virtual void display() const override;
};
Expand Down
69 changes: 32 additions & 37 deletions librarybuilder/include/SQLQueryUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,20 @@
#include "MediaCollection.h"
#include "DataBaseConnection.h"

/**
* @brief Adds a movie to an existing SQL table
*
* This function adds an entry to a movie table located in a given database
*
* @param database The database object that contains the table
* @param movie The movie to be added to the table
* @param table_name The table to add the movie to
*
*/
void add_row(DataBaseConnection &database, const MovieCollection &movie, std::string table_name);

/**
* @brief Adds a book to an existing SQL table
*
* This function adds an entry to a book table located in a given database
*
* @param database The database object that contains the table
* @param book The book to be added to the table
* @param table_name The table to add the book to
*
*/
void add_row(DataBaseConnection &database, const BookCollection &book, std::string table_name);

/**
* @brief Creates a SQL table
*
* This function creates a new SQL table to hold a movie collection
*
* @brief Creates a SQL table for a movie collection
*
* @param database The database object that will hold the table
* @param moviecollection The movie collection to be used to create the table
*
*/
void create_table(DataBaseConnection &database, const MovieCollection &moviecollection);

/**
* @brief Creates a SQL table
*
* This function creates a new SQL table to hold a book collection
*
* @brief Creates a SQL table for a book collection
*
* @param database The database object that will hold the table
* @param bookcollection The book collection to be used to create the table
*
*/
void create_table(DataBaseConnection &database, const BookCollection &bookcollection);

Expand All @@ -58,10 +29,34 @@ void create_table(DataBaseConnection &database, const BookCollection &bookcollec
* This function deletes an entry from a SQL table
*
* @param database The database object that contains the table
* @param table_name The table to add the book to
* @param table_name The table to delete the row from a media collection
* @param title The book or movie to be deleted
*/
void delete_row(DataBaseConnection &database, std::string table_name, std::string title);

void delete_row(DataBaseConnection &database, const std::string &table_name, const std::string &title);
/**
* @brief Adds a movie to an existing SQL table
*
* This function adds an entry to a movie table located in a given database
*
* @param database The database object that contains the table
* @param movie The movie to be added to the table
* @param table_name The table to add the movie to
*
*/
void add_row(DataBaseConnection &database, const Movie &movie, const std::string &table_name);

/**
* @brief Adds a book to an existing SQL table
*
* This function adds an entry to a book table located in a given database
*
* @param database The database object that contains the table
* @param book The book to be added to the table
* @param table_name The table to add the book to
*
*/
void add_row(DataBaseConnection &database, const Book &book, const std::string &table_name);

/**
* @brief Loads a movie collection
Expand All @@ -71,7 +66,7 @@ void delete_row(DataBaseConnection &database, std::string table_name, std::strin
* @param database The database object that contains the table
* @param table_name The table to load
*/
MovieCollection load_movie_collection(DataBaseConnection &database, std::string table_name);
MovieCollection load_movie_collection(DataBaseConnection &database, const std::string &table_name);

/**
* @brief Loads a book collection
Expand All @@ -81,6 +76,6 @@ MovieCollection load_movie_collection(DataBaseConnection &database, std::string
* @param database The database object that contains the table
* @param table_name The table to load
*/
BookCollection load_book_collection(DataBaseConnection &database, std::string table_name);
BookCollection load_book_collection(DataBaseConnection &database, const std::string &table_name);

#endif // _SQLQUERYUTIL_H_
Loading
Loading