-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
68 lines (53 loc) · 3.22 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <memory>
#include "includes/catalog.h"
#include "includes/commands/command_types.h"
#include "../includes/commands/queries/check_store_product_quantity_query.h"
#include "../includes/commands/queries/get_product_description_query.h"
#include "../includes/commands/queries/create_product_query.h"
#include "../includes/commands/queries/update_product_description_query.h"
#include "../includes/commands/queries/update_product_name_query.h"
#include "../includes/commands/queries/update_product_price_query.h"
#include "../includes/commands/queries/update_product_supplier_id_query.h"
#include "includes/commands/command_factory.h"
#include "includes/location.h"
int main() {
Catalog mainCatalog;
Location warehouse(&mainCatalog);
auto printResponse = [](const CommandResponse& response) {
std::cout << (response.success ? "Success: " : "Fail: ") << response.message;
if (response.data.has_value()) {
const std::type_info& type = response.data.type();
if (type == typeid(int)) {
std::cout << ": " << std::any_cast<int>(response.data);
} else if (type == typeid(std::string)) {
std::cout << ": " << std::any_cast<std::string>(response.data);
} else {
std::cout << ": Unhandled data type";
}
}
std::cout << std::endl;
};
std::unique_ptr<CommandQuery> createQuery = std::make_unique<CreateProductQuery>("Product A", 1200.00, "Description of Product A", 1);
printResponse(warehouse.executeCommand(*createQuery));
int productId = 1;
std::unique_ptr<CommandQuery> getDescriptionQuery = std::make_unique<GetProductDescriptionQuery>(productId);
printResponse(warehouse.executeCommand(*getDescriptionQuery));
std::unique_ptr<CommandQuery> checkQuantityQuery = std::make_unique<CheckStoreProductQuantityQuery>(productId);
printResponse(warehouse.executeCommand(*checkQuantityQuery));
std::unique_ptr<CommandQuery> getNameQuery = std::make_unique<GetProductNameQuery>(productId);
printResponse(warehouse.executeCommand(*getNameQuery));
std::unique_ptr<CommandQuery> getPriceQuery = std::make_unique<GetProductPriceQuery>(productId);
printResponse(warehouse.executeCommand(*getPriceQuery));
std::unique_ptr<CommandQuery> getSupplierIdQuery = std::make_unique<GetProductSupplierIdQuery>(productId);
printResponse(warehouse.executeCommand(*getSupplierIdQuery));
std::unique_ptr<CommandQuery> updateDescriptionQuery = std::make_unique<UpdateProductDescriptionQuery>(productId, "New description for Product A");
printResponse(warehouse.executeCommand(*updateDescriptionQuery));
std::unique_ptr<CommandQuery> updateNameQuery = std::make_unique<UpdateProductNameQuery>(productId, "New Product Name A");
printResponse(warehouse.executeCommand(*updateNameQuery));
std::unique_ptr<CommandQuery> updatePriceQuery = std::make_unique<UpdateProductPriceQuery>(productId, 1300.00);
printResponse(warehouse.executeCommand(*updatePriceQuery));
std::unique_ptr<CommandQuery> updateSupplierIdQuery = std::make_unique<UpdateProductSupplierIdQuery>(productId, 2);
printResponse(warehouse.executeCommand(*updateSupplierIdQuery));
return 0;
}