(Project) Daniel Cujba 1 2 2 19 48 SoftwareIdeasModeler.Core.Diagrams.UmlDiagrams.UmlPackageDiagram 1 SoftwareIdeasModeler.Core.Diagrams.UmlDiagrams.UmlClassDiagram 1 Daniel Cujba #00000000 Daniel Cujba #00000000 05/07/2023 14:06:49 01/01/0001 00:00:00 0 05/07/2023 14:07:04 01/01/0001 00:00:00 0 create destroy create create

/*

* Constructor for the UserController class

* Input: repo - Repository object

* Output: userController object

destroy

/*

* Destructor for the UserController class

* Input: -

* Output: -

/*

* Adds a trench coat to the shopping list

* Input: trench - Trench object

* Output: -

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);

/*

* Returns the total price of the shopping list

* Input: -

* Output: total - integer

int total = 0; for(Trench i : *this->_shoppingRepository) { total+=i.quantity()*i.price(); } return total;

/*

* Returns a vector of trench coats that are in the shopping list

* Input: size - integer

* Output: trenchCarousel - vector

object

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;
this->_shoppingRepository->open();
create destroy 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(); std::string command = "xdg-open " + this->_fileName + " > /dev/null 2>&1"; system(command.c_str()); destroy MemoryRepository::add(trench); this->saveToFile(); MemoryRepository::remove(index); this->saveToFile(); MemoryRepository::remove(trench); this->saveToFile(); MemoryRepository::update(index, price, quantity); this->saveToFile(); create create 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!"); } if (colour.length() == 0) { throw ValidatorException("Invalid colour!"); } 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!"); } 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!"); } if (photograph.length() == 0) { throw ValidatorException("Invalid photograph!"); } operator

/*

* Returns the trench coat at the given index

* Input: index - integer

* Output: trench coat - Trench object

* Throws: RepoException if: index is out of bounds

/*

* Returns an iterator for all the trench coats in the repository

* Input: -

* Output: iterator

create destroy 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();
destroy operator destroy

/*

* 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

operator operator operator
create destroy 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:05 05/07/2023 15:22:46 0
05/07/2023 14:07:04 05/07/2023 14:07:04 0