Commit dc570b0f by Patryk Czarnik

Odczyt klienta i zamówienia SAOP

parent 5dcf2778
...@@ -54,7 +54,7 @@ public class CustomerDAO { ...@@ -54,7 +54,7 @@ public class CustomerDAO {
private Customer customerFromRS(ResultSet rs) throws SQLException { private Customer customerFromRS(ResultSet rs) throws SQLException {
return new Customer( return new Customer(
rs.getString("customer_email"), rs.getString("customer_email"),
rs.getString("name"), rs.getString("customer_name"),
rs.getString("phone_number"), rs.getString("phone_number"),
rs.getString("address"), rs.getString("address"),
rs.getString("postal_code"), rs.getString("postal_code"),
...@@ -64,7 +64,7 @@ public class CustomerDAO { ...@@ -64,7 +64,7 @@ public class CustomerDAO {
public void insert(Customer customer) throws DBException { public void insert(Customer customer) throws DBException {
// używać gdy obiekt ma wpisane ID (tu: email) // używać gdy obiekt ma wpisane ID (tu: email)
final String sql = "INSERT INTO customers(" final String sql = "INSERT INTO customers("
+ "customer_email, name, phone_number, address, postal_code, city)" + "customer_email, customer_name, phone_number, address, postal_code, city)"
+ " VALUES (?, ?, ?, ?, ?, ?)"; + " VALUES (?, ?, ?, ?, ?, ?)";
try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) { try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) {
stmt.setString(1, customer.getEmail()); stmt.setString(1, customer.getEmail());
...@@ -81,7 +81,7 @@ public class CustomerDAO { ...@@ -81,7 +81,7 @@ public class CustomerDAO {
public boolean update(Customer customer) throws DBException { public boolean update(Customer customer) throws DBException {
final String sql = "UPDATE customers SET " final String sql = "UPDATE customers SET "
+ " name=?, phone_number=?, address=?, postal_code=?, city=?" + " customer_name=?, phone_number=?, address=?, postal_code=?, city=?"
+ " WHERE customer_email = ?"; + " WHERE customer_email = ?";
try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) { try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) {
stmt.setString(1, customer.getName()); stmt.setString(1, customer.getName());
......
...@@ -54,7 +54,7 @@ public class CustomerDAO { ...@@ -54,7 +54,7 @@ public class CustomerDAO {
private Customer customerFromRS(ResultSet rs) throws SQLException { private Customer customerFromRS(ResultSet rs) throws SQLException {
return new Customer( return new Customer(
rs.getString("customer_email"), rs.getString("customer_email"),
rs.getString("name"), rs.getString("customer_name"),
rs.getString("phone_number"), rs.getString("phone_number"),
rs.getString("address"), rs.getString("address"),
rs.getString("postal_code"), rs.getString("postal_code"),
...@@ -64,7 +64,7 @@ public class CustomerDAO { ...@@ -64,7 +64,7 @@ public class CustomerDAO {
public void insert(Customer customer) throws DBException { public void insert(Customer customer) throws DBException {
// używać gdy obiekt ma wpisane ID (tu: email) // używać gdy obiekt ma wpisane ID (tu: email)
final String sql = "INSERT INTO customers(" final String sql = "INSERT INTO customers("
+ "customer_email, name, phone_number, address, postal_code, city)" + "customer_email, customer_name, phone_number, address, postal_code, city)"
+ " VALUES (?, ?, ?, ?, ?, ?)"; + " VALUES (?, ?, ?, ?, ?, ?)";
try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) { try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) {
stmt.setString(1, customer.getEmail()); stmt.setString(1, customer.getEmail());
...@@ -81,7 +81,7 @@ public class CustomerDAO { ...@@ -81,7 +81,7 @@ public class CustomerDAO {
public boolean update(Customer customer) throws DBException { public boolean update(Customer customer) throws DBException {
final String sql = "UPDATE customers SET " final String sql = "UPDATE customers SET "
+ " name=?, phone_number=?, address=?, postal_code=?, city=?" + " customer_name=?, phone_number=?, address=?, postal_code=?, city=?"
+ " WHERE customer_email = ?"; + " WHERE customer_email = ?";
try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) { try(PreparedStatement stmt = db.getSqlConnection().prepareStatement(sql)) {
stmt.setString(1, customer.getName()); stmt.setString(1, customer.getName());
......
...@@ -4,10 +4,14 @@ import java.math.BigDecimal; ...@@ -4,10 +4,14 @@ import java.math.BigDecimal;
import java.util.List; import java.util.List;
import jakarta.jws.WebService; import jakarta.jws.WebService;
import sklep.db.CustomerDAO;
import sklep.db.DBConnection; import sklep.db.DBConnection;
import sklep.db.DBException; import sklep.db.DBException;
import sklep.db.OrderDAO;
import sklep.db.ProductDAO; import sklep.db.ProductDAO;
import sklep.db.RecordNotFound; import sklep.db.RecordNotFound;
import sklep.model.Customer;
import sklep.model.Order;
import sklep.model.Product; import sklep.model.Product;
@WebService @WebService
...@@ -41,4 +45,18 @@ public class Sklep { ...@@ -41,4 +45,18 @@ public class Sklep {
} }
} }
public Order zamowienieWgId(int orderId) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
OrderDAO orderDAO = db.orderDAO();
return orderDAO.findById(orderId);
}
}
public Customer klient(String email) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) {
CustomerDAO customerDAO = db.customerDAO();
return customerDAO.findByEmail(email);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment