From 4406a6d9ab17f28d3529a94d694886528ddb1fc8 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Wed, 4 Nov 2020 09:59:06 -0700 Subject: [PATCH 1/6] initial code loaded from phase I --- .gitignore | 63 ++- .../config/H2ServerConfiguration.java | 72 ++++ .../java/com/javagetorders/models/Agent.java | 236 ++++++++++ .../com/javagetorders/models/Customer.java | 408 ++++++++++++++++++ .../java/com/javagetorders/models/Order.java | 209 +++++++++ .../com/javagetorders/models/Payment.java | 116 +++++ .../repositories/AgentRepository.java | 12 + .../repositories/CustomerRepository.java | 13 + .../repositories/OrdersRepository.java | 13 + .../repositories/PaymentRepository.java | 13 + 10 files changed, 1123 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/javagetorders/config/H2ServerConfiguration.java create mode 100644 src/main/java/com/javagetorders/models/Agent.java create mode 100644 src/main/java/com/javagetorders/models/Customer.java create mode 100644 src/main/java/com/javagetorders/models/Order.java create mode 100644 src/main/java/com/javagetorders/models/Payment.java create mode 100644 src/main/java/com/javagetorders/repositories/AgentRepository.java create mode 100644 src/main/java/com/javagetorders/repositories/CustomerRepository.java create mode 100644 src/main/java/com/javagetorders/repositories/OrdersRepository.java create mode 100644 src/main/java/com/javagetorders/repositories/PaymentRepository.java diff --git a/.gitignore b/.gitignore index 37e7663..549e00a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,33 @@ -# Jetbrains IntelliJ Idea +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### .idea +*.iws *.iml - -# Linux -# backup files -*~ - -# Windows -# thumbnails -Thumbs.db - -# Mac OS X -# metadata -.DS_Store -# thumbnails -._* - -# GIT -.git/ - -# Java -*.class - -# packages -*.jar -*.war -*.ear - -# Logging -*.log - -# jME (binaries) -*.so +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/src/main/java/com/javagetorders/config/H2ServerConfiguration.java b/src/main/java/com/javagetorders/config/H2ServerConfiguration.java new file mode 100644 index 0000000..3ff7ee2 --- /dev/null +++ b/src/main/java/com/javagetorders/config/H2ServerConfiguration.java @@ -0,0 +1,72 @@ +package com.lambdaschool.orders.config; + +import org.h2.tools.Server; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.sql.SQLException; + +/** + * Configures H2 access through the JetBrains IntelliJ IDEA IDE. + *

+ * Adapted from https://techdev.io/en/developer-blog/querying-the-embedded-h2-database-of-a-spring-boot-application + * necessary for using the database tool built into intellij + */ +@Configuration +public class H2ServerConfiguration +{ + + /** + * TCP port for remote connections, default 9092. + */ + @Value("${h2.tcp.port:9092}") + private String h2TcpPort; + + /** + * Web port, default 8082. + */ + @Value("${h2.web.port:8082}") + private String h2WebPort; + + /** + * TCP connection to connect with SQL clients to the embedded h2 database. + *

