School Commit Init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
.vscode
|
||||
/x64/Debug
|
||||
/.vs/A8-DanielCujba
|
||||
/.vs
|
||||
/A8-DanielCujba.vcxproj.user
|
||||
/A8-DanielCujba.vcxproj.filters
|
||||
/A8-DanielCujba.vcxproj
|
||||
/A8-DanielCujba.sln
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "A8DanielCujba.h"
|
||||
|
||||
A8DanielCujba::A8DanielCujba(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
}
|
||||
|
||||
A8DanielCujba::~A8DanielCujba()
|
||||
{}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include "ui_A8DanielCujba.h"
|
||||
|
||||
class A8DanielCujba : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
A8DanielCujba(QWidget *parent = nullptr);
|
||||
~A8DanielCujba();
|
||||
|
||||
private:
|
||||
Ui::A8DanielCujbaClass ui;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
<RCC>
|
||||
<qresource prefix="A8DanielCujba">
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,28 @@
|
||||
<UI version="4.0" >
|
||||
<class>A8DanielCujbaClass</class>
|
||||
<widget class="QMainWindow" name="A8DanielCujbaClass" >
|
||||
<property name="objectName" >
|
||||
<string notr="true">A8DanielCujbaClass</string>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>A8DanielCujba</string>
|
||||
</property> <widget class="QMenuBar" name="menuBar" />
|
||||
<widget class="QToolBar" name="mainToolBar" />
|
||||
<widget class="QWidget" name="centralWidget" />
|
||||
<widget class="QStatusBar" name="statusBar" />
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<resources>
|
||||
<include location="A8DanielCujba.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</UI>
|
||||
@@ -0,0 +1,20 @@
|
||||
# Assignment 08-09
|
||||
|
||||
## Requirements
|
||||
- Create a graphical user interface using the Qt framework for the problem you have been working on (A04-05, A06, A07).
|
||||
|
||||
## Week 11
|
||||
- Implement the interface design, without using the Qt Designer. Use layouts to design your interface.
|
||||
- The list or table displaying the repository entities in administrator mode should be populated using your input file.
|
||||
|
||||
## Week 13
|
||||
- All functionalities must be available through the GUI. You may use Qt Designer, if you want to change the initial design of your GUI.
|
||||
- The functionality of the application must be the same (including the one-by-one iteration of objects for the user mode).
|
||||
|
||||
## Bonus possibility (0.2p, deadline week 13)
|
||||
Create a graphical representation of the data in your application. You have an example below: a bar chart representing the number of songs for each artist. Your representations can be a bar chart, a pie chart or another type of chart. You can even use circles or rectangles or any other geometric shapes to represent the data.
|
||||
|
||||
Hint: You can use QPainter (https://doc.qt.io/qt-6/qpainter.html), QGraphicsScene (https://doc.qt.io/qt-6/qgraphicsscene.html) or a special widget designed for plotting and data visualisation – QCustomPlot (http://www.qcustomplot.com/).
|
||||
|
||||
<img width="704" alt="Screenshot 2021-04-17 at 20 24 04" src="https://user-images.githubusercontent.com/25611695/115121335-df0f7e00-9fba-11eb-8839-40cd55da1d69.png">
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
38,Bej,55,30,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71zZoa1e-xL._AC_UX466_.jpg
|
||||
40,Bej,55,25,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71zZoa1e-xL._AC_UX466_.jpg
|
||||
36,Blac",60,5,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/41RBzLubByL._AC_UY550_.jpg
|
||||
40,Black,60,50,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/41RBzLubByL._AC_UY550_.jpg
|
||||
38,Army Green,60,40,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/61Qptn0CKQL._AC_UX342_.jpg
|
||||
42,Army Green,60,40,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/61Qptn0CKQL._AC_UX342_.jpg
|
||||
40,Black,100,3,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71YLqJCurtL._AC_UY550_.jpg
|
||||
38,Red,33,20,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/816lGcU-fWL._AC_UX425_.jpg
|
||||
40,Red,33,33,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/816lGcU-fWL._AC_UX425_.jpg
|
||||
38,Blue,51,15,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/51zHT88C6zL._AC_UY550_.jpg
|
||||
|
Can't render this file because it contains an unexpected character in line 3 and column 8.
|
@@ -0,0 +1,16 @@
|
||||
#include "A8DanielCujba.h"
|
||||
#include <QtWidgets/QApplication>
|
||||
#include "src/gui/gui.h"
|
||||
#include <crtdbg.h>
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
GUI g;
|
||||
g.run();
|
||||
a.exec();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
38,Bej,55,26,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71zZoa1e-xL._AC_UX466_.jpg
|
||||
40,Bej,55,24,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71zZoa1e-xL._AC_UX466_.jpg
|
||||
36,Black,60,4,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/41RBzLubByL._AC_UY550_.jpg
|
||||
40,Black,60,50,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/41RBzLubByL._AC_UY550_.jpg
|
||||
38,Army Green,60,40,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/61Qptn0CKQL._AC_UX342_.jpg
|
||||
42,Army Green,60,40,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/61Qptn0CKQL._AC_UX342_.jpg
|
||||
40,Black,100,3,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71YLqJCurtL._AC_UY550_.jpg
|
||||
38,Red,33,20,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/816lGcU-fWL._AC_UX425_.jpg
|
||||
40,Red,33,33,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/816lGcU-fWL._AC_UX425_.jpg
|
||||
38,Blue,51,15,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/51zHT88C6zL._AC_UY550_.jpg
|
||||
|
@@ -0,0 +1 @@
|
||||
38,Bej,55,1,https://m.media-amazon.com/images/W/IMAGERENDERING_521856-T2/images/I/71zZoa1e-xL._AC_UX466_.jpg
|
||||
|
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><title>Shopping list</title></head><body><table border="1"><tr><td>Size</td><td>Colour</td><td>Price</td><td>Quantity</td><td>Photograph Link</td><td>Photo</td></tr></table></body></html>
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#include "admin_controller.h"
|
||||
#include "../../exceptions/exceptions.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
AdminController::AdminController(std::shared_ptr<FileRepository> repo){
|
||||
this->_repo = repo;
|
||||
}
|
||||
|
||||
AdminController::~AdminController(){
|
||||
|
||||
}
|
||||
void AdminController::add(int size,std::string colour,int price,int quantity,std::string photograph){
|
||||
Trench trench(size,colour,price,quantity,photograph);
|
||||
this->_repo->add(trench);
|
||||
}
|
||||
void AdminController::remove(int size,std::string colour,std::string photograph){
|
||||
Trench trench(size,colour,0,0,photograph);
|
||||
this->_repo->remove(trench);
|
||||
}
|
||||
void AdminController::remove(int index){
|
||||
this->_repo->remove(index);
|
||||
}
|
||||
void AdminController::update(int size,std::string colour,int price,int quantity,std::string photograph){
|
||||
Trench trench(size,colour,price,quantity,photograph);
|
||||
int index = this->_repo->get(trench);
|
||||
if(index==-1){
|
||||
throw AdminControllerException("Trench does not exist");
|
||||
}
|
||||
this->_repo->update(index,price,quantity);
|
||||
|
||||
}
|
||||
int AdminController::get(int size,std::string colour,std::string photograph){
|
||||
if(size<=0){
|
||||
throw AdminControllerException("Size must be greater than 0");
|
||||
}
|
||||
if(colour.length()==0){
|
||||
throw AdminControllerException("Colour must not be empty");
|
||||
}
|
||||
if(photograph.length()==0){
|
||||
throw AdminControllerException("Photograph must not be empty");
|
||||
}
|
||||
Trench trench(size,colour,0,0,photograph);
|
||||
int index = this->_repo->get(trench);
|
||||
return index;
|
||||
|
||||
}
|
||||
int AdminController::size(){
|
||||
return this->_repo->size();
|
||||
}
|
||||
Trench& AdminController::operator[](int index){
|
||||
return (*this->_repo)[index];
|
||||
}
|
||||
std::shared_ptr<FileRepository> AdminController::getAll(){
|
||||
return this->_repo;
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
#include "../../repository/FileRepository.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class AdminController {
|
||||
private:
|
||||
std::shared_ptr<FileRepository> _repo;
|
||||
public:
|
||||
|
||||
|
||||
/*
|
||||
* Constructor for the AdminController class
|
||||
* Input: repo - Repository object
|
||||
* Output: adminController object
|
||||
*/
|
||||
AdminController(std::shared_ptr<FileRepository> repo);
|
||||
|
||||
/*
|
||||
* Destructor for the AdminController class
|
||||
* Input: -
|
||||
* Output: -
|
||||
*/
|
||||
~AdminController();
|
||||
|
||||
/*
|
||||
* Adds a trench coat to the repository
|
||||
* Input: size - integer
|
||||
* colour - string
|
||||
* price - integer
|
||||
* quantity - integer
|
||||
* photograph - string
|
||||
* Output: -
|
||||
* Throws: AdminControllerException if: size<=0
|
||||
* colour is empty
|
||||
* price<=0
|
||||
* quantity<0
|
||||
* photograph is empty
|
||||
* trench coat already exists
|
||||
*/
|
||||
void add(int size,std::string colour,int price,int quantity,std::string photograph);
|
||||
|
||||
/*
|
||||
* Removes a trench coat from the repository
|
||||
* Input: size - integer
|
||||
* colour - string
|
||||
* photograph - string
|
||||
* Output: -
|
||||
* Throws: AdminControllerException if: size<=0
|
||||
* colour is empty
|
||||
* photograph is empty
|
||||
* trench coat does not exist
|
||||
*/
|
||||
void remove(int size,std::string colour,std::string photograph);
|
||||
|
||||
/*
|
||||
* Removes a trench coat from the repository
|
||||
* Input: index - integer
|
||||
* Output: -
|
||||
* Throws: RepoException if: index is out of bounds
|
||||
*/
|
||||
void remove(int index);
|
||||
|
||||
/*
|
||||
* Updates a trench coat from the repository. If the price or quantity is -1, it will not be updated
|
||||
* Input: size - integer
|
||||
* colour - string
|
||||
* price - integer
|
||||
* quantity - integer
|
||||
* photograph - string
|
||||
* Output: -
|
||||
* Throws: AdminControllerException if: size<=0
|
||||
* colour is empty
|
||||
* price!=-1 and price<=0
|
||||
* quantity!=-1 and quantity<0
|
||||
* photograph is empty
|
||||
* trench coat does not exist
|
||||
*/
|
||||
void update(int size,std::string colour,int price,int quantity,std::string photograph);
|
||||
|
||||
/*
|
||||
* Returns the index of a trench coat in the repository. If it does not exist, it returns -1
|
||||
* Input: size - integer
|
||||
* colour - string
|
||||
* photograph - string
|
||||
* Output: index - integer
|
||||
*/
|
||||
int get(int size,std::string colour,std::string photograph);
|
||||
|
||||
/*
|
||||
* Returns the number of trench coats in the repository
|
||||
* Input: -
|
||||
* Output: size - integer
|
||||
*/
|
||||
int size();
|
||||
|
||||
/*
|
||||
* Returns the trench coat at the given index
|
||||
* Input: index - integer
|
||||
* Output: trench coat - Trench object
|
||||
* Throws: RepoException if: index is out of bounds
|
||||
*/
|
||||
Trench& operator[](int index);
|
||||
|
||||
/*
|
||||
* Returns an iterator for all the trench coats in the repository
|
||||
* Input: -
|
||||
* Output: iterator
|
||||
*/
|
||||
std::shared_ptr<FileRepository> getAll();
|
||||
|
||||
};
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#include "../../repository/FileRepository.h"
|
||||
#include "../../domain/trench.h"
|
||||
#include "user_controller.h"
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
UserController::UserController(std::shared_ptr<FileRepository> repo,std::shared_ptr<FileRepository> shoppingRepo) {
|
||||
this->_repo = repo;
|
||||
this->_shoppingRepository = shoppingRepo;
|
||||
}
|
||||
|
||||
UserController::~UserController() {
|
||||
|
||||
}
|
||||
|
||||
void UserController::addProductToShoppingList(Trench trench) {
|
||||
int index = this->_shoppingRepository->get(trench);
|
||||
int repo_index = this->_repo->get(trench);
|
||||
if(index==-1) {
|
||||
Trench trenchCopy = trench;
|
||||
trenchCopy.quantity(1);
|
||||
this->_shoppingRepository->add(trenchCopy);
|
||||
trench.quantity(trench.quantity()-1);
|
||||
(*this->_repo)[repo_index].quantity((*this->_repo)[repo_index].quantity()-1);
|
||||
return;
|
||||
}
|
||||
trench.quantity(trench.quantity()-1);
|
||||
this->_shoppingRepository->update(index,trench.price(),(*this->_shoppingRepository)[index].quantity()+1);
|
||||
(*this->_repo)[repo_index].quantity((*this->_repo)[repo_index].quantity()-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int UserController::shoppingListTotal() {
|
||||
int total = 0;
|
||||
for(Trench i : *this->_shoppingRepository) {
|
||||
total+=i.quantity()*i.price();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Trench> UserController::getTrenchCarousel(int size) {
|
||||
std::vector<Trench> trenchCarousel;
|
||||
for(Trench i : *this->_repo){
|
||||
if((size == -1||i.size()==size) && i.quantity()>0){
|
||||
Trench copy = i;
|
||||
trenchCarousel.push_back(copy);
|
||||
}
|
||||
}
|
||||
return trenchCarousel;
|
||||
}
|
||||
|
||||
void UserController::openShoppingList() {
|
||||
this->_shoppingRepository->open();
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include "../../repository/FileRepository.h"
|
||||
#include "../../domain/trench.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class UserController {
|
||||
private:
|
||||
std::shared_ptr<FileRepository> _repo;
|
||||
std::shared_ptr<FileRepository> _shoppingRepository;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Constructor for the UserController class
|
||||
* Input: repo - Repository object
|
||||
* Output: userController object
|
||||
*/
|
||||
UserController(std::shared_ptr<FileRepository> repo,std::shared_ptr<FileRepository> shoppingRepo);
|
||||
|
||||
/*
|
||||
* Destructor for the UserController class
|
||||
* Input: -
|
||||
* Output: -
|
||||
*/
|
||||
~UserController();
|
||||
|
||||
/*
|
||||
* Adds a trench coat to the shopping list
|
||||
* Input: trench - Trench object
|
||||
* Output: -
|
||||
*/
|
||||
void addProductToShoppingList(Trench trench);
|
||||
|
||||
/*
|
||||
* Returns the total price of the shopping list
|
||||
* Input: -
|
||||
* Output: total - integer
|
||||
*/
|
||||
int shoppingListTotal();
|
||||
|
||||
|
||||
/*
|
||||
* Returns a vector of trench coats that are in the shopping list
|
||||
* Input: size - integer
|
||||
* Output: trenchCarousel - vector<Trench*> object
|
||||
*/
|
||||
std::vector<Trench> getTrenchCarousel(int size);
|
||||
|
||||
void openShoppingList();
|
||||
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "trench.h"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
Trench::Trench(int size, std::string colour, int price, int quantity, std::string photograph){
|
||||
this->_size = size;
|
||||
this->_colour = colour;
|
||||
this->_price = price;
|
||||
this->_quantity = quantity;
|
||||
this->_photograph=photograph;
|
||||
}
|
||||
|
||||
Trench::~Trench(){
|
||||
|
||||
}
|
||||
|
||||
Trench::Trench(const Trench &trench){
|
||||
_size = trench.size();
|
||||
_colour = trench.colour();
|
||||
_price = trench.price();
|
||||
_quantity = trench.quantity();
|
||||
_photograph = trench.photograph();
|
||||
}
|
||||
|
||||
Trench& Trench::operator=(const Trench &trench){
|
||||
this->_size = trench.size();
|
||||
this->_colour=trench.colour();
|
||||
this->_price = trench.price();
|
||||
this->_quantity = trench.quantity();
|
||||
this->_photograph = trench.photograph();
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Trench::size() const {
|
||||
return this->_size;
|
||||
}
|
||||
|
||||
void Trench::size(int newSize){
|
||||
this->_size = newSize;
|
||||
}
|
||||
|
||||
std::string Trench::colour() const {
|
||||
return this->_colour;
|
||||
}
|
||||
|
||||
void Trench::colour(std::string newColour){
|
||||
this->_colour = newColour;
|
||||
}
|
||||
|
||||
int Trench::price() const {
|
||||
return this->_price;
|
||||
}
|
||||
|
||||
void Trench::price(int newPrice){
|
||||
this->_price = newPrice;
|
||||
}
|
||||
|
||||
int Trench::quantity() const{
|
||||
return this->_quantity;
|
||||
}
|
||||
|
||||
void Trench::quantity(int newQuantity){
|
||||
this->_quantity = newQuantity;
|
||||
}
|
||||
|
||||
std::string Trench::photograph() const {
|
||||
return this->_photograph;
|
||||
}
|
||||
|
||||
void Trench::photograph(std::string newPhotograph){
|
||||
this->_photograph = newPhotograph;
|
||||
}
|
||||
|
||||
bool Trench::operator==(const Trench& t){
|
||||
if(this->_size==t.size() && this->_colour == t.colour() && this->_photograph == t.photograph()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Trench& trench){
|
||||
os << "Size: " << trench.size() << " | Colour: " << trench.colour() << " | Price: " << trench.price() << " | Quantity: " << trench.quantity() << " | Photograph Link: " << trench.photograph() << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ofstream& operator<<(std::ofstream& os, const Trench& trench){
|
||||
os << trench.size() << "," << trench.colour() << "," << trench.price() << "," << trench.quantity() << "," << trench.photograph() << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ifstream& operator>>(std::ifstream& is, Trench& trench){
|
||||
std::string line;
|
||||
std::getline(is, line);
|
||||
if(line == ""){
|
||||
return is;
|
||||
}
|
||||
std::string delimiter = ",";
|
||||
size_t pos = 0;
|
||||
std::string token;
|
||||
int i = 0;
|
||||
while ((pos = line.find(delimiter)) != std::string::npos) {
|
||||
token = line.substr(0, pos);
|
||||
switch(i){
|
||||
case 0:
|
||||
trench.size(std::stoi(token));
|
||||
break;
|
||||
case 1:
|
||||
trench.colour(token);
|
||||
break;
|
||||
case 2:
|
||||
trench.price(std::stoi(token));
|
||||
break;
|
||||
case 3:
|
||||
trench.quantity(std::stoi(token));
|
||||
break;
|
||||
}
|
||||
line.erase(0, pos + delimiter.length());
|
||||
i++;
|
||||
}
|
||||
trench.photograph(line);
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
class Trench {
|
||||
|
||||
private:
|
||||
|
||||
int _size;
|
||||
std::string _colour;
|
||||
int _price;
|
||||
int _quantity;
|
||||
std::string _photograph;
|
||||
|
||||
public:
|
||||
Trench()=default;
|
||||
|
||||
/*
|
||||
* Constructor for the Trench class
|
||||
* Input: size - integer
|
||||
* colour - string
|
||||
* price - integer
|
||||
* quantity - integer
|
||||
* photograph - string
|
||||
* Output: trench object
|
||||
*/
|
||||
Trench(int size, std::string colour, int price, int quantity, std::string photograph);
|
||||
|
||||
|
||||
/*
|
||||
* Destructor for the Trench class
|
||||
* Input: -
|
||||
* Output: -
|
||||
*/
|
||||
~Trench();
|
||||
|
||||
/*
|
||||
* Copy constructor for the Trench class
|
||||
* Input: trench - trench object
|
||||
* Output: trench object
|
||||
*/
|
||||
Trench(const Trench &trench);
|
||||
|
||||
/*
|
||||
* Overload of the = operator
|
||||
* Input: trench - trench object
|
||||
* Output: trench object
|
||||
*/
|
||||
Trench& operator=(const Trench &trench);
|
||||
|
||||
/*
|
||||
* Getter for the size attribute
|
||||
* Input: -
|
||||
* Output: size - integer
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
/*
|
||||
* Setter for the size attribute
|
||||
* Input: newSize - integer
|
||||
* Output: -
|
||||
*/
|
||||
void size(int newSize);
|
||||
|
||||
/*
|
||||
* Getter for the colour attribute
|
||||
* Input: -
|
||||
* Output: colour - string
|
||||
*/
|
||||
std::string colour() const;
|
||||
|
||||
/*
|
||||
* Setter for the colour attribute
|
||||
* Input: newColour - string
|
||||
* Output: -
|
||||
*/
|
||||
void colour(std::string newColour);
|
||||
|
||||
/*
|
||||
* Getter for the price attribute
|
||||
* Input: -
|
||||
* Output: price - integer
|
||||
*/
|
||||
int price() const;
|
||||
|
||||
/*
|
||||
* Setter for the price attribute
|
||||
* Input: newPrice - integer
|
||||
* Output: -
|
||||
*/
|
||||
void price(int newPrice);
|
||||
|
||||
/*
|
||||
* Getter for the quantity attribute
|
||||
* Input: -
|
||||
* Output: quantity - integer
|
||||
*/
|
||||
int quantity() const;
|
||||
|
||||
/*
|
||||
* Setter for the quantity attribute
|
||||
* Input: newQuantity - integer
|
||||
* Output: -
|
||||
*/
|
||||
void quantity(int newQuantity);
|
||||
|
||||
/*
|
||||
* Getter for the photograph attribute
|
||||
* Input: -
|
||||
* Output: photograph - string
|
||||
*/
|
||||
std::string photograph() const;
|
||||
|
||||
/*
|
||||
* Setter for the photograph attribute
|
||||
* Input: newPhotograph - string
|
||||
* Output: -
|
||||
*/
|
||||
void photograph(std::string newPhotograph);
|
||||
|
||||
/*
|
||||
* Overload of the == operator
|
||||
* Input: trench - trench object
|
||||
* Output: true - if the trench objects are the same
|
||||
* false - otherwise
|
||||
*/
|
||||
bool operator==(const Trench& t);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Trench& trench);
|
||||
|
||||
friend std::ofstream& operator<<(std::ofstream& os, const Trench& trench);
|
||||
|
||||
friend std::ifstream& operator>>(std::ifstream& is, Trench& trench);
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "exceptions.h"
|
||||
|
||||
RepoException::RepoException(const char* message){
|
||||
this->_message = message;
|
||||
}
|
||||
|
||||
const char* RepoException::what() const noexcept {
|
||||
return this->_message;
|
||||
}
|
||||
|
||||
AdminControllerException::AdminControllerException(const char* message){
|
||||
this->_message = message;
|
||||
}
|
||||
|
||||
const char* AdminControllerException::what() const noexcept {
|
||||
return this->_message;
|
||||
}
|
||||
|
||||
ValidatorException::ValidatorException(const char* message){
|
||||
this->_message = message;
|
||||
}
|
||||
|
||||
const char* ValidatorException::what() const noexcept {
|
||||
return this->_message;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <exception>
|
||||
|
||||
class RepoException : public std::exception {
|
||||
public:
|
||||
RepoException(const char* message);
|
||||
const char* what() const noexcept override;
|
||||
private:
|
||||
const char* _message;
|
||||
};
|
||||
|
||||
class AdminControllerException : public std::exception {
|
||||
public:
|
||||
AdminControllerException(const char* message);
|
||||
const char* what() const noexcept override;
|
||||
private:
|
||||
const char* _message;
|
||||
};
|
||||
|
||||
class ValidatorException : public std::exception{
|
||||
public:
|
||||
ValidatorException(const char* message);
|
||||
const char* what() const noexcept override;
|
||||
private:
|
||||
const char* _message;
|
||||
};
|
||||
@@ -0,0 +1,436 @@
|
||||
#include "gui.h"
|
||||
|
||||
GUI::GUI(){
|
||||
this->repoSelector = new QWidget;
|
||||
this->mainMenu = new QWidget;
|
||||
this->adminMenu = new QWidget;
|
||||
this->userMenu = new QWidget;
|
||||
this->addMenu = new QWidget;
|
||||
this->deleteMenu = new QWidget;
|
||||
this->updateMenu = new QWidget;
|
||||
this->showMenu = new QWidget;
|
||||
|
||||
this->repoSelectorLayout = new QVBoxLayout;
|
||||
this->mainMenuLayout = new QVBoxLayout;
|
||||
this->adminMenuLayout = new QVBoxLayout;
|
||||
this->userMenuLayout = new QVBoxLayout;
|
||||
this->addMenuLayout = new QFormLayout;
|
||||
this->deleteMenuLayout = new QFormLayout;
|
||||
this->updateMenuLayout = new QFormLayout;
|
||||
this->showMenuLayout = new QVBoxLayout;
|
||||
|
||||
this->CSVBtn = new QPushButton("CSV");
|
||||
this->HTMLBtn = new QPushButton("HTML");
|
||||
|
||||
this->adminBtn = new QPushButton("Admin");
|
||||
this->userBtn = new QPushButton("User");
|
||||
|
||||
this->addBtn = new QPushButton("Add");
|
||||
this->deleteBtn = new QPushButton("Delete");
|
||||
this->updateBtn = new QPushButton("Update");
|
||||
this->showBtn = new QPushButton("Show");
|
||||
|
||||
this->addingBtn = new QPushButton("Add");
|
||||
this->deletingBtn = new QPushButton("Delete");
|
||||
this->updatingBtn = new QPushButton("Update");
|
||||
|
||||
this->adminExitBtn = new QPushButton("Exit");
|
||||
this->addExitBtn = new QPushButton("Exit");
|
||||
this->deleteExitBtn = new QPushButton("Exit");
|
||||
this->updateExitBtn = new QPushButton("Exit");
|
||||
this->showExitBtn = new QPushButton("Exit");
|
||||
|
||||
this->addSize = new QLineEdit;
|
||||
this->addColour = new QLineEdit;
|
||||
this->addPrice = new QLineEdit;
|
||||
this->addQuantity = new QLineEdit;
|
||||
this->addPhotograph = new QLineEdit;
|
||||
|
||||
this->deleteSize = new QLineEdit;
|
||||
this->deleteColour = new QLineEdit;
|
||||
this->deletePhotograph = new QLineEdit;
|
||||
|
||||
this->updateSize = new QLineEdit;
|
||||
this->updateColour = new QLineEdit;
|
||||
this->updatePrice = new QLineEdit;
|
||||
this->updateQuantity = new QLineEdit;
|
||||
this->updatePhotograph = new QLineEdit;
|
||||
|
||||
this->addSizeLabel = new QLabel("Size:");
|
||||
this->addColourLabel = new QLabel("Colour:");
|
||||
this->addPriceLabel = new QLabel("Price:");
|
||||
this->addQuantityLabel = new QLabel("Quantity:");
|
||||
this->addPhotographLabel = new QLabel("Photograph:");
|
||||
|
||||
this->deleteSizeLabel = new QLabel("Size:");
|
||||
this->deleteColourLabel = new QLabel("Colour:");
|
||||
this->deletePhotographLabel = new QLabel("Photograph:");
|
||||
|
||||
this->updateSizeLabel = new QLabel("Size:");
|
||||
this->updateColourLabel = new QLabel("Colour:");
|
||||
this->updatePriceLabel = new QLabel("Price: (leave empty to not update)");
|
||||
this->updateQuantityLabel = new QLabel("Quantity: (leave empty to not update)");
|
||||
this->updatePhotographLabel = new QLabel("Photograph:");
|
||||
|
||||
this->addSizeLabel->setBuddy(this->addSize);
|
||||
this->addColourLabel->setBuddy(this->addColour);
|
||||
this->addPriceLabel->setBuddy(this->addPrice);
|
||||
this->addQuantityLabel->setBuddy(this->addQuantity);
|
||||
this->addPhotographLabel->setBuddy(this->addPhotograph);
|
||||
|
||||
this->deleteSizeLabel->setBuddy(this->deleteSize);
|
||||
this->deleteColourLabel->setBuddy(this->deleteColour);
|
||||
this->deletePhotographLabel->setBuddy(this->deletePhotograph);
|
||||
|
||||
this->updateSizeLabel->setBuddy(this->updateSize);
|
||||
this->updateColourLabel->setBuddy(this->updateColour);
|
||||
this->updatePriceLabel->setBuddy(this->updatePrice);
|
||||
this->updateQuantityLabel->setBuddy(this->updateQuantity);
|
||||
this->updatePhotographLabel->setBuddy(this->updatePhotograph);
|
||||
|
||||
|
||||
this->repoSelectorLayout->addWidget(this->CSVBtn);
|
||||
this->repoSelectorLayout->addWidget(this->HTMLBtn);
|
||||
this->repoSelector->setLayout(this->repoSelectorLayout);
|
||||
|
||||
this->mainMenuLayout->addWidget(this->adminBtn);
|
||||
this->mainMenuLayout->addWidget(this->userBtn);
|
||||
this->mainMenu->setLayout(this->mainMenuLayout);
|
||||
|
||||
this->adminMenuLayout->addWidget(this->addBtn);
|
||||
this->adminMenuLayout->addWidget(this->deleteBtn);
|
||||
this->adminMenuLayout->addWidget(this->updateBtn);
|
||||
this->adminMenuLayout->addWidget(this->showBtn);
|
||||
this->adminMenuLayout->addWidget(this->adminExitBtn);
|
||||
this->adminMenu->setLayout(this->adminMenuLayout);
|
||||
|
||||
this->addMenuLayout->addRow(this->addSizeLabel, this->addSize);
|
||||
this->addMenuLayout->addRow(this->addColourLabel, this->addColour);
|
||||
this->addMenuLayout->addRow(this->addPriceLabel, this->addPrice);
|
||||
this->addMenuLayout->addRow(this->addQuantityLabel, this->addQuantity);
|
||||
this->addMenuLayout->addRow(this->addPhotographLabel, this->addPhotograph);
|
||||
this->addMenuLayout->addWidget(this->addingBtn);
|
||||
this->addMenuLayout->addWidget(this->addExitBtn);
|
||||
this->addMenu->setLayout(this->addMenuLayout);
|
||||
|
||||
this->deleteMenuLayout->addRow(this->deleteSizeLabel, this->deleteSize);
|
||||
this->deleteMenuLayout->addRow(this->deleteColourLabel, this->deleteColour);
|
||||
this->deleteMenuLayout->addRow(this->deletePhotographLabel, this->deletePhotograph);
|
||||
this->deleteMenuLayout->addWidget(this->deletingBtn);
|
||||
this->deleteMenuLayout->addWidget(this->deleteExitBtn);
|
||||
this->deleteMenu->setLayout(this->deleteMenuLayout);
|
||||
|
||||
this->updateMenuLayout->addRow(this->updateSizeLabel, this->updateSize);
|
||||
this->updateMenuLayout->addRow(this->updateColourLabel, this->updateColour);
|
||||
this->updateMenuLayout->addRow(this->updatePriceLabel, this->updatePrice);
|
||||
this->updateMenuLayout->addRow(this->updateQuantityLabel, this->updateQuantity);
|
||||
this->updateMenuLayout->addRow(this->updatePhotographLabel, this->updatePhotograph);
|
||||
this->updateMenuLayout->addWidget(this->updatingBtn);
|
||||
this->updateMenuLayout->addWidget(this->updateExitBtn);
|
||||
this->updateMenu->setLayout(this->updateMenuLayout);
|
||||
|
||||
this->table = new QTableWidget(0,5);
|
||||
this->table->setHorizontalHeaderLabels(QStringList{ "Size","Colour","Price","Quantity","Photograph" });
|
||||
this->table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
||||
this->showMenuLayout->addWidget(this->table);
|
||||
this->showMenuLayout->addWidget(this->showExitBtn);
|
||||
this->showMenu->setLayout(this->showMenuLayout);
|
||||
|
||||
QObject::connect(this->CSVBtn, &QPushButton::clicked, [&]() {
|
||||
std::shared_ptr<FileRepository> repo = std::make_shared<CSVRepository>("repo.csv",true);
|
||||
std::shared_ptr<FileRepository> shoppingRepo = std::make_shared<CSVRepository>("shoppingRepo.csv");
|
||||
this->adminController = std::make_unique<AdminController>(repo);
|
||||
this->userController = std::make_unique<UserController>(repo,shoppingRepo);
|
||||
this->repoSelector->hide();
|
||||
this->mainMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->HTMLBtn, &QPushButton::clicked, [&]() {
|
||||
std::shared_ptr<FileRepository> repo = std::make_shared<CSVRepository>("repo.csv",true);
|
||||
std::shared_ptr<FileRepository> shoppingRepo = std::make_shared<HTMLRepository>("shoppingRepo.html");
|
||||
this->adminController = std::make_unique<AdminController>(repo);
|
||||
this->userController = std::make_unique<UserController>(repo,shoppingRepo);
|
||||
this->repoSelector->hide();
|
||||
this->mainMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->adminBtn, &QPushButton::clicked, [&]() {
|
||||
this->mainMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->userBtn, &QPushButton::clicked, [&]() {
|
||||
this->mainMenu->hide();
|
||||
this->userMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->adminExitBtn, &QPushButton::clicked, [&]() {
|
||||
this->adminMenu->hide();
|
||||
this->mainMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->addBtn, &QPushButton::clicked, [&]() {
|
||||
this->adminMenu->hide();
|
||||
this->addMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->deleteBtn, &QPushButton::clicked, [&]() {
|
||||
this->adminMenu->hide();
|
||||
this->deleteMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->updateBtn, &QPushButton::clicked, [&]() {
|
||||
this->adminMenu->hide();
|
||||
this->updateMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->showBtn, &QPushButton::clicked, [&]() {
|
||||
this->table->clear();
|
||||
this->table->setRowCount(0);
|
||||
this->table->setHorizontalHeaderLabels(QStringList{ "Size","Colour","Price","Quantity","Photograph" });
|
||||
for(auto item : *this->adminController->getAll())
|
||||
{
|
||||
this->table->insertRow(this->table->rowCount());
|
||||
this->table->setItem(this->table->rowCount() - 1, 0, new QTableWidgetItem(QString::number(item.size())));
|
||||
this->table->setItem(this->table->rowCount() - 1, 1, new QTableWidgetItem(QString::fromStdString(item.colour())));
|
||||
this->table->setItem(this->table->rowCount() - 1, 2, new QTableWidgetItem(QString::number(item.price())));
|
||||
this->table->setItem(this->table->rowCount() - 1, 3, new QTableWidgetItem(QString::number(item.quantity())));
|
||||
this->table->setItem(this->table->rowCount() - 1, 4, new QTableWidgetItem(QString::fromStdString(item.photograph())));
|
||||
}
|
||||
this->adminMenu->hide();
|
||||
this->showMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->addExitBtn, &QPushButton::clicked, [&]() {
|
||||
this->addMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->deleteExitBtn, &QPushButton::clicked, [&]() {
|
||||
this->deleteMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->updateExitBtn, &QPushButton::clicked, [&]() {
|
||||
this->updateMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->showExitBtn, &QPushButton::clicked, [&]() {
|
||||
this->showMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->addingBtn, &QPushButton::clicked, [&]() {
|
||||
try {
|
||||
Validator::validate_size(this->addSize->text().toStdString());
|
||||
Validator::validate_colour(this->addColour->text().toStdString());
|
||||
Validator::validate_price(this->addPrice->text().toStdString());
|
||||
Validator::validate_quantity(this->addQuantity->text().toStdString());
|
||||
Validator::validate_photograph(this->addPhotograph->text().toStdString());
|
||||
this->adminController->add(this->addSize->text().toInt(), this->addColour->text().toStdString(), this->addPrice->text().toInt(), this->addQuantity->text().toInt(), this->addPhotograph->text().toStdString());
|
||||
}
|
||||
catch (ValidatorException& e) {
|
||||
QMessageBox::critical(this->addMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (RepoException& e) {
|
||||
QMessageBox::critical(this->addMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (AdminControllerException& e) {
|
||||
QMessageBox::critical(this->addMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
this->addMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->deletingBtn, &QPushButton::clicked, [&]() {
|
||||
try {
|
||||
Validator::validate_size(this->deleteSize->text().toStdString());
|
||||
Validator::validate_colour(this->deleteColour->text().toStdString());
|
||||
Validator::validate_photograph(this->deletePhotograph->text().toStdString());
|
||||
this->adminController->remove(this->deleteSize->text().toInt(), this->deleteColour->text().toStdString(), this->deletePhotograph->text().toStdString());
|
||||
}
|
||||
catch (ValidatorException& e) {
|
||||
QMessageBox::critical(this->deleteMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (RepoException& e) {
|
||||
QMessageBox::critical(this->deleteMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (AdminControllerException& e) {
|
||||
QMessageBox::critical(this->deleteMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
this->deleteMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->updatingBtn, &QPushButton::clicked, [&]() {
|
||||
int _quantity = -1;
|
||||
int _price = -1;
|
||||
try {
|
||||
Validator::validate_size(this->updateSize->text().toStdString());
|
||||
Validator::validate_colour(this->updateColour->text().toStdString());
|
||||
Validator::validate_price(this->updatePrice->text().toStdString());
|
||||
Validator::validate_quantity(this->updateQuantity->text().toStdString());
|
||||
Validator::validate_photograph(this->updatePhotograph->text().toStdString());
|
||||
if(this->updatePrice->text().toStdString()!="")
|
||||
_price = this->updatePrice->text().toInt();
|
||||
if(this->updateQuantity->text().toStdString()!="")
|
||||
_quantity = this->updateQuantity->text().toInt();
|
||||
this->adminController->update(this->updateSize->text().toInt(), this->updateColour->text().toStdString(), this->updatePrice->text().toInt(), this->updateQuantity->text().toInt(), this->updatePhotograph->text().toStdString());
|
||||
}
|
||||
catch (ValidatorException& e) {
|
||||
QMessageBox::critical(this->updateMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (RepoException& e) {
|
||||
QMessageBox::critical(this->updateMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (AdminControllerException& e) {
|
||||
QMessageBox::critical(this->updateMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
this->updateMenu->hide();
|
||||
this->adminMenu->show();
|
||||
});
|
||||
|
||||
this->userShowMenu = new QWidget();
|
||||
this->userShowLayout = new QVBoxLayout();
|
||||
|
||||
this->showAllBtn = new QPushButton("Show by size");
|
||||
this->openBtn = new QPushButton("Open");
|
||||
this->exitUserBtn = new QPushButton("Exit");
|
||||
this->searchBtn = new QPushButton("Search");
|
||||
this->userSize = new QLineEdit();
|
||||
this->userSize->setPlaceholderText("Size");
|
||||
this->nextBtn = new QPushButton("Next");
|
||||
this->buyBtn = new QPushButton("Buy");
|
||||
this->exitBtn = new QPushButton("Exit");
|
||||
|
||||
this->userTable = new QStackedWidget();
|
||||
|
||||
|
||||
userMenuLayout->addWidget(this->showAllBtn);
|
||||
userMenuLayout->addWidget(this->openBtn);
|
||||
userMenuLayout->addWidget(this->exitUserBtn);
|
||||
|
||||
userMenu->setLayout(userMenuLayout);
|
||||
|
||||
QObject::connect(this->showAllBtn, &QPushButton::clicked, [&]() {
|
||||
this->userMenu->hide();
|
||||
this->userShowMenu->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->openBtn, &QPushButton::clicked, [&]() {
|
||||
this->userController->openShoppingList();
|
||||
});
|
||||
|
||||
QObject::connect(this->exitUserBtn, &QPushButton::clicked, [&]() {
|
||||
this->userMenu->hide();
|
||||
this->mainMenu->show();
|
||||
});
|
||||
|
||||
this->userTable->addWidget(new QLabel("No trench coats to show!"));
|
||||
this->userTable->addWidget(new QLabel("No !"));
|
||||
|
||||
userShowLayout->addWidget(this->userSize);
|
||||
userShowLayout->addWidget(this->searchBtn);
|
||||
userShowLayout->addWidget(this->userTable);
|
||||
userShowLayout->addWidget(this->nextBtn);
|
||||
userShowLayout->addWidget(this->buyBtn);
|
||||
userShowLayout->addWidget(this->exitBtn);
|
||||
|
||||
userShowMenu->setLayout(userShowLayout);
|
||||
|
||||
this->userSize->setValidator(new QIntValidator(0, 50));
|
||||
|
||||
QObject::connect(this->searchBtn, &QPushButton::clicked, [&]() {
|
||||
try {
|
||||
int size = -1;
|
||||
if (this->userSize->text().toStdString() != "")
|
||||
size = this->userSize->text().toInt();
|
||||
auto iterator = this->userController->getTrenchCarousel(size);
|
||||
if(iterator.size() == 0){
|
||||
QMessageBox::critical(this->userShowMenu, "Error", "No trench coats with the given size!");
|
||||
return;
|
||||
}
|
||||
this->userCoats = iterator;
|
||||
while(this->userTable->count() > 0)
|
||||
this->userTable->removeWidget(this->userTable->widget(0));
|
||||
for (auto& trench : iterator) {
|
||||
QWidget* widget = new QWidget();
|
||||
QHBoxLayout* layout = new QHBoxLayout();
|
||||
QLabel* sizeLabel = new QLabel(QString::fromStdString(std::to_string(trench.size())));
|
||||
QLabel* colourLabel = new QLabel(QString::fromStdString(trench.colour()));
|
||||
QLabel* priceLabel = new QLabel(QString::fromStdString(std::to_string(trench.price())));
|
||||
QLabel* quantityLabel = new QLabel(QString::fromStdString(std::to_string(trench.quantity())));
|
||||
QLabel* photographLabel = new QLabel(QString::fromStdString(trench.photograph()));
|
||||
layout->addWidget(sizeLabel);
|
||||
layout->addWidget(colourLabel);
|
||||
layout->addWidget(priceLabel);
|
||||
layout->addWidget(quantityLabel);
|
||||
layout->addWidget(photographLabel);
|
||||
widget->setLayout(layout);
|
||||
this->userTable->addWidget(widget);
|
||||
}
|
||||
this->userTable->setCurrentIndex(0);
|
||||
}
|
||||
catch (ValidatorException& e) {
|
||||
QMessageBox::critical(this->userShowMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
catch (RepoException& e) {
|
||||
QMessageBox::critical(this->userShowMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(this->nextBtn, &QPushButton::clicked, [&]() {
|
||||
if(this->userTable->count() == 0)
|
||||
return;
|
||||
int index = this->userTable->currentIndex();
|
||||
if(index == this->userTable->count() - 1)
|
||||
index = 0;
|
||||
else
|
||||
index++;
|
||||
this->userTable->setCurrentIndex(index);
|
||||
});
|
||||
|
||||
QObject::connect(this->buyBtn, &QPushButton::clicked, [&]() {
|
||||
if(this->userTable->count() == 0)
|
||||
return;
|
||||
int index = this->userTable->currentIndex();
|
||||
try {
|
||||
Trench trench = this->userCoats[index];
|
||||
this->userController->addProductToShoppingList(trench);
|
||||
QMessageBox::information(this->userShowMenu, "Info", "Product added to shopping list!");
|
||||
this->searchBtn->click();
|
||||
if(index == this->userTable->count() - 1)
|
||||
index = 0;
|
||||
this->userTable->setCurrentIndex(index);
|
||||
}
|
||||
catch (RepoException& e) {
|
||||
QMessageBox::critical(this->userShowMenu, "Error", QString::fromStdString(e.what()));
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(this->exitBtn, &QPushButton::clicked, [&]() {
|
||||
this->userShowMenu->hide();
|
||||
this->userMenu->show();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
GUI::~GUI()
|
||||
{
|
||||
delete repoSelector;
|
||||
delete mainMenu;
|
||||
delete adminMenu;
|
||||
delete userMenu;
|
||||
delete addMenu;
|
||||
delete deleteMenu;
|
||||
delete updateMenu;
|
||||
delete showMenu;
|
||||
delete userShowMenu;
|
||||
}
|
||||
|
||||
void GUI::run()
|
||||
{
|
||||
this->repoSelector->show();
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <QStackedWidget>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QMessageBox>
|
||||
#include "../controllers/admin_controller/admin_controller.h"
|
||||
#include "../controllers/user_controller/user_controller.h"
|
||||
#include "../repository/CSVRepository.h"
|
||||
#include "../repository/HTMLRepository.h"
|
||||
#include "../validator/validator.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
#include "../domain/trench.h"
|
||||
#include <memory>
|
||||
|
||||
class GUI
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<AdminController> adminController;
|
||||
std::shared_ptr<UserController> userController;
|
||||
QWidget* repoSelector;
|
||||
QWidget* mainMenu;
|
||||
|
||||
QWidget* adminMenu;
|
||||
QWidget* userMenu;
|
||||
|
||||
QWidget* addMenu;
|
||||
QWidget* deleteMenu;
|
||||
QWidget* updateMenu;
|
||||
QWidget* showMenu;
|
||||
|
||||
QTableWidget* table;
|
||||
|
||||
QVBoxLayout* repoSelectorLayout;
|
||||
QVBoxLayout* mainMenuLayout;
|
||||
QVBoxLayout* adminMenuLayout;
|
||||
QVBoxLayout* userMenuLayout;
|
||||
QFormLayout* addMenuLayout;
|
||||
QFormLayout* deleteMenuLayout;
|
||||
QFormLayout* updateMenuLayout;
|
||||
QVBoxLayout* showMenuLayout;
|
||||
|
||||
QPushButton* CSVBtn;
|
||||
QPushButton* HTMLBtn;
|
||||
|
||||
QPushButton* adminBtn;
|
||||
QPushButton* userBtn;
|
||||
|
||||
QPushButton* addBtn;
|
||||
QPushButton* deleteBtn;
|
||||
QPushButton* updateBtn;
|
||||
QPushButton* showBtn;
|
||||
|
||||
QPushButton* addingBtn;
|
||||
QPushButton* deletingBtn;
|
||||
QPushButton* updatingBtn;
|
||||
|
||||
QPushButton* adminExitBtn;
|
||||
QPushButton* addExitBtn;
|
||||
QPushButton* deleteExitBtn;
|
||||
QPushButton* updateExitBtn;
|
||||
QPushButton* showExitBtn;
|
||||
|
||||
QLineEdit* addSize;
|
||||
QLineEdit* addColour;
|
||||
QLineEdit* addPrice;
|
||||
QLineEdit* addQuantity;
|
||||
QLineEdit* addPhotograph;
|
||||
|
||||
QLineEdit* deleteSize;
|
||||
QLineEdit* deleteColour;
|
||||
QLineEdit* deletePhotograph;
|
||||
|
||||
QLineEdit* updateSize;
|
||||
QLineEdit* updateColour;
|
||||
QLineEdit* updatePrice;
|
||||
QLineEdit* updateQuantity;
|
||||
QLineEdit* updatePhotograph;
|
||||
|
||||
QLabel* addSizeLabel;
|
||||
QLabel* addColourLabel;
|
||||
QLabel* addPriceLabel;
|
||||
QLabel* addQuantityLabel;
|
||||
QLabel* addPhotographLabel;
|
||||
|
||||
QLabel* deleteSizeLabel;
|
||||
QLabel* deleteColourLabel;
|
||||
QLabel* deletePhotographLabel;
|
||||
|
||||
QLabel* updateSizeLabel;
|
||||
QLabel* updateColourLabel;
|
||||
QLabel* updatePriceLabel;
|
||||
QLabel* updateQuantityLabel;
|
||||
QLabel* updatePhotographLabel;
|
||||
|
||||
|
||||
QWidget* userShowMenu;
|
||||
|
||||
QPushButton* showAllBtn;
|
||||
QPushButton* openBtn;
|
||||
QPushButton* exitUserBtn;
|
||||
|
||||
QVBoxLayout* userShowLayout;
|
||||
|
||||
QPushButton* nextBtn;
|
||||
QPushButton* buyBtn;
|
||||
QPushButton* exitBtn;
|
||||
|
||||
QLineEdit* userSize;
|
||||
|
||||
QLabel* userSizeLabel;
|
||||
|
||||
QPushButton* searchBtn;
|
||||
|
||||
QStackedWidget* userTable;
|
||||
|
||||
std::vector<Trench> userCoats;
|
||||
|
||||
|
||||
public:
|
||||
GUI();
|
||||
~GUI();
|
||||
void run();
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "CSVRepository.h"
|
||||
|
||||
CSVRepository::CSVRepository(std::string fileName,bool loadOnStart){
|
||||
this->_fileName = fileName;
|
||||
if(loadOnStart)
|
||||
this->loadFromFile();
|
||||
}
|
||||
|
||||
CSVRepository::~CSVRepository(){
|
||||
this->saveToFile();
|
||||
}
|
||||
|
||||
void CSVRepository::loadFromFile(){
|
||||
std::ifstream file(this->_fileName);
|
||||
if(!file.is_open()){
|
||||
return;
|
||||
}
|
||||
|
||||
while(true){
|
||||
Trench trench;
|
||||
file >> trench;
|
||||
if(file.eof()){
|
||||
break;
|
||||
}
|
||||
this->_data.push_back(trench);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void CSVRepository::saveToFile(){
|
||||
std::ofstream file(this->_fileName);
|
||||
if(!file.is_open()){
|
||||
return;
|
||||
}
|
||||
for(auto trench : this->_data){
|
||||
file << trench;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void CSVRepository::open(){
|
||||
std::string command = "notepad.exe " + this->_fileName;
|
||||
system(command.c_str());
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "FileRepository.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
#include "../domain/trench.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
class CSVRepository : public FileRepository {
|
||||
private:
|
||||
std::string _fileName;
|
||||
void loadFromFile() override;
|
||||
void saveToFile() override;
|
||||
public:
|
||||
CSVRepository(std::string fileName,bool loadOnStart = false);
|
||||
~CSVRepository();
|
||||
void open() override;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "FileRepository.h"
|
||||
|
||||
void FileRepository::add(Trench trench){
|
||||
MemoryRepository::add(trench);
|
||||
this->saveToFile();
|
||||
}
|
||||
|
||||
void FileRepository::remove(int index){
|
||||
MemoryRepository::remove(index);
|
||||
this->saveToFile();
|
||||
}
|
||||
|
||||
void FileRepository::remove(Trench trench){
|
||||
MemoryRepository::remove(trench);
|
||||
this->saveToFile();
|
||||
}
|
||||
|
||||
void FileRepository::update(int index, int price, int quantity){
|
||||
MemoryRepository::update(index, price, quantity);
|
||||
this->saveToFile();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "MemoryRepository.h"
|
||||
#include "../domain/trench.h"
|
||||
#include <string>
|
||||
|
||||
class FileRepository : public MemoryRepository {
|
||||
protected:
|
||||
std::string _fileName;
|
||||
virtual void saveToFile()=0;
|
||||
virtual void loadFromFile()=0;
|
||||
|
||||
public:
|
||||
FileRepository() = default;
|
||||
~FileRepository() = default;
|
||||
virtual void add(Trench trench) override;
|
||||
virtual void remove(Trench trench) override;
|
||||
virtual void remove(int index) override;
|
||||
virtual void update(int index, int price, int quantity) override;
|
||||
virtual void open()=0;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "HTMLRepository.h"
|
||||
|
||||
|
||||
HTMLRepository::HTMLRepository(std::string fileName){
|
||||
this->_fileName = fileName;
|
||||
}
|
||||
|
||||
HTMLRepository::~HTMLRepository(){
|
||||
this->saveToFile();
|
||||
}
|
||||
|
||||
void HTMLRepository::saveToFile(){
|
||||
std::ofstream file(this->_fileName);
|
||||
if(!file.is_open()){
|
||||
return;
|
||||
}
|
||||
file << "<!DOCTYPE html><html><head><title>Shopping list</title></head><body><table border=\"1\"><tr><td>Size</td><td>Colour</td><td>Price</td><td>Quantity</td><td>Photograph Link</td><td>Photo</td></tr>";
|
||||
for(auto trench : this->_data){
|
||||
file << "<tr><td>" << trench.size() << "</td><td>" << trench.colour() << "</td><td>" << trench.price() << "</td><td>" << trench.quantity() << "</td><td>" << "<a href=\"" << trench.photograph() << "\">Link</a> " << "</td><td>" << "<img src=\"" << trench.photograph() << "\" width=100 height=100>" << "</td></tr>";
|
||||
}
|
||||
file << "</table></body></html>";
|
||||
file.close();
|
||||
}
|
||||
|
||||
void HTMLRepository::open(){
|
||||
std::string command = "start " + this->_fileName;
|
||||
system(command.c_str());
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "FileRepository.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
#include "../domain/trench.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
class HTMLRepository : public FileRepository {
|
||||
private:
|
||||
std::string _fileName;
|
||||
void loadFromFile(){};
|
||||
void saveToFile() override;
|
||||
public:
|
||||
HTMLRepository(std::string fileName);
|
||||
~HTMLRepository();
|
||||
void open() override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "MemoryRepository.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
|
||||
MemoryRepository::MemoryRepository(){
|
||||
|
||||
}
|
||||
MemoryRepository::~MemoryRepository(){
|
||||
|
||||
}
|
||||
void MemoryRepository::add(Trench trench){
|
||||
if(this->get(trench)!=-1)
|
||||
throw RepoException("Trench already exists");
|
||||
this->_data.push_back(trench);
|
||||
|
||||
}
|
||||
void MemoryRepository::remove(Trench trench){
|
||||
int index = this->get(trench);
|
||||
if(index==-1)
|
||||
throw RepoException("Trench does not exists");
|
||||
this->remove(index);
|
||||
}
|
||||
void MemoryRepository::remove(int index){
|
||||
if(index<0 || index > (int)(this->_data.size())-1)
|
||||
throw RepoException("Index out of bounds");
|
||||
this->_data.erase(this->_data.begin()+index);
|
||||
}
|
||||
|
||||
int MemoryRepository::get(Trench trench){
|
||||
for(int i=0;i<(int)(this->_data.size());i++){
|
||||
if(trench == this->_data[i])
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Trench& MemoryRepository::operator[](int index){
|
||||
if(index<0 || index > (int)(this->_data.size())-1)
|
||||
throw RepoException("Index out of bounds");
|
||||
return this->_data[index];
|
||||
}
|
||||
void MemoryRepository::update(int index, int price, int quantity){
|
||||
if(index<0 || index > (int)(this->_data.size())-1)
|
||||
throw RepoException("Index out of bounds");
|
||||
Trench& trench = this->_data[index];
|
||||
if(price!=-1 && price<=0)
|
||||
throw RepoException("Invalid price");
|
||||
if(quantity!=-1 && quantity<0)
|
||||
throw RepoException("Invalid quantity");
|
||||
if(price>0)
|
||||
trench.price(price);
|
||||
if(quantity>=0)
|
||||
trench.quantity(quantity);
|
||||
}
|
||||
|
||||
int MemoryRepository::size(){
|
||||
return this->_data.size();
|
||||
}
|
||||
|
||||
std::vector<Trench>::iterator MemoryRepository::begin(){
|
||||
return this->_data.begin();
|
||||
}
|
||||
std::vector<Trench>::iterator MemoryRepository::end(){
|
||||
return this->_data.end();
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
#include "../domain/trench.h"
|
||||
#include <vector>
|
||||
#include "Repository.h"
|
||||
|
||||
class MemoryRepository : public Repository {
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
* Constructor for the Repository class
|
||||
* Input: -
|
||||
* Output: repository object
|
||||
*/
|
||||
MemoryRepository();
|
||||
|
||||
/*
|
||||
* Destructor for the Repository class
|
||||
* Input: -
|
||||
* Output: -
|
||||
*/
|
||||
~MemoryRepository();
|
||||
|
||||
/*
|
||||
* Adds a trench to the repository
|
||||
* Input: trench - trench object
|
||||
* Output: -
|
||||
* Throws: RepoException if trench already exists
|
||||
*/
|
||||
void add(Trench trench) override;
|
||||
|
||||
/*
|
||||
* Removes a trench from the repository
|
||||
* Input: trench - trench object
|
||||
* Output: -
|
||||
* Throws: RepoException if trench does not exist
|
||||
*/
|
||||
void remove(Trench trench) override;
|
||||
|
||||
/*
|
||||
* Removes a trench from the repository
|
||||
* Input: index - index of the trench
|
||||
* Output: -
|
||||
* Throws: RepoException if index is out of bounds
|
||||
*/
|
||||
void remove(int index) override;
|
||||
|
||||
/*
|
||||
* Returns the index of a trench in the repository
|
||||
* Input: trench - trench object
|
||||
* Output: index of the trench. -1 if trench does not exist
|
||||
*/
|
||||
int get(Trench trench) override;
|
||||
|
||||
/*
|
||||
* Returns a trench from the repository
|
||||
* Input: index - index of the trench
|
||||
* Output: trench object
|
||||
* Throws: RepoException if index is out of bounds
|
||||
*/
|
||||
Trench& operator[](int index) override;
|
||||
|
||||
/*
|
||||
* Updates a trench from the repository
|
||||
* Input: index - index of the trench
|
||||
* price - new price
|
||||
* quantity - new quantity
|
||||
* Output: -
|
||||
* Throws: RepoException if index is out of bounds
|
||||
*/
|
||||
void update(int index, int price, int quantity) override;
|
||||
|
||||
/*
|
||||
* Returns the size of the repository
|
||||
* Input: -
|
||||
* Output: size of the repository
|
||||
*/
|
||||
int size() override;
|
||||
|
||||
/*
|
||||
* Returns an iterator to the beginning of the repository
|
||||
* Input: -
|
||||
* Output: iterator to the beginning of the repository
|
||||
*/
|
||||
std::vector<Trench>::iterator begin() override;
|
||||
|
||||
/*
|
||||
* Returns an iterator to the end of the repository
|
||||
* Input: -
|
||||
* Output: iterator to the end of the repository
|
||||
*/
|
||||
std::vector<Trench>::iterator end() override;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "../domain/trench.h"
|
||||
#include <vector>
|
||||
|
||||
class Repository {
|
||||
protected:
|
||||
std::vector<Trench> _data;
|
||||
public:
|
||||
Repository() = default;
|
||||
~Repository() = default;
|
||||
virtual void add(Trench trench) = 0;
|
||||
virtual void remove(Trench trench) = 0;
|
||||
virtual void remove(int index) = 0;
|
||||
virtual int get(Trench trench) = 0;
|
||||
virtual Trench& operator[](int index) = 0;
|
||||
virtual void update(int index, int price, int quantity) = 0;
|
||||
virtual int size() = 0;
|
||||
virtual std::vector<Trench>::iterator begin() = 0;
|
||||
virtual std::vector<Trench>::iterator end() = 0;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,332 @@
|
||||
#include "ui.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
#include "../domain/trench.h"
|
||||
#include "../validator/validator.h"
|
||||
#include "../repository/Repository.h"
|
||||
#include "../repository/MemoryRepository.h"
|
||||
#include "../repository/CSVRepository.h"
|
||||
#include "../repository/HTMLRepository.h"
|
||||
#include "../controllers/admin_controller/admin_controller.h"
|
||||
#include "../controllers/user_controller/user_controller.h"
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
UI::UI(){
|
||||
std::shared_ptr<FileRepository> repo = std::make_shared<CSVRepository>("repo.csv",true);;
|
||||
std::shared_ptr<FileRepository> shoppingRepo;
|
||||
while(true){
|
||||
std::cout<<"1. CSV Repository"<<std::endl;
|
||||
std::cout<<"2. HTML Repository"<<std::endl;
|
||||
std::cout<<"Option: ";
|
||||
std::string buffer;
|
||||
getline(std::cin,buffer);
|
||||
if(buffer.length()!=1){
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
char option = buffer[0];
|
||||
switch(option){
|
||||
case '1':
|
||||
shoppingRepo = std::make_shared<CSVRepository>("shoppingRepo.csv");
|
||||
break;
|
||||
case '2':
|
||||
shoppingRepo = std::make_shared<HTMLRepository>("shoppingRepo.html");
|
||||
break;
|
||||
default:
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
this->_adminController = std::make_unique<AdminController>(repo);
|
||||
this->_userController = std::make_unique<UserController>(repo,shoppingRepo);
|
||||
}
|
||||
|
||||
|
||||
UI::~UI(){
|
||||
|
||||
}
|
||||
|
||||
void UI::run(){
|
||||
char option = 0;
|
||||
std::string buffer;
|
||||
while(1){
|
||||
std::cout<<"1. Run as admin"<<std::endl;
|
||||
std::cout<<"2. Run as user"<<std::endl;
|
||||
std::cout<<"3. Exit"<<std::endl;
|
||||
std::cout<<"Option: ";
|
||||
std::getline(std::cin,buffer);
|
||||
if(buffer.length()!=1){
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
option = buffer[0];
|
||||
switch(option){
|
||||
case '1':
|
||||
this->runAsAdmin();
|
||||
break;
|
||||
case '2':
|
||||
this->runAsUser();
|
||||
break;
|
||||
case '3':
|
||||
return;
|
||||
default:
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI::runAsAdmin(){
|
||||
char option = 0;
|
||||
std::string buffer;
|
||||
while(1){
|
||||
std::cout<<"1. Add trench"<<std::endl;
|
||||
std::cout<<"2. Remove trench"<<std::endl;
|
||||
std::cout<<"3. Update trench"<<std::endl;
|
||||
std::cout<<"4. List all trenches"<<std::endl;
|
||||
std::cout<<"5. Exit"<<std::endl;
|
||||
std::cout<<"Option: ";
|
||||
std::getline(std::cin,buffer);
|
||||
if(buffer.length()!=1){
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
option = buffer[0];
|
||||
switch(option){
|
||||
case '1':
|
||||
{
|
||||
try{
|
||||
std::string buffer;
|
||||
int size;
|
||||
std::string colour;
|
||||
int price;
|
||||
int quantity;
|
||||
std::string photograph;
|
||||
std::cout<<"Size: ";
|
||||
getline(std::cin,buffer);
|
||||
Validator::validate_size(buffer);
|
||||
size = std::stoi(buffer);
|
||||
std::cout<<"Colour: ";
|
||||
getline(std::cin,colour);
|
||||
Validator::validate_colour(colour);
|
||||
std::cout<<"Price: ";
|
||||
getline(std::cin,buffer);
|
||||
Validator::validate_price(buffer);
|
||||
price = std::stoi(buffer);
|
||||
std::cout<<"Quantity: ";
|
||||
getline(std::cin,buffer);
|
||||
Validator::validate_quantity(buffer);
|
||||
quantity = std::stoi(buffer);
|
||||
std::cout<<"Photograph: ";
|
||||
getline(std::cin,photograph);
|
||||
Validator::validate_photograph(photograph);
|
||||
this->_adminController->add(size,colour,price,quantity,photograph);
|
||||
std::cout<<"Trench added!"<<std::endl;
|
||||
}
|
||||
catch(ValidatorException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
catch(RepoException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
{
|
||||
try{
|
||||
std::string buffer;
|
||||
int size;
|
||||
std::string colour;
|
||||
std::string photograph;
|
||||
std::cout<<"Size: ";
|
||||
getline(std::cin,buffer);
|
||||
Validator::validate_size(buffer);
|
||||
size = std::stoi(buffer);
|
||||
std::cout<<"Colour: ";
|
||||
getline(std::cin,colour);
|
||||
Validator::validate_colour(colour);
|
||||
std::cout<<"Photograph: ";
|
||||
getline(std::cin,photograph);
|
||||
Validator::validate_photograph(photograph);
|
||||
this->_adminController->remove(size,colour,photograph);
|
||||
std::cout<<"Trench removed!"<<std::endl;
|
||||
}
|
||||
catch(ValidatorException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
catch(RepoException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
{
|
||||
try{
|
||||
std::string buffer;
|
||||
int size;
|
||||
std::string colour;
|
||||
int price;
|
||||
int quantity;
|
||||
std::string photograph;
|
||||
std::cout<<"Size: ";
|
||||
getline(std::cin,buffer);
|
||||
Validator::validate_size(buffer);
|
||||
size = std::stoi(buffer);
|
||||
std::cout<<"Colour: ";
|
||||
getline(std::cin,colour);
|
||||
Validator::validate_colour(colour);
|
||||
std::cout<<"Price: (type enter to not change it) ";
|
||||
getline(std::cin,buffer);
|
||||
if (buffer.length()!=0){
|
||||
Validator::validate_price(buffer);
|
||||
price = std::stoi(buffer);
|
||||
}
|
||||
else
|
||||
price = -1;
|
||||
std::cout<<"Quantity: (type enter to not change it) ";
|
||||
getline(std::cin,buffer);
|
||||
if (buffer.length()!=0){
|
||||
Validator::validate_quantity(buffer);
|
||||
quantity = std::stoi(buffer);
|
||||
}
|
||||
else
|
||||
quantity = -1;
|
||||
std::cout<<"Photograph: ";
|
||||
getline(std::cin,photograph);
|
||||
Validator::validate_photograph(photograph);
|
||||
this->_adminController->update(size,colour,price,quantity,photograph);
|
||||
std::cout<<"Trench updated!"<<std::endl;
|
||||
}
|
||||
catch(ValidatorException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
catch(RepoException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
catch(AdminControllerException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
for(Trench i:*this->_adminController->getAll()){
|
||||
std::cout<<i;
|
||||
}
|
||||
break;
|
||||
case '5':
|
||||
return;
|
||||
default:
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI::runAsUser(){
|
||||
char option;
|
||||
std::string buffer;
|
||||
while(1){
|
||||
std::cout<<"1. Show all trench coats in a given size"<<std::endl;
|
||||
std::cout<<"2. Show shopping cart"<<std::endl;
|
||||
std::cout<<"3. Exit"<<std::endl;
|
||||
std::cout<<"Option: ";
|
||||
std::getline(std::cin,buffer);
|
||||
if(buffer.length()!=1){
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
option = buffer[0];
|
||||
switch(option){
|
||||
case '1':
|
||||
{
|
||||
std::string buffer;
|
||||
int size;
|
||||
std::cout<<"Size: ";
|
||||
getline(std::cin,buffer);
|
||||
if (buffer.length()!=0){
|
||||
try{
|
||||
Validator::validate_size(buffer);
|
||||
}
|
||||
catch(ValidatorException& e){
|
||||
std::cout<<e.what()<<std::endl;
|
||||
continue;
|
||||
}
|
||||
size = std::stoi(buffer);
|
||||
}
|
||||
else
|
||||
size = -1;
|
||||
std::vector<Trench> iterator = this->_userController->getTrenchCarousel(size);
|
||||
if(iterator.size()==0){
|
||||
std::cout<<"No trench coats found!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
int exit = 1;
|
||||
int index = 0;
|
||||
while(exit && iterator.size()){
|
||||
Trench s = iterator[index];
|
||||
std::cout<< s << std::endl;
|
||||
std::cout<<"Total price: "<<this->_userController->shoppingListTotal()<<std::endl;
|
||||
char option;
|
||||
std::string buffer;
|
||||
std::cout<<"1. Add to shopping cart"<<std::endl;
|
||||
std::cout<<"2. Next trench coat"<<std::endl;
|
||||
std::cout<<"3. Exit"<<std::endl;
|
||||
std::cout<<"Option: ";
|
||||
std::getline(std::cin,buffer);
|
||||
if(buffer.length()!=1){
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
option = buffer[0];
|
||||
switch(option){
|
||||
case '1':
|
||||
{
|
||||
this->_userController->addProductToShoppingList(iterator[index]);
|
||||
iterator[index].quantity(iterator[index].quantity()-1);
|
||||
if (iterator[index].quantity() == 0){
|
||||
iterator.erase(iterator.begin()+index);
|
||||
if(index==(int)(iterator.size()))
|
||||
index=0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '2':
|
||||
{
|
||||
index++;
|
||||
if(index==(int)(iterator.size()))
|
||||
index=0;
|
||||
break;
|
||||
}
|
||||
case '3':
|
||||
{
|
||||
exit=0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
std::cout<<"Invalid option!"<<std::endl;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '2':
|
||||
{
|
||||
this->_userController->openShoppingList();
|
||||
}
|
||||
|
||||
case '3':
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "../controllers/admin_controller/admin_controller.h"
|
||||
#include "../controllers/user_controller/user_controller.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
class UI {
|
||||
private:
|
||||
std::unique_ptr<AdminController> _adminController;
|
||||
std::unique_ptr<UserController> _userController;
|
||||
public:
|
||||
UI();
|
||||
~UI();
|
||||
void run();
|
||||
void runAsAdmin();
|
||||
void runAsUser();
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "validator.h"
|
||||
#include "../exceptions/exceptions.h"
|
||||
|
||||
void Validator::validate_size(const std::string& size) {
|
||||
if (size.length() == 0) {
|
||||
throw ValidatorException("Invalid size!");
|
||||
}
|
||||
for(size_t i=0;i<size.length();i++){
|
||||
if(size[i]<'0' || size[i]>'9'){
|
||||
throw ValidatorException("Invalid size!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (std::stoi(size) <= 0) {
|
||||
throw ValidatorException("Invalid size!");
|
||||
}
|
||||
}
|
||||
|
||||
void Validator::validate_colour(const std::string& colour) {
|
||||
if (colour.length() == 0) {
|
||||
throw ValidatorException("Invalid colour!");
|
||||
}
|
||||
}
|
||||
|
||||
void Validator::validate_price(const std::string& price) {
|
||||
if (price.length() == 0) {
|
||||
throw ValidatorException("Invalid price!");
|
||||
}
|
||||
for(size_t i=0;i<price.length();i++){
|
||||
if(price[i]<'0' || price[i]>'9'){
|
||||
throw ValidatorException("Invalid price!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (std::stoi(price) <= 0) {
|
||||
throw ValidatorException("Invalid price!");
|
||||
}
|
||||
}
|
||||
|
||||
void Validator::validate_quantity(const std::string& quantity) {
|
||||
if (quantity.length() == 0) {
|
||||
throw ValidatorException("Invalid quantity!");
|
||||
}
|
||||
for(size_t i=0;i<quantity.length();i++){
|
||||
if(quantity[i]<'0' || quantity[i]>'9'){
|
||||
throw ValidatorException("Invalid quantity!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (std::stoi(quantity) < 0) {
|
||||
throw ValidatorException("Invalid quantity!");
|
||||
}
|
||||
}
|
||||
|
||||
void Validator::validate_photograph(const std::string& photograph) {
|
||||
if (photograph.length() == 0) {
|
||||
throw ValidatorException("Invalid photograph!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Validator {
|
||||
private:
|
||||
Validator()=default;
|
||||
public:
|
||||
static void validate_size(const std::string& size);
|
||||
static void validate_colour(const std::string& colour);
|
||||
static void validate_price(const std::string& price);
|
||||
static void validate_quantity(const std::string& quantity);
|
||||
static void validate_photograph(const std::string& photograph);
|
||||
};
|
||||
Reference in New Issue
Block a user