define api controller

This commit is contained in:
2026-01-29 20:07:54 -05:00
parent e0691bc7fe
commit 230771c7f9
4 changed files with 86 additions and 43 deletions

View File

@@ -59,9 +59,43 @@ public class ApiController { // SINGLETON
/* Update Customer List */ /* Update Customer List */
CustomerManager.getInstance().save(); CustomerManager.getInstance().save();
InventoryList customerCart = new InventoryList();
customerCart.add(InventoryManager.getInstance().INVENTORY.getFirst());
customerCart.add(InventoryManager.getInstance().INVENTORY.getLast());
enterTransaction(CustomerManager.getInstance().findByEmail("kate@museum.com"), customerCart);
} }
return new ResponseEntity<>("Resource loaded!", HttpStatus.OK); InventoryManager imgr = InventoryManager.getInstance();
return new ResponseEntity<>("Resource loaded! \n" + String.format("Art Pieces in INVENTORY: count %d", imgr.INVENTORY.size())
, HttpStatus.OK);
}
static void enterTransaction(Customer customer, InventoryList customerCart){
TransactionManager tmgr = TransactionManager.getInstance();
tmgr.load();
/*
* 3. Add a new transaction object to the list manager is handling
*/
Transaction tran = tmgr.TransactRequest(customer, customerCart);
/*
* 4. Calculate and return transaction price
* 5. Complete transaction
*/
tmgr.compute(tran);
tmgr.complete(tran);
/*
* 9. Update inventory file(s) on local system
*/
InventoryManager.getInstance().save();
/*
* 10. Update transaction file(s) on local system
*/
TransactionManager.getInstance().save();
} }
static void callerInterface() { static void callerInterface() {
@@ -93,25 +127,10 @@ public class ApiController { // SINGLETON
return; return;
} }
CustomerManager cmgr = CustomerManager.getInstance(); Transaction tran = null;
Customer customer = cmgr.findByEmail("kate@museum.com"); TransactionManager tmgr = null;
InventoryList customerCart = new InventoryList();
customerCart.add(imgr.INVENTORY.getFirst());
customerCart.add(imgr.INVENTORY.getLast());
TransactionManager tmgr = TransactionManager.getInstance(); //* 6. Remove transaction object
tmgr.load();
/*
* 3. Add a new transaction object to the list manager is handling
*/
Transaction tran = tmgr.TransactRequest(customer, customerCart);
/*
* 4. Calculate and return transaction price
* 5. Complete transaction
* 6. Remove transaction object
*/
tmgr.compute(tran);
tmgr.complete(tran);
// tmgr.remove(tran); // tmgr.remove(tran);
/* /*
* 7. Format and return transaction data in print format * 7. Format and return transaction data in print format
@@ -121,6 +140,7 @@ public class ApiController { // SINGLETON
* 8. Retrieve and return transactions based on: * 8. Retrieve and return transactions based on:
* customer email * customer email
*/ */
Customer customer = CustomerManager.getInstance().findByEmail("kate@museum.com");
TransactionList foundTrans = tmgr.findByCustomerEmail(customer.getEmail()); TransactionList foundTrans = tmgr.findByCustomerEmail(customer.getEmail());
/* /*
* transaction date * transaction date
@@ -134,15 +154,6 @@ public class ApiController { // SINGLETON
* art id * art id
*/ */
foundTrans = tmgr.findByTransactionId(tran.getId()); foundTrans = tmgr.findByTransactionId(tran.getId());
/*
* 9. Update inventory file(s) on local system
*/
InventoryManager.getInstance().save();
/*
* 10. Update transaction file(s) on local system
*/
TransactionManager.getInstance().save();
} }
static Drawing make(Drawing o) { static Drawing make(Drawing o) {

View File

@@ -1,21 +1,21 @@
[ [
{ {
"email": "kate@museum.com", "email": "kate@museum.com",
"id": "2020281777", "id": "3138660874",
"nameFirst": "Kate", "nameFirst": "Kate",
"nameLast": "Demsey", "nameLast": "Demsey",
"phone": "310-676-4844" "phone": "310-676-4844"
}, },
{ {
"email": "jim@homedeco.com", "email": "jim@homedeco.com",
"id": "5261329301", "id": "2183321125",
"nameFirst": "Jim", "nameFirst": "Jim",
"nameLast": "Gumbly", "nameLast": "Gumbly",
"phone": "203-676-4844" "phone": "203-676-4844"
}, },
{ {
"email": "evan@homedeco.com", "email": "evan@homedeco.com",
"id": "4961460829", "id": "5208154740",
"nameFirst": "Evan", "nameFirst": "Evan",
"nameLast": "Hao", "nameLast": "Hao",
"phone": "203-676-8943" "phone": "203-676-8943"

View File

@@ -2,9 +2,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.628880822-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "3215738680", "id": "2679997537",
"price": 92.0, "price": 92.0,
"title": "Windy Rowing", "title": "Windy Rowing",
"type": "DRAWING" "type": "DRAWING"
@@ -12,9 +12,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.628927081-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "5150484617", "id": "3264962183",
"price": 102.0, "price": 102.0,
"title": "Different day same thing", "title": "Different day same thing",
"type": "PRINT" "type": "PRINT"
@@ -22,9 +22,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.628966511-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "4279724246", "id": "4028811925",
"price": 51.0, "price": 51.0,
"title": "Walking by the beach.", "title": "Walking by the beach.",
"type": "PAINTING", "type": "PAINTING",
@@ -34,9 +34,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.628997921-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "2561610938", "id": "4044784693",
"price": 32.0, "price": 32.0,
"title": "Jolly Romp", "title": "Jolly Romp",
"type": "SCULPTURE", "type": "SCULPTURE",
@@ -45,9 +45,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.629066491-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "3819887576", "id": "1288927655",
"price": 32.0, "price": 32.0,
"title": "Jolly Romp", "title": "Jolly Romp",
"type": "SCULPTURE", "type": "SCULPTURE",
@@ -56,9 +56,9 @@
{ {
"Author": "Dave Janson", "Author": "Dave Janson",
"author": "Dave Janson", "author": "Dave Janson",
"created": "2026-01-28T18:21:41.62908951-05:00[America/New_York]", "created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.", "description": "East Market Square find. Local Author.",
"id": "4329655027", "id": "3852318757",
"price": 32.0, "price": 32.0,
"title": "Jolly Romp", "title": "Jolly Romp",
"type": "SCULPTURE", "type": "SCULPTURE",

View File

@@ -0,0 +1,32 @@
[
{
"completed": "2026-01-29T20:03:27.6062321-05:00[America/New_York]",
"created": "2026-01-29T20:03:27.6062321-05:00[America/New_York]",
"customerId": "3138660874",
"customerInventoryList": [
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "2679997537",
"price": 92.0,
"title": "Windy Rowing",
"type": "DRAWING"
},
{
"Author": "Dave Janson",
"author": "Dave Janson",
"created": "2026-01-29T20:03:27.5385961-05:00[America/New_York]",
"description": "East Market Square find. Local Author.",
"id": "3852318757",
"price": 32.0,
"title": "Jolly Romp",
"type": "SCULPTURE",
"weight": 4.0
}
],
"id": "ZcXUQAck4PPQiN-Qmeowsw",
"totalPrice": 124.8
}
]