+ * Connect to "jdbc:h2:tcp://localhost:9092/mem:testdb", username "sa", password empty. + * + * @return The created TcpServer needed to access H2. + * @throws SQLException If the server cannot be created. + */ + @Bean + @ConditionalOnExpression("${h2.tcp.enabled:true}") + public Server h2TcpServer() throws + SQLException + { + return Server.createTcpServer("-tcp", + "-tcpAllowOthers", + "-tcpPort", + h2TcpPort) + .start(); + } + + /** + * Web console for the embedded h2 database. + *

+ * Go to http://localhost:8082 and connect to the database "jdbc:h2:mem:testdb", username "sa", password empty. + * + * @return The created web server needed to access H2. + * @throws SQLException If the server cannot be created. + */ + @Bean + @ConditionalOnExpression("${h2.web.enabled:true}") + public Server h2WebServer() throws + SQLException + { + return Server.createWebServer("-web", + "-webAllowOthers", + "-webPort", + h2WebPort) + .start(); + } +} diff --git a/src/main/java/com/javagetorders/models/Agent.java b/src/main/java/com/javagetorders/models/Agent.java new file mode 100644 index 0000000..aa4fafd --- /dev/null +++ b/src/main/java/com/javagetorders/models/Agent.java @@ -0,0 +1,236 @@ +package com.lambdaschool.orders.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +/** + * The entity allowing interaction with the agents table. + */ +@Entity +@Table(name = "agents") +public class Agent +{ + /** + * The primary key number (long) of the agents table. + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long agentcode; + + /** + * The name (String) of the agent. + */ + private String agentname; + + /** + * The working area, geographical area, (String) of the agent. + */ + private String workingarea; + + /** + * The commission rate (double) of the agent. + */ + private double commission; + + /** + * The phone number (String) of the agent. No predefined format. + */ + private String phone; + + /** + * The country (String) where the agent is localed. + */ + private String country; + + /** + * List of customers associated with this agent. Does not get saved in the database directly. + * Forms a One-To-Many relationship with customers. One agent to many customers. + */ + @OneToMany(mappedBy = "agent", + cascade = CascadeType.ALL, + orphanRemoval = true) + @JsonIgnoreProperties(value = "agent", + allowSetters = true) + private List customers = new ArrayList<>(); + + /** + * Default constructor used primarily by the JPA. + */ + public Agent() + { + } + + /** + * Given the params, create a new agent object. + *

+ * agentcode is autogenerated. + * + * @param agentname The name (String) of the agent. + * @param workingarea The working area, geographical area, (String) of the agent. + * @param commission The commission rate (double) of the agent. + * @param phone The phone number (String) of the agent. No predefined format. + * @param country The country (String) where the agent is localed. + * customers are added outside of this constructor. + */ + public Agent( + String agentname, + String workingarea, + double commission, + String phone, + String country) + { + this.agentname = agentname; + this.workingarea = workingarea; + this.commission = commission; + this.phone = phone; + this.country = country; + } + + /** + * Getter for agentcode. + * + * @return The primary key number (long) of the agents table. + */ + public long getAgentcode() + { + return agentcode; + } + + /** + * Setter for agentcode - used primarily when seeding data. + * + * @param agentcode The primary key number (long) of the agents table. + */ + public void setAgentcode(long agentcode) + { + this.agentcode = agentcode; + } + + /** + * Getter for agentname. + * + * @return The name (String) of the agent. + */ + public String getAgentname() + { + return agentname; + } + + /** + * Setter for agentname. + * + * @param agentname The new name (String) of the agent. + */ + public void setAgentname(String agentname) + { + this.agentname = agentname; + } + + /** + * Getter for workingarea. + * + * @return The working area, geographical area, (String) of the agent. + */ + public String getWorkingarea() + { + return workingarea; + } + + /** + * Setter for workingarea. + * + * @param workingarea The new working area, geographical area, (String) of the agent. + */ + public void setWorkingarea(String workingarea) + { + this.workingarea = workingarea; + } + + /** + * Getter for commission. + * + * @return The commission rate (double) of the agent. + */ + public double getCommission() + { + return commission; + } + + /** + * Setter for the commission. + *

+ * If the value is set through the JPA, specifically through a JSON object set to this API, + * hasvaluefor will be set to true. Otherwise it defaults to false. + * This allows the application to tell if a commission rate is 0.0 because it was set as 0.0 or + * because it is not set and thus should be considered NULL but is in fact 0.0. + * + * @param commission The new commission rate (double) of the agent. + */ + public void setCommission(double commission) + { + this.commission = commission; + } + + /** + * Getter for phone. + * + * @return The phone number (String) of the agent. No predefined format. + */ + public String getPhone() + { + return phone; + } + + /** + * Setter for phone. + * + * @param phone The new phone number (String) of the agent. No predefined format. + */ + public void setPhone(String phone) + { + this.phone = phone; + } + + /** + * Getter for country. + * + * @return The country (String) where the agent is localed. + */ + public String getCountry() + { + return country; + } + + /** + * Setter for country. + * + * @param country The new country (String) where the agent is localed. + */ + public void setCountry(String country) + { + this.country = country; + } + + /** + * Getter for customers. + * + * @return List of customers associated with this agent. + */ + public List getCustomers() + { + return customers; + } + + /** + * Setter for customers. + * + * @param customers Replaces the list of customers associated with this agent with the this list. + */ + public void setCustomers(List customers) + { + this.customers = customers; + } +} diff --git a/src/main/java/com/javagetorders/models/Customer.java b/src/main/java/com/javagetorders/models/Customer.java new file mode 100644 index 0000000..d494428 --- /dev/null +++ b/src/main/java/com/javagetorders/models/Customer.java @@ -0,0 +1,408 @@ +package com.lambdaschool.orders.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +/** + * The entity allowing interaction with the customers table. + */ +@Entity +@Table(name = "customers") +public class Customer +{ + /** + * The primary key number (long) of the customer's table. + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long custcode; + + /** + * The name (String) of the customer. Cannot be null. + */ + @Column(nullable = false) + private String custname; + + /** + * The city (String) of the customer. + */ + private String custcity; + + /** + * The workingarea, geographical location, (String) of the customer. + */ + private String workingarea; + + /** + * The country (String) of the customer. + */ + private String custcountry; + + /** + * The grade (String) of the customer. + */ + private String grade; + + /** + * The openingamt (double) of the customer's account. + */ + private double openingamt; + + /** + * The amount received (double) on the customer's account. + */ + private double receiveamt; + + /** + * The payment amount (double) on the customer's account. + */ + private double paymentamt; + + /** + * The amount outstanding (double) on the customer's account. + */ + private double outstandingamt; + + /** + * The phone number (String) of the agent. No predefined format. + */ + private String phone; + + /** + * A foreign key to the agent table. + * Forms a Many-To-One relation with the agent table. Many customers to one agent. + * Contains an object pointer to the full agent object. + */ + @ManyToOne + @JoinColumn(name = "agentcode", + nullable = false) + @JsonIgnoreProperties(value = "customers", + allowSetters = true) + private Agent agent; + + /** + * List of orders associated with this customer. Does not get saved in the database directly. + * Forms a One-To-Many relationship to orders. One customer to many orders. + */ + @OneToMany(mappedBy = "customer", + cascade = CascadeType.ALL, + orphanRemoval = true) + @JsonIgnoreProperties(value = "customer", + allowSetters = true) + private List orders = new ArrayList<>(); + + /** + * Default constructor used primarily by the JPA. + */ + public Customer() + { + } + + /** + * Given the params, create a new customer object. + *

+ * custcode is autogenerated. + * + * @param custname The name (String) of the customer. + * @param custcity The city (String) of the customer. + * @param workingarea The workingarea, geographical location, (String) of the customer. + * @param custcountry The country (String) of the customer. + * @param grade The grade (String) of the customer. + * @param openingamt The openingamt (double) of the customer's account. + * @param receiveamt The amount received (double) on the customer's account. + * @param paymentamt The payment amount (double) on the customer's account. + * @param outstandingamt The amount outstanding (double) on the customer's account. + * @param phone The phone number (String) of the agent. + * @param agent The agent record associated with this customer. + * orders are added outside of this constructor. + */ + public Customer( + String custname, + String custcity, + String workingarea, + String custcountry, + String grade, + double openingamt, + double receiveamt, + double paymentamt, + double outstandingamt, + String phone, + Agent agent) + { + this.custname = custname; + this.custcity = custcity; + this.workingarea = workingarea; + this.custcountry = custcountry; + this.grade = grade; + this.openingamt = openingamt; + this.receiveamt = receiveamt; + this.paymentamt = paymentamt; + this.outstandingamt = outstandingamt; + this.phone = phone; + this.agent = agent; + } + + /** + * Getter custcode. + * + * @return The primary key number (long) of the customer's table. + */ + public long getCustcode() + { + return custcode; + } + + /** + * Setter for the custcode - used primarily when seeding data. + * + * @param custcode The new primary key number (long) of the customer's table. + */ + public void setCustcode(long custcode) + { + this.custcode = custcode; + } + + /** + * Getter for the custname. + * + * @return The name (String) of the customer. + */ + public String getCustname() + { + return custname; + } + + /** + * Setter for the custname. + * + * @param custname The new name (String) of the customer. + */ + public void setCustname(String custname) + { + this.custname = custname; + } + + /** + * Getter for custcity. + * + * @return The city (String) of the customer. + */ + public String getCustcity() + { + return custcity; + } + + /** + * Setter for custcity. + * + * @param custcity The new city (String) of the customer. + */ + public void setCustcity(String custcity) + { + this.custcity = custcity; + } + + /** + * Getter for workingarea + * + * @return The workingarea, geographical location, (String) of the customer. + */ + public String getWorkingarea() + { + return workingarea; + } + + /** + * Setter for workingarea. + * + * @param workingarea The new workingarea, geographical location, (String) of the customer. + */ + public void setWorkingarea(String workingarea) + { + this.workingarea = workingarea; + } + + /** + * Getter for customer country. + * + * @return The country (String) of the customer. + */ + public String getCustcountry() + { + return custcountry; + } + + /** + * Setter for custcountry. + * + * @param custcountry The new country (String) of the customer. + */ + public void setCustcountry(String custcountry) + { + this.custcountry = custcountry; + } + + /** + * Getter for grade. + * + * @return The grade (String) of the customer. + */ + public String getGrade() + { + return grade; + } + + /** + * Setter for grade. + * + * @param grade The new grade (String) of the customer. + */ + public void setGrade(String grade) + { + this.grade = grade; + } + + /** + * Getter for openingamt. + * + * @return The openingamt (double) of the customer's account. + */ + public double getOpeningamt() + { + return openingamt; + } + + /** + * Setter for openingamt. + * + * @param openingamt The new openingamt (double) of the customer's account. + */ + public void setOpeningamt(double openingamt) + { + this.openingamt = openingamt; + } + + /** + * Getter for receiveamt. + * + * @return The amount received (double) on the customer's account. + */ + public double getReceiveamt() + { + return receiveamt; + } + + /** + * Setter for receiveamt. + * + * @param receiveamt The new amount received (double) on the customer's account. + */ + public void setReceiveamt(double receiveamt) + { + this.receiveamt = receiveamt; + } + + /** + * Getter for paymentamt. + * + * @return The payment amount (double) on the customer's account. + */ + public double getPaymentamt() + { + return paymentamt; + } + + /** + * Setter for paymentamt. + *

+ * + * @param paymentamt The new payment amount (double) on the customer's account. + */ + public void setPaymentamt(double paymentamt) + { + this.paymentamt = paymentamt; + } + + /** + * Getter for outstandingamt. + * + * @return The amount outstanding (double) on the customer's account. + */ + public double getOutstandingamt() + { + return outstandingamt; + } + + /** + * Setter for outstandingamt. + * + * @param outstandingamt The new amount outstanding (double) on the customer's account. + */ + public void setOutstandingamt(double outstandingamt) + { + this.outstandingamt = outstandingamt; + } + + /** + * Getter for phone. + * + * @return The phone number (String) of the agent. + */ + public String getPhone() + { + return phone; + } + + /** + * Setter for phone. + * + * @param phone The new phone number (String) of the agent. + */ + public void setPhone(String phone) + { + this.phone = phone; + } + + /** + * Getter for agent. + * + * @return The agent record assigned to this customer. + */ + public Agent getAgent() + { + return agent; + } + + /** + * Setter for agent. + * + * @param agent The new agent record assigned to this customer. + */ + public void setAgent(Agent agent) + { + this.agent = agent; + } + + /** + * Getter orders. + * + * @return List of orders for this customer. + */ + public List getOrders() + { + return orders; + } + + /** + * Setter orders. + * + * @param orders A new list of orders for this customer. + */ + public void setOrders(List orders) + { + this.orders = orders; + } +} diff --git a/src/main/java/com/javagetorders/models/Order.java b/src/main/java/com/javagetorders/models/Order.java new file mode 100644 index 0000000..5301fc9 --- /dev/null +++ b/src/main/java/com/javagetorders/models/Order.java @@ -0,0 +1,209 @@ +package com.lambdaschool.orders.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +/** + * The entity allowing interaction with the orders table. + */ +@Entity +@Table(name = "orders") +public class Order +{ + /** + * The primary key number (long) of the order's table. + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long ordnum; + + /** + * The order amount (double) for this order. + */ + private double ordamount; + + /** + * The amount (double) prepaid for this order. + */ + private double advanceamount; + + /** + * The description of this order (String). + */ + private String orderdescription; + + /** + * Creates a join table joining Orders and Payments in a Many-To-Many relations. + * Contains a list of Payment objects used by this order. + */ + @ManyToMany() + @JoinTable(name = "orderspayments", + joinColumns = @JoinColumn(name = "ordnum"), + inverseJoinColumns = @JoinColumn(name = "paymentid")) + @JsonIgnoreProperties("orders") + Set payments = new HashSet<>(); + + /** + * A foreign key to the customer table. + * Forms a Many-To-One relation with the customer table. Many orders to one customer. + * Contains an object pointer to the full customer object. + */ + @ManyToOne + @JoinColumn(name = "custcode", + nullable = false) + @JsonIgnoreProperties("orders") + private Customer customer; + + /** + * Default constructor used primarily by the JPA. + */ + public Order() + { + } + + /** + * Given the params, create a new order object. + *

+ * ordnum is autogeneration + * + * @param ordamount The order amount (double) for this order. + * @param advanceamount The amount (double) prepaid for this order. + * @param customer The customer object assigned to this order + * @param orderdescription The description of this order (String). + * payments are added outside of this constructor. + */ + public Order( + double ordamount, + double advanceamount, + Customer customer, + String orderdescription) + { + this.ordamount = ordamount; + this.advanceamount = advanceamount; + this.orderdescription = orderdescription; + this.customer = customer; + } + + /** + * Getter for ordnum. + * + * @return The primary key number (long) of the order's table. + */ + public long getOrdnum() + { + return ordnum; + } + + /** + * Setter for ordnum - used primarily when seeding data. + * + * @param ordnum The new primary key number (long) of the order's table. + */ + public void setOrdnum(long ordnum) + { + this.ordnum = ordnum; + } + + /** + * Getter for ordamount. + * + * @return The order amount (double) for this order. + */ + public double getOrdamount() + { + return ordamount; + } + + /** + * Setter for ordamount. + * + * @param ordamount The new order amount (double) for this order. + */ + public void setOrdamount(double ordamount) + { + this.ordamount = ordamount; + } + + /** + * Getter for advanceamount. + * + * @return The amount (double) prepaid for this order. + */ + public double getAdvanceamount() + { + return advanceamount; + } + + /** + * Setter for advanceamount. + * + * @param advanceamount The new amount (double) prepaid for this order. + */ + public void setAdvanceamount(double advanceamount) + { + this.advanceamount = advanceamount; + } + + /** + * Getter for order description. + * + * @return The description of this order (String). + */ + public String getOrderdescription() + { + return orderdescription; + } + + /** + * Setter for order description. + * + * @param orderdescription The new description of this order (String). + */ + public void setOrderdescription(String orderdescription) + { + this.orderdescription = orderdescription; + } + + /** + * Getter for customer. + * + * @return The customer object assigned to this order. + */ + public Customer getCustomer() + { + return customer; + } + + /** + * Setter for customer. + * + * @param customer Assigning a new customer object to this order. + */ + public void setCustomer(Customer customer) + { + this.customer = customer; + } + + /** + * Getter for payments. + * + * @return A list of the payments used by this order. + */ + public Set getPayments() + { + return payments; + } + + /** + * Setter for payments. + * + * @param payments A new list of payments used by this order. + */ + public void setPayments(Set payments) + { + this.payments = payments; + } +} \ No newline at end of file diff --git a/src/main/java/com/javagetorders/models/Payment.java b/src/main/java/com/javagetorders/models/Payment.java new file mode 100644 index 0000000..fcf9d04 --- /dev/null +++ b/src/main/java/com/javagetorders/models/Payment.java @@ -0,0 +1,116 @@ +package com.lambdaschool.orders.models; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +/** + * The entity allowing interaction with the payments table. + */ +@Entity +@Table(name = "payments") +public class Payment +{ + /** + * The primary key number (long) of the payments table. + */ + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long paymentid; + + /** + * The type (String) of payment. Cannot be null and must be unique. + */ + @Column(nullable = false, + unique = true) + private String type; + + /** + * Creates a join table joining Orders and Payments in a Many-To-Many relations. + * Contains a list of Payment objects used by this order. + */ + @ManyToMany(mappedBy = "payments") + @JsonIgnoreProperties("payments") + private Set orders = new HashSet<>(); + + /** + * Default Constructor used primarily by the JPA. + */ + public Payment() + { + } + + /** + * Given the type, create a new payment object. Order gets added later. + *

+ * paymentid is autogenerated. + * + * @param type The type (String) of payment. Cannot be null. + */ + public Payment(String type) + { + this.type = type; + } + + /** + * Getter for paymentid. + * + * @return The primary key number (long) of the payments table. + */ + public long getPaymentid() + { + return paymentid; + } + + /** + * Setter for paymentid - used primarily when seeding data. + * + * @param paymentid The new primary key (long) number of the payments table. + */ + public void setPaymentid(long paymentid) + { + this.paymentid = paymentid; + } + + /** + * Getter for type. + * + * @return The type (String) of the payment. + */ + public String getType() + { + return type; + } + + /** + * Setter for type. + * + * @param type The new type (String) of this payment. + */ + public void setType(String type) + { + this.type = type; + } + + /** + * Getter for the orders using this payment. + * + * @return List of orders objects using this payment. + */ + public Set getOrders() + { + return orders; + } + + /** + * Setter for the orders using this payment. + * + * @param orders The new list of orders objects using this payment. + */ + public void setOrders(Set orders) + { + this.orders = orders; + } +} diff --git a/src/main/java/com/javagetorders/repositories/AgentRepository.java b/src/main/java/com/javagetorders/repositories/AgentRepository.java new file mode 100644 index 0000000..c81ab6b --- /dev/null +++ b/src/main/java/com/javagetorders/repositories/AgentRepository.java @@ -0,0 +1,12 @@ +package com.lambdaschool.orders.repositories; + +import com.lambdaschool.orders.models.Agent; +import org.springframework.data.repository.CrudRepository; + +/** + * The CRUD Repository connecting Agent to rest of the application. + */ +public interface AgentsRepository + extends CrudRepository +{ +} diff --git a/src/main/java/com/javagetorders/repositories/CustomerRepository.java b/src/main/java/com/javagetorders/repositories/CustomerRepository.java new file mode 100644 index 0000000..93841eb --- /dev/null +++ b/src/main/java/com/javagetorders/repositories/CustomerRepository.java @@ -0,0 +1,13 @@ +package com.lambdaschool.orders.repositories; + +import com.lambdaschool.orders.models.Customer; +import org.springframework.data.repository.CrudRepository; + +/** + * The CRUD Repository connecting Customer to rest of the application. + */ +public interface CustomersRepository + extends CrudRepository +{ +} + diff --git a/src/main/java/com/javagetorders/repositories/OrdersRepository.java b/src/main/java/com/javagetorders/repositories/OrdersRepository.java new file mode 100644 index 0000000..b3db0c0 --- /dev/null +++ b/src/main/java/com/javagetorders/repositories/OrdersRepository.java @@ -0,0 +1,13 @@ +package com.lambdaschool.orders.repositories; + +import com.lambdaschool.orders.models.Order; +import org.springframework.data.repository.CrudRepository; + +/** + * The CRUD Repository connecting Order to rest of the application. + */ +public interface OrdersRepository + extends CrudRepository +{ +} + diff --git a/src/main/java/com/javagetorders/repositories/PaymentRepository.java b/src/main/java/com/javagetorders/repositories/PaymentRepository.java new file mode 100644 index 0000000..f0cdf3c --- /dev/null +++ b/src/main/java/com/javagetorders/repositories/PaymentRepository.java @@ -0,0 +1,13 @@ +package com.lambdaschool.orders.repositories; + +import com.lambdaschool.orders.models.Payment; +import org.springframework.data.repository.CrudRepository; + +/** + * The CRUD Repository connecting Payment to rest of the application. + */ +public interface PaymentRepository + extends CrudRepository +{ +} + From 3498a01f521fdcaf9c99e1c6cb58009ff9e4ed31 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Wed, 4 Nov 2020 16:09:57 -0700 Subject: [PATCH 2/6] SeedData transferred --- .../com/javagetorders/OrdersApplication.java | 24 + src/main/java/com/javagetorders/SeedData.java | 635 ++++++++++++++++++ 2 files changed, 659 insertions(+) create mode 100644 src/main/java/com/javagetorders/OrdersApplication.java create mode 100644 src/main/java/com/javagetorders/SeedData.java diff --git a/src/main/java/com/javagetorders/OrdersApplication.java b/src/main/java/com/javagetorders/OrdersApplication.java new file mode 100644 index 0000000..7daa973 --- /dev/null +++ b/src/main/java/com/javagetorders/OrdersApplication.java @@ -0,0 +1,24 @@ +package com.lambdaschool.orders; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Main class to start the application. + */ +@SpringBootApplication +public class OrdersApplication +{ + + /** + * Main method to start the application. + * + * @param args Not used in this application. + */ + public static void main(String[] args) + { + SpringApplication.run(OrdersApplication.class, + args); + } + +} diff --git a/src/main/java/com/javagetorders/SeedData.java b/src/main/java/com/javagetorders/SeedData.java new file mode 100644 index 0000000..1ef109f --- /dev/null +++ b/src/main/java/com/javagetorders/SeedData.java @@ -0,0 +1,635 @@ +package com.lambdaschool.orders; + +import com.github.javafaker.Faker; +import com.lambdaschool.orders.models.Agent; +import com.lambdaschool.orders.models.Customer; +import com.lambdaschool.orders.models.Order; +import com.lambdaschool.orders.models.Payment; +import com.lambdaschool.orders.repositories.AgentsRepository; +import com.lambdaschool.orders.repositories.CustomersRepository; +import com.lambdaschool.orders.repositories.OrdersRepository; +import com.lambdaschool.orders.repositories.PaymentRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Random; +import java.util.Set; + +@Transactional +@Component +public class SeedData + implements CommandLineRunner +{ + /** + * Connects the customer table to this SeedData method + */ + @Autowired + private CustomersRepository custrepos; + + /** + * Connects the agents table to this SeedData method + */ + @Autowired + private AgentsRepository agentrepos; + + /** + * Connects the orders table to this SeedData method + */ + @Autowired + private OrdersRepository ordersrepos; + + /** + * Connects the payment table to this SeedData method + */ + @Autowired + private PaymentRepository paymentrepos; + + /** + * A Random generator is needed to randomly generate faker data. + */ + private Random random = new Random(); + + /** + * Generates test, seed data for our application + * First a set of known data is seeded into our database. + * Second a random set of data using Java Faker is seeded into our database. + * Note this process does not remove data from the database. So if data exists in the database + * prior to running this process, that data remains in the database. + * + * @param args The parameter is required by the parent interface but is not used in this process. + */ + @Transactional + @Override + public void run(String[] args) throws + Exception + { + Payment pay1 = new Payment("Cash"); + Payment pay2 = new Payment("Gift Card"); + Payment pay3 = new Payment("Credit Card"); + Payment pay4 = new Payment("Mobile Pay"); + + pay1 = paymentrepos.save(pay1); + pay2 = paymentrepos.save(pay2); + pay3 = paymentrepos.save(pay3); + pay4 = paymentrepos.save(pay4); + + Agent a01 = new Agent("Ramasundar", + "Bangalore", + 0.15, + "077-25814763", + ""); + Agent a02 = new Agent("Alex", + "London", + 0.13, + "075-12458969", + ""); + Agent a03 = new Agent("Alford", + "New York", + 0.12, + "044-25874365", + ""); + Agent a04 = new Agent("Ravi", + "Bangalore", + 0.15, + "077-45625874", + ""); + Agent a05 = new Agent("Santakumar", + "Chennai", + 0.14, + "007-22388644", + ""); + Agent a06 = new Agent("Lucida", + "San Jose", + 0.12, + "044-52981425", + ""); + Agent a07 = new Agent("Anderson", + "Brisban", + 0.13, + "045-21447739", + ""); + Agent a08 = new Agent("Subbarao", + "Bangalore", + 0.14, + "077-12346674", + ""); + Agent a09 = new Agent("Mukesh", + "Mumbai", + 0.11, + "029-12358964", + ""); + Agent a10 = new Agent("McDen", + "London", + 0.15, + "078-22255588", + ""); + Agent a11 = new Agent("Ivan", + "Torento", + 0.15, + "008-22544166", + ""); + Agent a12 = new Agent("Benjamin", + "Hampshair", + 0.11, + "008-22536178", + ""); + + Customer c01 = new Customer("Holmes", + "London", + "London", + "UK", + "2", + 6000.00, + 5000.00, + 7000.00, + 4000.00, + "BBBBBBB", + a03); + Customer c02 = new Customer("Micheal", + "New York", + "New York", + "USA", + "2", + 3000.00, + 5000.00, + 2000.00, + 6000.00, + "CCCCCCC", + a08); + Customer c03 = new Customer("Albert", + "New York", + "New York", + "USA", + "3", + 5000.00, + 7000.00, + 6000.00, + 6000.00, + "BBBBSBB", + a08); + Customer c04 = new Customer("Ravindran", + "Bangalore", + "Bangalore", + "India", + "2", + 5000.00, + 7000.00, + 4000.00, + 8000.00, + "AVAVAVA", + a11); + Customer c05 = new Customer("Cook", + "London", + "London", + "UK", + "2", + 4000.00, + 9000.00, + 7000.00, + 6000.00, + "FSDDSDF", + a06); + Customer c06 = new Customer("Stuart", + "London", + "London", + "UK", + "1", + 6000.00, + 8000.00, + 3000.00, + 11000.00, + "GFSGERS", + a03); + Customer c07 = new Customer("Bolt", + "New York", + "New York", + "USA", + "3", + 5000.00, + 7000.00, + 9000.00, + 3000.00, + "DDNRDRH", + a08); + Customer c08 = new Customer("Fleming", + "Brisban", + "Brisban", + "Australia", + "2", + 7000.00, + 7000.00, + 9000.00, + 5000.00, + "NHBGVFC", + a05); + Customer c09 = new Customer("Jacks", + "Brisban", + "Brisban", + "Australia", + "1", + 7000.00, + 7000.00, + 7000.00, + 7000.00, + "WERTGDF", + a05); + Customer c10 = new Customer("Yearannaidu", + "Chennai", + "Chennai", + "India", + "1", + 8000.00, + 7000.00, + 7000.00, + 8000.00, + "ZZZZBFV", + a10); + Customer c11 = new Customer("Sasikant", + "Mumbai", + "Mumbai", + "India", + "1", + 7000.00, + 11000.00, + 7000.00, + 11000.00, + "147-25896312", + a02); + Customer c12 = new Customer("Ramanathan", + "Chennai", + "Chennai", + "India", + "1", + 7000.00, + 11000.00, + 9000.00, + 9000.00, + "GHRDWSD", + a10); + Customer c13 = new Customer("Avinash", + "Mumbai", + "Mumbai", + "India", + "2", + 7000.00, + 11000.00, + 9000.00, + 9000.00, + "113-12345678", + a02); + Customer c14 = new Customer("Winston", + "Brisban", + "Brisban", + "Australia", + "1", + 5000.00, + 8000.00, + 7000.00, + 6000.00, + "AAAAAAA", + a05); + Customer c15 = new Customer("Karl", + "London", + "London", + "UK", + "0", + 4000.00, + 6000.00, + 7000.00, + 3000.00, + "AAAABAA", + a06); + Customer c16 = new Customer("Shilton", + "Torento", + "Torento", + "Canada", + "1", + 10000.00, + 7000.00, + 6000.00, + 11000.00, + "DDDDDDD", + a04); + Customer c17 = new Customer("Charles", + "Hampshair", + "Hampshair", + "UK", + "3", + 6000.00, + 4000.00, + 5000.00, + 5000.00, + "MMMMMMM", + a09); + Customer c18 = new Customer("Srinivas", + "Bangalore", + "Bangalore", + "India", + "2", + 8000.00, + 4000.00, + 3000.00, + 9000.00, + "AAAAAAB", + a07); + Customer c19 = new Customer("Steven", + "San Jose", + "San Jose", + "USA", + "1", + 5000.00, + 7000.00, + 9000.00, + 3000.00, + "KRFYGJK", + a10); + Customer c20 = new Customer("Karolina", + "Torento", + "Torento", + "Canada", + "1", + 7000.00, + 7000.00, + 9000.00, + 5000.00, + "HJKORED", + a04); + Customer c21 = new Customer("Martin", + "Torento", + "Torento", + "Canada", + "2", + 8000.00, + 7000.00, + 7000.00, + 8000.00, + "MJYURFD", + a04); + Customer c22 = new Customer("Ramesh", + "Mumbai", + "Mumbai", + "India", + "3", + 8000.00, + 7000.00, + 3000.00, + 12000.00, + "Phone No", + a02); + Customer c23 = new Customer("Rangarappa", + "Bangalore", + "Bangalore", + "India", + "2", + 8000.00, + 11000.00, + 7000.00, + 12000.00, + "AAAATGF", + a01); + Customer c24 = new Customer("Venkatpati", + "Bangalore", + "Bangalore", + "India", + "2", + 8000.00, + 11000.00, + 7000.00, + 12000.00, + "JRTVFDD", + a07); + Customer c25 = new Customer("Sundariya", + "Chennai", + "Chennai", + "India", + "3", + 7000.00, + 11000.00, + 7000.00, + 11000.00, + "PPHGRTS", + a10); + + Order o01 = new Order(1000.00, + 600.00, + c13, + "SOD"); + o01.getPayments() + .add(pay1); + + Order o02 = new Order(3000.00, + 500.00, + c19, + "SOD"); + o02.getPayments() + .add(pay2); + + Order o03 = new Order(4500.00, + 900.00, + c07, + "SOD"); + o03.getPayments() + .add(pay3); + o03.getPayments() + .add(pay2); + + Order o04 = new Order(2000.00, + 0.00, + c16, + "SOD"); + o04.getPayments() + .add(pay4); + + Order o05 = new Order(4000.00, + 600.00, + c22, + "SOD"); + o05.getPayments() + .add(pay2); + + Order o06 = new Order(2000.00, + 0.00, + c12, + "SOD"); + o06.getPayments() + .add(pay3); + + Order o07 = new Order(3500.00, + 2000.00, + c02, + "SOD"); + o07.getPayments() + .add(pay4); + + Order o08 = new Order(2500.00, + 400.00, + c03, + "SOD"); + o08.getPayments() + .add(pay1); + + Order o09 = new Order(500.00, + 0.00, + c23, + "SOD"); + o09.getPayments() + .add(pay3); + + Order o10 = new Order(4000.00, + 700.00, + c07, + "SOD"); + o10.getPayments() + .add(pay4); + + Order o11 = new Order(1500.00, + 600.00, + c08, + "SOD"); + o11.getPayments() + .add(pay2); + + Order o12 = new Order(2500.00, + 0.00, + c25, + "SOD"); + o12.getPayments() + .add(pay1); + + agentrepos.save(a01); + agentrepos.save(a02); + agentrepos.save(a03); + agentrepos.save(a04); + agentrepos.save(a05); + agentrepos.save(a06); + agentrepos.save(a07); + agentrepos.save(a08); + agentrepos.save(a09); + agentrepos.save(a10); + agentrepos.save(a11); + agentrepos.save(a12); + + custrepos.save(c01); + custrepos.save(c02); + custrepos.save(c03); + custrepos.save(c04); + custrepos.save(c05); + custrepos.save(c06); + custrepos.save(c07); + custrepos.save(c08); + custrepos.save(c09); + custrepos.save(c10); + custrepos.save(c11); + custrepos.save(c12); + custrepos.save(c13); + custrepos.save(c14); + custrepos.save(c15); + custrepos.save(c16); + custrepos.save(c17); + custrepos.save(c18); + custrepos.save(c19); + custrepos.save(c20); + custrepos.save(c21); + custrepos.save(c22); + custrepos.save(c23); + custrepos.save(c24); + custrepos.save(c25); + + ordersrepos.save(o01); + ordersrepos.save(o02); + ordersrepos.save(o03); + ordersrepos.save(o04); + ordersrepos.save(o05); + ordersrepos.save(o06); + ordersrepos.save(o07); + ordersrepos.save(o08); + ordersrepos.save(o09); + ordersrepos.save(o10); + ordersrepos.save(o11); + ordersrepos.save(o12); + + //Begins the faker data + + Faker dataFaker = new Faker(new Locale("en-US")); + Set customerNames = new HashSet<>(); + for (int i = 0; i < 100; i++) + { + customerNames.add(dataFaker.name() + .fullName()); + } + + for (String theName : customerNames) + { + String custcity = dataFaker.address() + .city(); + String tempWorkingarea = dataFaker.address() + .cityName(); + String tempCustcountry = dataFaker.address() + .country(); + String tempGrade = dataFaker.country() + .countryCode2(); + double tempOpeningamt = dataFaker.number() + .randomDouble(2, + 0, + 10000); + double tempReceiveamt = dataFaker.number() + .randomDouble(2, + 0, + 10000); + double tempPaymentamt = dataFaker.number() + .randomDouble(2, + 0, + 10000); + double tempOutstandingamt = dataFaker.number() + .randomDouble(2, + 0, + 10000); + String tempPhone = dataFaker.phoneNumber() + .phoneNumber(); + + Customer fakeCustomer = new Customer(theName, + custcity, + tempWorkingarea, + tempCustcountry, + tempGrade, + tempOpeningamt, + tempReceiveamt, + tempPaymentamt, + tempOutstandingamt, + tempPhone, + a10); + + int randomNumber = random.nextInt(10); // random number 0 through 9 + for (int i = 0; i < randomNumber; i++) + { + double tempGetOrdamount = dataFaker.number() + .randomDouble(2, + 0, + 10000); + double tempGetAdvanceamount = dataFaker.number() + .randomDouble(2, + 0, + 10000); + String tempGetOrderdescription = dataFaker.lorem() + .characters(); + + Order newOrder = new Order(tempGetOrdamount, + tempGetAdvanceamount, + fakeCustomer, + tempGetOrderdescription); + + newOrder.getPayments() + .add(pay1); + fakeCustomer.getOrders() + .add(newOrder); + } + + // this actually saves the faker data. + custrepos.save(fakeCustomer); + } + } +} From 6b820051fc68fb3802e96e8c848f3ecdca895383 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Wed, 4 Nov 2020 20:24:16 -0700 Subject: [PATCH 3/6] pathways updated on Repositories --- .../controllers/CustomerController.java | 30 +++++++++++++++++++ .../repositories/AgentRepository.java | 4 +-- .../repositories/CustomerRepository.java | 7 +++-- .../repositories/OrdersRepository.java | 4 +-- .../repositories/PaymentRepository.java | 4 +-- .../javagetorders/services/AgentServices.java | 5 ++++ .../services/AgentServicesImpl.java | 5 ++++ .../services/CustomerServices.java | 5 ++++ .../services/CustomerServicesImpl.java | 5 ++++ .../javagetorders/services/OrderServices.java | 5 ++++ .../services/OrderServicesImpl.java | 5 ++++ .../services/PaymentServices.java | 5 ++++ .../services/PaymentServicesImpl.java | 5 ++++ 13 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/javagetorders/controllers/CustomerController.java create mode 100644 src/main/java/com/javagetorders/services/AgentServices.java create mode 100644 src/main/java/com/javagetorders/services/AgentServicesImpl.java create mode 100644 src/main/java/com/javagetorders/services/CustomerServices.java create mode 100644 src/main/java/com/javagetorders/services/CustomerServicesImpl.java create mode 100644 src/main/java/com/javagetorders/services/OrderServices.java create mode 100644 src/main/java/com/javagetorders/services/OrderServicesImpl.java create mode 100644 src/main/java/com/javagetorders/services/PaymentServices.java create mode 100644 src/main/java/com/javagetorders/services/PaymentServicesImpl.java diff --git a/src/main/java/com/javagetorders/controllers/CustomerController.java b/src/main/java/com/javagetorders/controllers/CustomerController.java new file mode 100644 index 0000000..57e03bf --- /dev/null +++ b/src/main/java/com/javagetorders/controllers/CustomerController.java @@ -0,0 +1,30 @@ +package com.javagetorders.controllers; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/customers") +public class CustomerController +{ + @Autowired + + // http://localhost:2019/customers/orders + @GetMapping(value = "/orders", produces = {"application/json"}) + public ResponseEntity listAllOrders() + { + List rtnList = + } + + // http://localhost:2019/customers/customer/7 + + // http://localhost:2019/cusomters/customer/77 + + // http://localhost:2019/customers/namelike/mes + + // http://localhost:2019/agents/agent/9 + + // http://localhost:2019/orders/order/7 + + // http://localhost:2019/orders/advanceamount +} diff --git a/src/main/java/com/javagetorders/repositories/AgentRepository.java b/src/main/java/com/javagetorders/repositories/AgentRepository.java index c81ab6b..406e823 100644 --- a/src/main/java/com/javagetorders/repositories/AgentRepository.java +++ b/src/main/java/com/javagetorders/repositories/AgentRepository.java @@ -1,6 +1,6 @@ -package com.lambdaschool.orders.repositories; +package com.javagetorders.repositories; -import com.lambdaschool.orders.models.Agent; +import com.javagetorders.models.Agent; import org.springframework.data.repository.CrudRepository; /** diff --git a/src/main/java/com/javagetorders/repositories/CustomerRepository.java b/src/main/java/com/javagetorders/repositories/CustomerRepository.java index 93841eb..b95da89 100644 --- a/src/main/java/com/javagetorders/repositories/CustomerRepository.java +++ b/src/main/java/com/javagetorders/repositories/CustomerRepository.java @@ -1,12 +1,13 @@ -package com.lambdaschool.orders.repositories; +package com.javagetorders.repositories; -import com.lambdaschool.orders.models.Customer; +import com.javagetorders.models.Customer; +import com.javagetorders.repositories.CustomerRepository; import org.springframework.data.repository.CrudRepository; /** * The CRUD Repository connecting Customer to rest of the application. */ -public interface CustomersRepository +public interface CustomerRepository extends CrudRepository { } diff --git a/src/main/java/com/javagetorders/repositories/OrdersRepository.java b/src/main/java/com/javagetorders/repositories/OrdersRepository.java index b3db0c0..4f617ce 100644 --- a/src/main/java/com/javagetorders/repositories/OrdersRepository.java +++ b/src/main/java/com/javagetorders/repositories/OrdersRepository.java @@ -1,6 +1,6 @@ -package com.lambdaschool.orders.repositories; +package com.javagetorders.repositories; -import com.lambdaschool.orders.models.Order; +import com.javagetorders.Order; import org.springframework.data.repository.CrudRepository; /** diff --git a/src/main/java/com/javagetorders/repositories/PaymentRepository.java b/src/main/java/com/javagetorders/repositories/PaymentRepository.java index f0cdf3c..965da1f 100644 --- a/src/main/java/com/javagetorders/repositories/PaymentRepository.java +++ b/src/main/java/com/javagetorders/repositories/PaymentRepository.java @@ -1,6 +1,6 @@ -package com.lambdaschool.orders.repositories; +package com.javagetorders.repositories; -import com.lambdaschool.orders.models.Payment; +import com.javagetorders.models.Payment; import org.springframework.data.repository.CrudRepository; /** diff --git a/src/main/java/com/javagetorders/services/AgentServices.java b/src/main/java/com/javagetorders/services/AgentServices.java new file mode 100644 index 0000000..f1350ae --- /dev/null +++ b/src/main/java/com/javagetorders/services/AgentServices.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class AgentServices +{ +} diff --git a/src/main/java/com/javagetorders/services/AgentServicesImpl.java b/src/main/java/com/javagetorders/services/AgentServicesImpl.java new file mode 100644 index 0000000..1d6c07d --- /dev/null +++ b/src/main/java/com/javagetorders/services/AgentServicesImpl.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class AgentServicesImpl +{ +} diff --git a/src/main/java/com/javagetorders/services/CustomerServices.java b/src/main/java/com/javagetorders/services/CustomerServices.java new file mode 100644 index 0000000..770ac58 --- /dev/null +++ b/src/main/java/com/javagetorders/services/CustomerServices.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class CustomerServices +{ +} diff --git a/src/main/java/com/javagetorders/services/CustomerServicesImpl.java b/src/main/java/com/javagetorders/services/CustomerServicesImpl.java new file mode 100644 index 0000000..9bdf52c --- /dev/null +++ b/src/main/java/com/javagetorders/services/CustomerServicesImpl.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class CustomerServicesImpl +{ +} diff --git a/src/main/java/com/javagetorders/services/OrderServices.java b/src/main/java/com/javagetorders/services/OrderServices.java new file mode 100644 index 0000000..b262b9d --- /dev/null +++ b/src/main/java/com/javagetorders/services/OrderServices.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class OrderServices +{ +} diff --git a/src/main/java/com/javagetorders/services/OrderServicesImpl.java b/src/main/java/com/javagetorders/services/OrderServicesImpl.java new file mode 100644 index 0000000..a3fdab4 --- /dev/null +++ b/src/main/java/com/javagetorders/services/OrderServicesImpl.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class OrderServicesImpl +{ +} diff --git a/src/main/java/com/javagetorders/services/PaymentServices.java b/src/main/java/com/javagetorders/services/PaymentServices.java new file mode 100644 index 0000000..2878310 --- /dev/null +++ b/src/main/java/com/javagetorders/services/PaymentServices.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class PaymentServices +{ +} diff --git a/src/main/java/com/javagetorders/services/PaymentServicesImpl.java b/src/main/java/com/javagetorders/services/PaymentServicesImpl.java new file mode 100644 index 0000000..717e69f --- /dev/null +++ b/src/main/java/com/javagetorders/services/PaymentServicesImpl.java @@ -0,0 +1,5 @@ +package com.javagetorders.services; + +public class PaymentServicesImpl +{ +} From 8f021186d199e2b9b2f8eb6ae6eb700544b79784 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 5 Nov 2020 00:12:33 -0700 Subject: [PATCH 4/6] CustomerController added --- .../controllers/CustomerController.java | 50 +++++++++++++------ .../java/com/javagetorders/models/Agent.java | 2 +- .../javagetorders/services/AgentServices.java | 7 ++- .../services/AgentServicesImpl.java | 23 ++++++++- .../services/CustomerServices.java | 15 +++++- .../services/CustomerServicesImpl.java | 44 +++++++++++++++- .../javagetorders/services/OrderServices.java | 16 +++++- .../services/OrderServicesImpl.java | 31 +++++++++++- .../services/PaymentServices.java | 2 +- .../services/PaymentServicesImpl.java | 13 ++++- 10 files changed, 179 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/javagetorders/controllers/CustomerController.java b/src/main/java/com/javagetorders/controllers/CustomerController.java index 57e03bf..54c9d6f 100644 --- a/src/main/java/com/javagetorders/controllers/CustomerController.java +++ b/src/main/java/com/javagetorders/controllers/CustomerController.java @@ -1,30 +1,52 @@ package com.javagetorders.controllers; +import com.javagetorders.models.Customer; +import com.javagetorders.services.CustomerServices; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequestMapping("/customers") public class CustomerController { @Autowired + private CustomerServices customerService; - // http://localhost:2019/customers/orders - @GetMapping(value = "/orders", produces = {"application/json"}) - public ResponseEntity listAllOrders() + @GetMapping(value = "/orders", + produces = {"application/json"}) + public ResponseEntity listAllCustomers() { - List rtnList = + List myCustomers = customerService.findAllCustomers(); + return new ResponseEntity<>(myCustomers, + HttpStatus.OK); } - // http://localhost:2019/customers/customer/7 - - // http://localhost:2019/cusomters/customer/77 - - // http://localhost:2019/customers/namelike/mes - - // http://localhost:2019/agents/agent/9 - - // http://localhost:2019/orders/order/7 + @GetMapping(value = "/customer/{custid}", + produces = {"application/json"}) + public ResponseEntity getCustomerById( + @PathVariable + long custid) + { + Customer c = customersService.findCustomersById(custid); + return new ResponseEntity<>(c, + HttpStatus.OK); + } - // http://localhost:2019/orders/advanceamount + @GetMapping(value = "/namelike/{custname}", + produces = {"application/json"}) + public ResponseEntity findCustomerByName( + @PathVariable + String custname) + { + List myCustomerList = customersService.findByCustomerName(custname); + return new ResponseEntity<>(myCustomerList, + HttpStatus.OK); + } } diff --git a/src/main/java/com/javagetorders/models/Agent.java b/src/main/java/com/javagetorders/models/Agent.java index aa4fafd..d9a14ce 100644 --- a/src/main/java/com/javagetorders/models/Agent.java +++ b/src/main/java/com/javagetorders/models/Agent.java @@ -1,4 +1,4 @@ -package com.lambdaschool.orders.models; +package com.javagetorders.models; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/src/main/java/com/javagetorders/services/AgentServices.java b/src/main/java/com/javagetorders/services/AgentServices.java index f1350ae..e6765aa 100644 --- a/src/main/java/com/javagetorders/services/AgentServices.java +++ b/src/main/java/com/javagetorders/services/AgentServices.java @@ -1,5 +1,8 @@ package com.javagetorders.services; -public class AgentServices +import com.javagetorders.models.Agent; + +public interface AgentServices { -} + Agent findAgentById(long id); +} \ No newline at end of file diff --git a/src/main/java/com/javagetorders/services/AgentServicesImpl.java b/src/main/java/com/javagetorders/services/AgentServicesImpl.java index 1d6c07d..bd12753 100644 --- a/src/main/java/com/javagetorders/services/AgentServicesImpl.java +++ b/src/main/java/com/javagetorders/services/AgentServicesImpl.java @@ -1,5 +1,26 @@ package com.javagetorders.services; -public class AgentServicesImpl +import com.javagetorders.models.Agent; +import com.javagetorders.repositories.AgentRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityNotFoundException; + +@Transactional +@Service(value = "agentsService") +public class AgentServiceImpl + implements AgentService { + @Autowired + private AgentRepository agentsrepos; + + @Override + public Agent findAgentById(long id) throws + EntityNotFoundException + { + return agentsrepos.findById(id) + .orElseThrow(() -> new EntityNotFoundException("Agent Id " + id + " Not Found")); + } } diff --git a/src/main/java/com/javagetorders/services/CustomerServices.java b/src/main/java/com/javagetorders/services/CustomerServices.java index 770ac58..4723f4e 100644 --- a/src/main/java/com/javagetorders/services/CustomerServices.java +++ b/src/main/java/com/javagetorders/services/CustomerServices.java @@ -1,5 +1,18 @@ package com.javagetorders.services; -public class CustomerServices +import com.javagetorders.models.Customer; + +import java.util.List; + + +public interface CustomerServices { + + List findAllCustomers(); + + + List findByCustomerName(String custname); + + + Customer findCustomersById(long id); } diff --git a/src/main/java/com/javagetorders/services/CustomerServicesImpl.java b/src/main/java/com/javagetorders/services/CustomerServicesImpl.java index 9bdf52c..54a3e45 100644 --- a/src/main/java/com/javagetorders/services/CustomerServicesImpl.java +++ b/src/main/java/com/javagetorders/services/CustomerServicesImpl.java @@ -1,5 +1,47 @@ package com.javagetorders.services; -public class CustomerServicesImpl +import com.javagetorders.models.Customer; +import com.javagetorders.repositories.CustomerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityNotFoundException; +import java.util.ArrayList; +import java.util.List; + + +@Transactional +@Service(value = "customersService") +public class CustomerServiceImpl + implements CustomerService { + + @Autowired + private CustomerRepository custrepos; + + @Override + public List findAllCustomers() + { + List list = new ArrayList<>(); + + custrepos.findAll() + .iterator() + .forEachRemaining(list::add); + return list; + } + + @Override + public List findByCustomerName(String custname) + { + return custrepos.findByCustnameContainingIgnoringCase(custname); + } + + @Override + public Customer findCustomersById(long id) throws + EntityNotFoundException + { + return custrepos.findById(id) + .orElseThrow(() -> new EntityNotFoundException("Customer " + id + " Not Found")); + } } diff --git a/src/main/java/com/javagetorders/services/OrderServices.java b/src/main/java/com/javagetorders/services/OrderServices.java index b262b9d..5a0d627 100644 --- a/src/main/java/com/javagetorders/services/OrderServices.java +++ b/src/main/java/com/javagetorders/services/OrderServices.java @@ -1,5 +1,19 @@ package com.javagetorders.services; -public class OrderServices +import com.javagetorders.models.Order; + +import java.util.List; + +public interface OrdersServices { + + List findOrdersWithAdvanceAmount(); + + /** + * Returns the order with the given primary key. + * + * @param id The primary key (long) of the order you seek. + * @return The given order or throws an exception if not found. + */ + Order findOrdersById(long id); } diff --git a/src/main/java/com/javagetorders/services/OrderServicesImpl.java b/src/main/java/com/javagetorders/services/OrderServicesImpl.java index a3fdab4..84ca9b1 100644 --- a/src/main/java/com/javagetorders/services/OrderServicesImpl.java +++ b/src/main/java/com/javagetorders/services/OrderServicesImpl.java @@ -1,5 +1,34 @@ package com.javagetorders.services; -public class OrderServicesImpl +import com.javagetorders.models.Order; +import com.javagetorders.repositories.OrdersRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityNotFoundException; +import java.util.List; + + +@Transactional +@Service(value = "ordersService") +public class OrdersServiceImpl + implements OrdersService { + @Autowired + private OrdersRepository ordersrepos; + + @Override + public List findOrdersWithAdvanceAmount() + { + return ordersrepos.findAllByAdvanceamountGreaterThan(0.00); + } + + @Override + public Order findOrdersById(long id) throws + EntityNotFoundException + { + return ordersrepos.findById(id) + .orElseThrow(() -> new EntityNotFoundException("Order " + id + " Not Found")); + } } diff --git a/src/main/java/com/javagetorders/services/PaymentServices.java b/src/main/java/com/javagetorders/services/PaymentServices.java index 2878310..9799fae 100644 --- a/src/main/java/com/javagetorders/services/PaymentServices.java +++ b/src/main/java/com/javagetorders/services/PaymentServices.java @@ -1,5 +1,5 @@ package com.javagetorders.services; -public class PaymentServices +public interface PaymentServices { } diff --git a/src/main/java/com/javagetorders/services/PaymentServicesImpl.java b/src/main/java/com/javagetorders/services/PaymentServicesImpl.java index 717e69f..1c84c82 100644 --- a/src/main/java/com/javagetorders/services/PaymentServicesImpl.java +++ b/src/main/java/com/javagetorders/services/PaymentServicesImpl.java @@ -1,5 +1,16 @@ package com.javagetorders.services; +import com.javagetorders.repositories.PaymentRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Transactional +@Service(value = "paymentService") public class PaymentServicesImpl + implements PaymentServices { -} + @Autowired + PaymentRepository paymentrepos; +} \ No newline at end of file From 152b09a536b0d29b55bd1fe0445b0be3f73f7ff4 Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 5 Nov 2020 00:17:08 -0700 Subject: [PATCH 5/6] All controllers added --- .../controllers/AgentController.java | 31 +++++++++++++ .../controllers/OrderController.java | 43 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/main/java/com/javagetorders/controllers/AgentController.java create mode 100644 src/main/java/com/javagetorders/controllers/OrderController.java diff --git a/src/main/java/com/javagetorders/controllers/AgentController.java b/src/main/java/com/javagetorders/controllers/AgentController.java new file mode 100644 index 0000000..b42ddc2 --- /dev/null +++ b/src/main/java/com/javagetorders/controllers/AgentController.java @@ -0,0 +1,31 @@ +package com.javagetorders.controllers; + +import com.javagetorders.models.Agent; +import com.javagetorders.services.AgentServices; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("/agents") +public class AgentController +{ + @Autowired + AgentServices agentsService; + + @GetMapping(value = "/agent/{agentid}") + public ResponseEntity getAgentById( + @PathVariable + long agentid) + { + + Agent a = agentsService.findAgentById(agentid); + return new ResponseEntity<>(a, + HttpStatus.OK); + } +} diff --git a/src/main/java/com/javagetorders/controllers/OrderController.java b/src/main/java/com/javagetorders/controllers/OrderController.java new file mode 100644 index 0000000..c39ee17 --- /dev/null +++ b/src/main/java/com/javagetorders/controllers/OrderController.java @@ -0,0 +1,43 @@ +package com.javagetorders.controllers; + +import com.javagetorders.models.Order; +import com.javagetorders.services.OrderServices; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + + +@RestController +@RequestMapping("/orders") +public class OrderController +{ + + @Autowired + OrderServices orderService; + + @GetMapping(value = "/advanceamount") + public ResponseEntity getOrdersWithAdvanceAmount() + { + List myOrderList = ordersService.findOrdersWithAdvanceAmount(); + return new ResponseEntity<>(myOrderList, + HttpStatus.OK); + } + + @GetMapping(value = "/order/{ordernum}", + produces = {"application/json"}) + public ResponseEntity getOrderByNumber( + @PathVariable + long ordernum) + { + Order o = ordersService.findOrdersById(ordernum); + return new ResponseEntity<>(o, + HttpStatus.OK); + } +} + From d6c922317ec7e41de46057fad0fd2120336b54af Mon Sep 17 00:00:00 2001 From: Simone Ballard Date: Thu, 5 Nov 2020 00:36:33 -0700 Subject: [PATCH 6/6] pathway errors --- .../java/com/javagetorders/config/H2ServerConfiguration.java | 2 +- src/main/java/com/javagetorders/models/Customer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/javagetorders/config/H2ServerConfiguration.java b/src/main/java/com/javagetorders/config/H2ServerConfiguration.java index 3ff7ee2..ff73d40 100644 --- a/src/main/java/com/javagetorders/config/H2ServerConfiguration.java +++ b/src/main/java/com/javagetorders/config/H2ServerConfiguration.java @@ -1,4 +1,4 @@ -package com.lambdaschool.orders.config; +package com.javagetorders.config; import org.h2.tools.Server; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/javagetorders/models/Customer.java b/src/main/java/com/javagetorders/models/Customer.java index d494428..dee699a 100644 --- a/src/main/java/com/javagetorders/models/Customer.java +++ b/src/main/java/com/javagetorders/models/Customer.java @@ -1,4 +1,4 @@ -package com.lambdaschool.orders.models; +package com.javagetorders.models; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;