* Throws: RepoException if: index is out of bounds
/*
* Returns an iterator for all the trench coats in the repository
* Input: -
* Output: iterator
createdestroy
Trench trench(size,colour,price,quantity,photograph);
this->_repo->add(trench);
Trench trench(size,colour,0,0,photograph);
this->_repo->remove(trench);
this->_repo->remove(index);
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);
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;
return this->_repo->size();
destroyoperatordestroy
/*
* Destructor for the Repository class
* Input: -
* Output: -
create
/*
* Constructor for the Trench class
* Input: size - integer
* colour - string
* price - integer
* quantity - integer
* photograph - string
* Output: trench object
destroy
/*
* Destructor for the Trench class
* Input: -
* Output: -
create
/*
* Copy constructor for the Trench class
* Input: trench - trench object
* Output: trench object
operator
/*
* Overload of the = operator
* Input: trench - trench object
* Output: trench object
/*
* Getter for the size attribute
* Input: -
* Output: size - integer
/*
* Setter for the size attribute
* Input: newSize - integer
* Output: -
/*
* Getter for the colour attribute
* Input: -
* Output: colour - string
/*
* Setter for the colour attribute
* Input: newColour - string
* Output: -
/*
* Getter for the price attribute
* Input: -
* Output: price - integer
/*
* Setter for the price attribute
* Input: newPrice - integer
* Output: -
/*
* Getter for the quantity attribute
* Input: -
* Output: quantity - integer
/*
* Setter for the quantity attribute
* Input: newQuantity - integer
* Output: -
/*
* Getter for the photograph attribute
* Input: -
* Output: photograph - string
/*
* Setter for the photograph attribute
* Input: newPhotograph - string
* Output: -
operator
/*
* Overload of the == operator
* Input: trench - trench object
* Output: true - if the trench objects are the same
* false - otherwise
operatoroperatoroperatorcreatedestroy
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;
}
}
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;
}
}
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;
}
}
}
05/07/2023 14:07:0505/07/2023 15:22:46005/07/2023 14:07:0405/07/2023 14:07:040