Updates
This commit is contained in:
@@ -86,7 +86,7 @@ public interface Api {
|
|||||||
customerCart.add(imgr.INVENTORY.getLast());
|
customerCart.add(imgr.INVENTORY.getLast());
|
||||||
|
|
||||||
TransactionManager tmgr = TransactionManager.getInstance();
|
TransactionManager tmgr = TransactionManager.getInstance();
|
||||||
|
tmgr.load();
|
||||||
/*
|
/*
|
||||||
* 3. Add a new transaction object to the list manager is handling
|
* 3. Add a new transaction object to the list manager is handling
|
||||||
*/
|
*/
|
||||||
@@ -98,7 +98,7 @@ public interface Api {
|
|||||||
*/
|
*/
|
||||||
tmgr.compute(tran);
|
tmgr.compute(tran);
|
||||||
tmgr.complete(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
|
||||||
*/
|
*/
|
||||||
@@ -135,6 +135,7 @@ public interface Api {
|
|||||||
o.setTitle("Windy Rowing");
|
o.setTitle("Windy Rowing");
|
||||||
o.setDescription("East Market Square find. Local Author.");
|
o.setDescription("East Market Square find. Local Author.");
|
||||||
o.setAuthor("Dave Janson");
|
o.setAuthor("Dave Janson");
|
||||||
|
o.setPrice(92.0f);
|
||||||
o.setCreated(ZonedDateTime.now());
|
o.setCreated(ZonedDateTime.now());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@@ -143,6 +144,7 @@ public interface Api {
|
|||||||
o.setTitle("Walking by the beach.");
|
o.setTitle("Walking by the beach.");
|
||||||
o.setDescription("East Market Square find. Local Author.");
|
o.setDescription("East Market Square find. Local Author.");
|
||||||
o.setAuthor("Dave Janson");
|
o.setAuthor("Dave Janson");
|
||||||
|
o.setPrice(51.0f);
|
||||||
o.setCreated(ZonedDateTime.now());
|
o.setCreated(ZonedDateTime.now());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@@ -151,7 +153,7 @@ public interface Api {
|
|||||||
o.setTitle("Different day same thing");
|
o.setTitle("Different day same thing");
|
||||||
o.setDescription("East Market Square find. Local Author.");
|
o.setDescription("East Market Square find. Local Author.");
|
||||||
o.setAuthor("Dave Janson");
|
o.setAuthor("Dave Janson");
|
||||||
|
o.setPrice(102.0f);
|
||||||
o.setCreated(ZonedDateTime.now());
|
o.setCreated(ZonedDateTime.now());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@@ -160,7 +162,8 @@ public interface Api {
|
|||||||
o.setTitle("Jolly Romp");
|
o.setTitle("Jolly Romp");
|
||||||
o.setDescription("East Market Square find. Local Author.");
|
o.setDescription("East Market Square find. Local Author.");
|
||||||
o.setAuthor("Dave Janson");
|
o.setAuthor("Dave Janson");
|
||||||
|
o.setPrice(32.0f);
|
||||||
|
o.setWeight(4.0F);
|
||||||
o.setCreated(ZonedDateTime.now());
|
o.setCreated(ZonedDateTime.now());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|||||||
22
Api/src/resources/db/inventory.json
Normal file
22
Api/src/resources/db/inventory.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"Author": "Dave Janson",
|
||||||
|
"author": "Dave Janson",
|
||||||
|
"created": "2025-10-30T13:47:16.4766896-04:00[America/New_York]",
|
||||||
|
"description": "East Market Square find. Local Author.",
|
||||||
|
"id": "1829220534",
|
||||||
|
"price": 92.0,
|
||||||
|
"title": "Windy Rowing",
|
||||||
|
"type": "DRAWING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Author": "Dave Janson",
|
||||||
|
"author": "Dave Janson",
|
||||||
|
"created": "2025-10-30T13:47:16.4776889-04:00[America/New_York]",
|
||||||
|
"description": "East Market Square find. Local Author.",
|
||||||
|
"id": "3269813598",
|
||||||
|
"price": 102.0,
|
||||||
|
"title": "Different day same thing",
|
||||||
|
"type": "PRINT"
|
||||||
|
}
|
||||||
|
]
|
||||||
31
Api/src/resources/db/transactions.json
Normal file
31
Api/src/resources/db/transactions.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"completed": "2025-10-30T13:55:22.069972-04:00[America/New_York]",
|
||||||
|
"created": "2025-10-30T13:55:22.069972-04:00[America/New_York]",
|
||||||
|
"customerId": "4659170390",
|
||||||
|
"customerInventoryList": [
|
||||||
|
{
|
||||||
|
"Author": "Dave Janson",
|
||||||
|
"author": "Dave Janson",
|
||||||
|
"created": "2025-10-30T13:47:16.4766896-04:00[America/New_York]",
|
||||||
|
"description": "East Market Square find. Local Author.",
|
||||||
|
"id": "1829220534",
|
||||||
|
"price": 92.0,
|
||||||
|
"title": "Windy Rowing",
|
||||||
|
"type": "DRAWING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Author": "Dave Janson",
|
||||||
|
"author": "Dave Janson",
|
||||||
|
"created": "2025-10-30T13:47:16.4776889-04:00[America/New_York]",
|
||||||
|
"description": "East Market Square find. Local Author.",
|
||||||
|
"id": "3269813598",
|
||||||
|
"price": 102.0,
|
||||||
|
"title": "Different day same thing",
|
||||||
|
"type": "PRINT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "h3kaUzeDU8llUhCPsdPacg",
|
||||||
|
"totalPrice": 194.0
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -66,7 +66,11 @@ public class DataRepository {
|
|||||||
read(manager, path);
|
read(manager, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WalkFileSystemTree(final TransactionManager manager) throws IOException {
|
public static void WalkFileSystemTree(final TransactionManager manager) throws JsonException, IOException, Exception {
|
||||||
|
String dataRoot = getRepositoryConfig.getPath();
|
||||||
|
dataRoot = dataRoot + "/transactions.json";
|
||||||
|
Path path = Paths.get(dataRoot);
|
||||||
|
read(manager, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void serialize_deserialize() {
|
static void serialize_deserialize() {
|
||||||
@@ -129,6 +133,21 @@ public class DataRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void write(TransactionManager mgr) throws IOException {
|
||||||
|
JsonbConfig config = new JsonbConfig()
|
||||||
|
.withFormatting(true); // Enable pretty-printing
|
||||||
|
Jsonb jsonb = JsonbBuilder.create(config);
|
||||||
|
String result = jsonb.toJson(mgr.TRANSACTIONS);
|
||||||
|
|
||||||
|
String dataRoot = getRepositoryConfig.getPath();
|
||||||
|
dataRoot = dataRoot + "/transactions.json";
|
||||||
|
Path path = Paths.get(dataRoot);
|
||||||
|
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
||||||
|
writer.write(result);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void read(CustomerManager customerManager, Path path) throws Exception {
|
private static void read(CustomerManager customerManager, Path path) throws Exception {
|
||||||
String result;
|
String result;
|
||||||
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))) {
|
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))) {
|
||||||
@@ -141,7 +160,19 @@ public class DataRepository {
|
|||||||
customerManager.CUSTOMERS.addAll(customers);
|
customerManager.CUSTOMERS.addAll(customers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void read(InventoryManager manager, Path path) throws JsonException, IOException, Exception {
|
private static void read(TransactionManager manager, Path path) throws Exception {
|
||||||
|
String result;
|
||||||
|
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))) {
|
||||||
|
result = in.readAllAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Transaction> transactions = mapJsonToObjectList(result, Transaction.class);
|
||||||
|
|
||||||
|
manager.TRANSACTIONS.clear();
|
||||||
|
manager.TRANSACTIONS.addAll(transactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read(InventoryManager manager, Path path) throws JsonException, IOException, InvalidRecordDataException, Exception {
|
||||||
String result;
|
String result;
|
||||||
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))) {
|
try (BufferedReader in = new BufferedReader(new FileReader(path.toFile(), StandardCharsets.UTF_8))) {
|
||||||
result = in.readAllAsString();
|
result = in.readAllAsString();
|
||||||
@@ -188,5 +219,4 @@ public class DataRepository {
|
|||||||
return home.replace('\\', '/') + "/workspace/inventorym/Api/src/resources/db";
|
return home.replace('\\', '/') + "/workspace/inventorym/Api/src/resources/db";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ public class Transaction {
|
|||||||
this.customerId = id;
|
this.customerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void check() throws InvalidTransactionException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class TransactionList extends ArrayList<Transaction> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(Transaction e) {
|
public boolean add(Transaction e) {
|
||||||
// TODO Auto-generated method stub
|
// TODO check transaction
|
||||||
return super.add(e);
|
return super.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package edu.inventorym.model;
|
package edu.inventorym.model;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
public class TransactionManager {
|
public class TransactionManager {
|
||||||
@@ -19,6 +21,7 @@ public class TransactionManager {
|
|||||||
public Transaction TransactRequest(Customer customer, InventoryList iPieces) {
|
public Transaction TransactRequest(Customer customer, InventoryList iPieces) {
|
||||||
Transaction transacted = new Transaction(customer, iPieces);
|
Transaction transacted = new Transaction(customer, iPieces);
|
||||||
transacted.setShipToAddress(customer.getMailing());
|
transacted.setShipToAddress(customer.getMailing());
|
||||||
|
add(transacted);
|
||||||
compute(transacted);
|
compute(transacted);
|
||||||
return transacted;
|
return transacted;
|
||||||
}
|
}
|
||||||
@@ -47,12 +50,31 @@ public class TransactionManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void add(Transaction tran) {
|
||||||
|
TRANSACTIONS.add(tran);
|
||||||
|
}
|
||||||
|
|
||||||
public void remove(Transaction tran) {
|
public void remove(Transaction tran) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
|
try {
|
||||||
|
DataRepository.write(this);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
try {
|
||||||
|
DataRepository.WalkFileSystemTree(this);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println(String.format("TRANSACTIONS: %s", e.getLocalizedMessage().toString()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user