mirror of
https://github.com/danog/WarehouseLibrary.git
synced 2024-12-04 02:08:02 +01:00
Fixes
This commit is contained in:
parent
a7de077ff7
commit
61ad7d089a
@ -18,7 +18,7 @@ package Main;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Studente
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class Cart extends Container {
|
public class Cart extends Container {
|
||||||
public Cart(String input) {
|
public Cart(String input) {
|
||||||
|
@ -19,8 +19,6 @@ package Main;
|
|||||||
import Payloads.RequestPayload;
|
import Payloads.RequestPayload;
|
||||||
import Payloads.ResponsePayload;
|
import Payloads.ResponsePayload;
|
||||||
import Payloads.ServerException;
|
import Payloads.ServerException;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -30,9 +28,9 @@ import java.net.Socket;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author root
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class Client implements ActionListener {
|
public class Client {
|
||||||
private BufferedWriter out;
|
private BufferedWriter out;
|
||||||
private BufferedReader in;
|
private BufferedReader in;
|
||||||
|
|
||||||
@ -70,7 +68,6 @@ public class Client implements ActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void commit() throws IOException, ServerException {
|
public void commit() throws IOException, ServerException {
|
||||||
|
|
||||||
RequestPayload request = new RequestPayload("POST", "/", cart.getPayload());
|
RequestPayload request = new RequestPayload("POST", "/", cart.getPayload());
|
||||||
request.shouldKeepAlive(true);
|
request.shouldKeepAlive(true);
|
||||||
request.write(out);
|
request.write(out);
|
||||||
@ -80,21 +77,7 @@ public class Client implements ActionListener {
|
|||||||
if (response.getResponseCode() != 200) {
|
if (response.getResponseCode() != 200) {
|
||||||
throw new ServerException(response);
|
throw new ServerException(response);
|
||||||
}
|
}
|
||||||
warehouse = new Warehouse(response.getPayload());
|
this.warehouse.rebuild(response.getPayload());
|
||||||
cart = new Cart();
|
this.cart.rebuild();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
System.out.println(e.paramString());
|
|
||||||
/* if (e.getText().equals("Buy")) {
|
|
||||||
try {
|
|
||||||
this.addToCart(Integer.parseInt(e.getActionCommand()));
|
|
||||||
} catch (ClientException ex) {
|
|
||||||
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package Main;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author root
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class ClientException extends Exception {
|
public class ClientException extends Exception {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import java.util.Hashtable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author root
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public abstract class Container
|
public abstract class Container
|
||||||
{
|
{
|
||||||
@ -32,6 +32,17 @@ public abstract class Container
|
|||||||
Constructors
|
Constructors
|
||||||
*/
|
*/
|
||||||
public Container(String response) {
|
public Container(String response) {
|
||||||
|
rebuild(response);
|
||||||
|
}
|
||||||
|
public Container() {
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rebuild() {
|
||||||
|
this.products.clear();
|
||||||
|
}
|
||||||
|
public void rebuild(String response) {
|
||||||
|
this.products.clear();
|
||||||
String[] split;
|
String[] split;
|
||||||
for (String line: response.split("\n")) {
|
for (String line: response.split("\n")) {
|
||||||
split = line.split(";");
|
split = line.split(";");
|
||||||
@ -48,11 +59,6 @@ public abstract class Container
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Container() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the string payload of the container
|
* Get the string payload of the container
|
||||||
* @return The string payload
|
* @return The string payload
|
||||||
|
@ -18,7 +18,7 @@ package Main;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Studente
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class Product {
|
public class Product {
|
||||||
private Double price;
|
private Double price;
|
||||||
|
@ -19,7 +19,7 @@ package Main;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author root
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class ProductCollection {
|
public class ProductCollection {
|
||||||
private final Product product;
|
private final Product product;
|
||||||
|
@ -18,7 +18,7 @@ package Main;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author root
|
* @author Daniil Gentili
|
||||||
*/
|
*/
|
||||||
public class Warehouse extends Container {
|
public class Warehouse extends Container {
|
||||||
public Warehouse(String input) {
|
public Warehouse(String input) {
|
||||||
|
Loading…
Reference in New Issue
Block a user