From e30279c16aa655df54328bc88bb4890682be417f Mon Sep 17 00:00:00 2001 From: Santiago Schumacher Date: Tue, 10 Feb 2015 17:09:48 -0300 Subject: [PATCH] Bootcamp final project santiagos --- FinalProject/finalproject.mwb | Bin 0 -> 8921 bytes FinalProject/pom.xml | 68 ++++++++++ .../data/jpa/FinalProjectBootcamp.java | 18 +++ .../data/jpa/domain/Itemtobuy.java | 63 +++++++++ .../finalproject/data/jpa/domain/Product.java | 68 ++++++++++ .../data/jpa/domain/Shoppingcart.java | 46 +++++++ .../finalproject/data/jpa/domain/User.java | 50 +++++++ .../data/jpa/service/ItemToBuyRepository.java | 25 ++++ .../data/jpa/service/ProductRepository.java | 22 +++ .../data/jpa/service/ProductService.java | 27 ++++ .../data/jpa/service/ProductServiceImp.java | 35 +++++ .../jpa/service/ShoppingCartRepository.java | 36 +++++ .../data/jpa/service/ShoppingService.java | 59 ++++++++ .../data/jpa/service/ShoppingServiceImpl.java | 127 ++++++++++++++++++ .../data/jpa/service/UserRepository.java | 11 ++ .../data/jpa/service/UserService.java | 35 +++++ .../data/jpa/service/UserServiceImpl.java | 55 ++++++++ .../finalproject/data/jpa/web/Controller.java | 86 ++++++++++++ .../src/main/resources/application.properties | 5 + 19 files changed, 836 insertions(+) create mode 100644 FinalProject/finalproject.mwb create mode 100644 FinalProject/pom.xml create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/FinalProjectBootcamp.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Itemtobuy.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Product.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Shoppingcart.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/User.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ItemToBuyRepository.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductRepository.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductService.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductServiceImp.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingCartRepository.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingService.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingServiceImpl.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserRepository.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserService.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserServiceImpl.java create mode 100644 FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/web/Controller.java create mode 100644 FinalProject/src/main/resources/application.properties diff --git a/FinalProject/finalproject.mwb b/FinalProject/finalproject.mwb new file mode 100644 index 0000000000000000000000000000000000000000..2c29e2435112e19f8fa6a1f3dd31e979b900b415 GIT binary patch literal 8921 zcmZ{~b8sfWw=Ejy3nn(d*v?FB+t$RkZB1<3wl&EY+nLz5C%$vez4gxTy}GZvx^~y@ zz5eOyRn>d1ttbNtg#iWz1^`2iloqFZO=t@t0s|XL1qVa<=QXi6cC|INb78b~H)8a# zwYk*OabM?5^vg5Y-S=J1(Q9{vZ75s!21B{H#T^-2leeEyL86#rrAjO>C@0V5zu(4A zHqmi&A)y&;wRsZJHVRTkb$zJ}5Z*ohdig;>;3IV>l^Ns5B`R@q;~)F=;LOCh7wo6+ z(>Z=;sQc~|v1vf?(0JvN9{o#UXo~aY@Md#r=qs1#-5}NfioEFRvA?T24G}3Va*oW) z57 z+!G)W#S&YN$!_A4q>4SY`$4+_6&POU^yV@_7izgNv%edZw)MV#a8m{!jp8&S$;9CA zBwomqgR#o&0w54heH!vG`5ednL&1)_ECOnw%yp&AO;>KW+~LpC>kt00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P)FDoR`K4 zXys&2aS_;&&c-Z{r~F!hN$A6;#ZyfvISTL~Gz{Y>QBLBs>|3v)X*!Dk&wSS2J;GUuk^nbAz z4D#Qs_-B_%z`#Vo3;h2A{7U2f literal 0 HcmV?d00001 diff --git a/FinalProject/pom.xml b/FinalProject/pom.xml new file mode 100644 index 00000000..31094d7a --- /dev/null +++ b/FinalProject/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 1.2.1.RELEASE + + + + UTF-8 + com.javabootcamp.finalproject.data.jpa.main.FinalProjectBootcamp + 1.8 + + + FinalProject + com.javabootcamp + Java bootcamp final project + Spring Boot Data JPA Sample + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + + + org.hibernate + hibernate-entitymanager + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-web + jar + + + org.springframework + spring-webmvc + jar + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/FinalProjectBootcamp.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/FinalProjectBootcamp.java new file mode 100644 index 00000000..bd4bf55d --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/FinalProjectBootcamp.java @@ -0,0 +1,18 @@ + +package com.javabootcamp.finalproject.data.jpa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +/** + * Class with main method, starts the application + * @author Santiago + */ +@SpringBootApplication +public class FinalProjectBootcamp { + + public static void main(String[] args) throws Exception { + SpringApplication.run(FinalProjectBootcamp.class, args); + + } + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Itemtobuy.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Itemtobuy.java new file mode 100644 index 00000000..dfc3f28a --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Itemtobuy.java @@ -0,0 +1,63 @@ + +package com.javabootcamp.finalproject.data.jpa.domain; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.PrimaryKeyJoinColumn; +import org.hibernate.annotations.NaturalId; + +@Entity +public class Itemtobuy implements Serializable { + + @Id + @GeneratedValue + private Long iditem; + + @NaturalId + @PrimaryKeyJoinColumn(referencedColumnName = "idshoppingcart") + private Long idcart; + + @NaturalId + @PrimaryKeyJoinColumn(referencedColumnName = "idproduct") + private Long idprod; + + @Column(nullable = false) + private int quantity; + + protected Itemtobuy(){} + + public Itemtobuy (Long idcart, Long idprod, int quantity){ + this.idcart = idcart; + this.idprod = idprod; + this.quantity = quantity; + } + + public Long getIdcart() { + return idcart; + } + + public void setIdcart(Long ids) { + this.idcart = ids; + } + + public Long getIdprod() { + return idprod; + } + + public void setIdprod(Long idprod) { + this.idprod = idprod; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Product.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Product.java new file mode 100644 index 00000000..68e51906 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Product.java @@ -0,0 +1,68 @@ + +package com.javabootcamp.finalproject.data.jpa.domain; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Product implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + @Column(name="idproduct") + private Long idproduct; + + @Column(nullable=false) + private String name; + + @Column(nullable=false) + private String category; + + @Column(nullable=false) + private double price; + + protected Product(){} + + public Product(String name, String category){ + this.name = name; + this.category = category; + } + + public Long getId() { + return idproduct; + } + + public String getName() { + return name; + } + + public String getCategory() { + return category; + } + + @Override + public String toString() { + return "Product{" + "id=" + idproduct + ", name=" + name + ", category=" + category + '}'; + } + + public void setName(String name) { + this.name = name; + } + + public void setCategory(String category) { + this.category = category; + } + + public void setPrice(double p){ + this.price = p; + } + + public double getPrice(){ + return price; + } +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Shoppingcart.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Shoppingcart.java new file mode 100644 index 00000000..275a88f6 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/Shoppingcart.java @@ -0,0 +1,46 @@ + +package com.javabootcamp.finalproject.data.jpa.domain; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.PrimaryKeyJoinColumn; + + +@Entity +public class Shoppingcart implements Serializable { + + @Id + @PrimaryKeyJoinColumn(referencedColumnName = "iduser") + private Long idshoppingcart; + + @Column(nullable = false) + private double total; + + protected Shoppingcart(){} + + public Shoppingcart(Long id, double total){ + this.idshoppingcart = id; + this.total = total; + } + + public Long getUserid() { + return idshoppingcart; + } + + public void setUserid(Long userid) { + this.idshoppingcart = userid; + } + + + public double getTotal() { + return total; + } + + public void setTotal(double num) { + this.total = num; + } + + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/User.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/User.java new file mode 100644 index 00000000..3a8e7930 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/domain/User.java @@ -0,0 +1,50 @@ + +package com.javabootcamp.finalproject.data.jpa.domain; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class User implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + @Column( name = "iduser") + private Long iduser; + + @Column(nullable = false) + private String username; + + @Column(nullable = false) + private String password; + + protected User(){} + + public User(String username, String password){ + this.username = username; + this.password = password; + } + + @Override + public String toString() { + return "User{" + ", username=" + username + ", password=" + password + ", administrator=" +'}'; + } + + public Long getId() { + return iduser; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ItemToBuyRepository.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ItemToBuyRepository.java new file mode 100644 index 00000000..0fd696c9 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ItemToBuyRepository.java @@ -0,0 +1,25 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Itemtobuy; +import java.util.List; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface ItemToBuyRepository extends CrudRepository { + + @Query("Select p.name, i.quantity from Product p, Itemtobuy i where i.idprod = ?1 and i.idprod = p.idproduct" ) + public String findAllProductsById(Long id); + + @Query("from Itemtobuy i where idcart = ?1 and idprod = ?2 ") + public Itemtobuy findByShopId(Long id, Long idprod); + + @Query("Select i.idprod from Itemtobuy i where i.idcart = ?1") + public List getIdItemsInCart(Long id); + + @Modifying + @Query("Delete from Itemtobuy i where i.idcart = ?1") + public void deleteAllById(Long id); + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductRepository.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductRepository.java new file mode 100644 index 00000000..a2909a62 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductRepository.java @@ -0,0 +1,22 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import java.util.List; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface ProductRepository extends CrudRepository{ + + Product findByIdproduct(Long productid); + + List findAll(); + + @Query("Select idproduct from Product p where p.name = ?1") + Long getIdproductByName(String name); + + @Query("Select price from Product p where p.idproduct = ?1") + public double getPriceForId(Long idprod); + + List findAllByCategory(String category); +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductService.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductService.java new file mode 100644 index 00000000..53451556 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductService.java @@ -0,0 +1,27 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import java.util.List; + +public interface ProductService { + /** + * Returns product with the given id + * @param productid + * @return + */ + Product findByIdproduct(Long productid); + + /** + * Returns list with all products + * @return + */ + List findAll(); + + /** + * Returns list with the products of the given category + * @param category + * @return + */ + List findAllByCategory(String category); +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductServiceImp.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductServiceImp.java new file mode 100644 index 00000000..a7e7488f --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ProductServiceImp.java @@ -0,0 +1,35 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +@Service("productService") +public class ProductServiceImp implements ProductService { + + private final ProductRepository productrepository; + + @Autowired + public ProductServiceImp(ProductRepository productrepository){ + this.productrepository = productrepository; + } + + @Override + public Product findByIdproduct(Long productid) { + Assert.notNull(productid, "Product if must not be null"); + return this.productrepository.findByIdproduct(productid); + } + + @Override + public List findAll(){ + return this.productrepository.findAll(); + } + + @Override + public List findAllByCategory(String category){ + return this.productrepository.findAllByCategory(category); + } +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingCartRepository.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingCartRepository.java new file mode 100644 index 00000000..15791e7a --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingCartRepository.java @@ -0,0 +1,36 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Shoppingcart; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface ShoppingCartRepository extends CrudRepository { + + @Query("Select sp.idshoppingcart from Shoppingcart sp where sp.idshoppingcart = ?1") + public Long getShoppingCartId(Long id); + + @Modifying + @Query(value = "Insert into Itemtobuy(idcart, idprod, quantity) values (?1, ?2, ?3)", nativeQuery = true) + public void addItemToBuy(Long id,Long idprod,int i); + + @Modifying + @Query("Update Itemtobuy i set quantity = (quantity - ?1) where i.idcart = ?2 AND i.idprod = ?3") + public void removeItemToBuy(int quantity, Long id, Long idprod); + + @Modifying + @Query("Update Shoppingcart s set total = (total + (?2 * ?3)) where s.idshoppingcart = ?1") + public void addTotal(Long id, double price, int quantity); + + @Query("Select s.total from Shoppingcart s where s.idshoppingcart = ?1") + public double findTotalByIdshoppingcart(Long id); + + @Modifying + @Query("Update Shoppingcart s set total = (total - (?2 * ?3)) where s.idshoppingcart = ?1") + public void removeFromTotal(Long id, int quantity, double price); + + @Modifying + @Query("Update Shoppingcart s set total = 0 where s.idshoppingcart = ?1") + public void clearTotal(Long id); +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingService.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingService.java new file mode 100644 index 00000000..71b98107 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingService.java @@ -0,0 +1,59 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import com.javabootcamp.finalproject.data.jpa.domain.Shoppingcart; +import org.springframework.transaction.annotation.Transactional; + +public interface ShoppingService { + + /** + * Adds single item to cart given an product name + * @param name + * @param username + * @param password + * @return + */ + @Transactional + Product addToCart(String name, String username, String password); + /** + * Adds items to cart given by product name and quantity + * @param quantity + * @param name + * @param username + * @param password + * @return + */ + @Transactional + Product addToCartItems(int quantity, String name, String username, String password); + /** + * Removes an item from cart given by product name and quantity + * @param quantity + * @param name + * @param username + * @param password + * @return + */ + @Transactional + String removeFromCart(int quantity, String name, String username, String password); + /** + * Saves cart + * @param s + */ + void save(Shoppingcart s); + /** + * Returns cart of given user + * @param username + * @param password + * @return + */ + String getCart(String username, String password); + /** + * Empty cart of the given user. Sets total to zero and deletes items in cart. + * @param username + * @param password + * @return + */ + @Transactional + public String clearCart(String username, String password); +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingServiceImpl.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingServiceImpl.java new file mode 100644 index 00000000..9dda239c --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/ShoppingServiceImpl.java @@ -0,0 +1,127 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Itemtobuy; +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import com.javabootcamp.finalproject.data.jpa.domain.Shoppingcart; +import com.javabootcamp.finalproject.data.jpa.domain.User; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service("shoppingCartService") +public class ShoppingServiceImpl implements ShoppingService { + + private final ShoppingCartRepository shoppingRepository; + private final UserRepository userRepository; + private final ProductRepository productRepository; + private final ItemToBuyRepository itemToBuyRepository; + + @Autowired + public ShoppingServiceImpl(ShoppingCartRepository shoppingRepository,UserRepository userRepository, ProductRepository productRepository, ItemToBuyRepository itemToBuyRepository){ + this.shoppingRepository = shoppingRepository; + this.userRepository = userRepository; + this.productRepository = productRepository; + this.itemToBuyRepository = itemToBuyRepository; + } + + @Override + public Product addToCart(String name, String username, String password) { + User u = this.userRepository.getUserByUsername(username); + if (u.getPassword().equals(password)){ + Long id = this.shoppingRepository.getShoppingCartId(u.getId()); + Long idprod = this.productRepository.getIdproductByName(name); + double price = this.productRepository.getPriceForId(idprod); + Itemtobuy i = new Itemtobuy(id, idprod, 1); + this.itemToBuyRepository.save(i); + + this.shoppingRepository.addTotal(id, price, 1); + + return this.productRepository.findByIdproduct(idprod); + } else { + throw new IllegalArgumentException ("Username and password does not match"); + } + } + + @Override + public Product addToCartItems(int quantity, String name, String username, String password) { + if (quantity < 1){ + throw new IllegalArgumentException ("Please insert a valid quantity value"); + } else { + User u = this.userRepository.getUserByUsername(username); + if (u.getPassword().equals(password)){ + Long id = this.shoppingRepository.getShoppingCartId(u.getId()); + Long idprod = this.productRepository.getIdproductByName(name); + double price = this.productRepository.getPriceForId(idprod); + + Itemtobuy i = new Itemtobuy(id, idprod, quantity); + this.itemToBuyRepository.save(i); + + this.shoppingRepository.addTotal(id, price, quantity); + return this.productRepository.findByIdproduct(idprod); + } else { + throw new IllegalArgumentException ("Username and password does not match"); + } + } + } + + @Override + public String removeFromCart(int quantity, String name, String username, String password) { + User u = this.userRepository.getUserByUsername(username); + if (u.getPassword().equals(password)){ + Long id = this.shoppingRepository.getShoppingCartId(u.getId()); + Long idprod = this.productRepository.getIdproductByName(name); + Itemtobuy i = this.itemToBuyRepository.findByShopId(id, idprod); + if (quantity > i.getQuantity()) { + throw new IllegalArgumentException ("Given quantity is greater than quantity in cart"); + } else { + double price = this.productRepository.getPriceForId(idprod); + this.shoppingRepository.removeFromTotal(id, quantity, price); + this.shoppingRepository.removeItemToBuy(quantity, id,idprod); + return "Removed item from cart"; + } + } else { + throw new IllegalArgumentException ("Username and password does not match"); + } + } + + @Override + public void save(Shoppingcart s){ + this.shoppingRepository.save(s); + } + + @Override + public String getCart(String username, String password) { + User u = this.userRepository.getUserByUsername(username); + if (u.getPassword().equals(password)){ + Long id = this.shoppingRepository.getShoppingCartId(u.getId()); + StringBuilder sb = new StringBuilder(); + + List idlist = this.itemToBuyRepository.getIdItemsInCart(id); + + for (int i = 0; i < idlist.size(); i++){ + sb.append(this.itemToBuyRepository.findAllProductsById(idlist.get(i))); + sb.append(", "); + } + sb.append(" Total: $"); + sb.append(this.shoppingRepository.findTotalByIdshoppingcart(id)); + return sb.toString(); + } else{ + throw new IllegalArgumentException ("Username and password does not match"); + } + } + + @Override + public String clearCart(String username, String password) { + User u = this.userRepository.getUserByUsername(username); + if (u.getPassword().equals(password)){ + Long id = this.shoppingRepository.getShoppingCartId(u.getId()); + this.itemToBuyRepository.deleteAllById(id); + this.shoppingRepository.clearTotal(id); + + return "Shopping cart cleared"; + }else{ + throw new IllegalArgumentException ("Username and password does not match"); + } + } +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserRepository.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserRepository.java new file mode 100644 index 00000000..4a56a24b --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserRepository.java @@ -0,0 +1,11 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.User; +import org.springframework.data.repository.CrudRepository; + +public interface UserRepository extends CrudRepository { + + User getUserByUsername(String username); + +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserService.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserService.java new file mode 100644 index 00000000..8657a402 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserService.java @@ -0,0 +1,35 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.User; +import org.springframework.transaction.annotation.Transactional; + +public interface UserService { + /** + * Creates a new user and assigns a shopping cart + * @param username Username. Must be at least 6 characters + * @param password Password. Must be at least 6 characters + * @return Returns User object + */ + @Transactional + User createUser(String username, String password); + /** + * Deletes user with the given username + * @param username + * @param password + * @return + */ + String deleteUser(String username, String password); + /** + * Creates a Shopping cart. This method is called when creating a new user + * @param u + */ + @Transactional + void createCart(User u); + /** + * Returns Id given an username + * @param username + * @return + */ + Long getIdByUsername(String username); +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserServiceImpl.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserServiceImpl.java new file mode 100644 index 00000000..4b65353f --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/service/UserServiceImpl.java @@ -0,0 +1,55 @@ + +package com.javabootcamp.finalproject.data.jpa.service; + +import com.javabootcamp.finalproject.data.jpa.domain.Shoppingcart; +import com.javabootcamp.finalproject.data.jpa.domain.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service("userService") +public class UserServiceImpl implements UserService { + + private final UserRepository userrepository; + private final ShoppingCartRepository shoppingRepository; + + @Autowired + public UserServiceImpl(UserRepository userrepository, ShoppingCartRepository shoppingRepository) { + this.userrepository = userrepository; + this.shoppingRepository = shoppingRepository; + } + + @Override + public User createUser(String username, String password) { + if( username.length() < 6 || password.length() < 6){ + throw new IllegalArgumentException ("Username and password must be at least 6 chars"); + } else { + User user = new User(username, password); + this.userrepository.save(user); + createCart(user); + return user; + } + } + + @Override + public void createCart(User u){ + Shoppingcart sp = new Shoppingcart(u.getId(), 0); + this.shoppingRepository.save(sp); + } + + @Override + public String deleteUser(String username, String password) { + User user = new User(username, password); + this.userrepository.delete(user); + StringBuilder sb = new StringBuilder(); + sb.append("Username: "); + sb.append(username); + sb.append(" deleted."); + return sb.toString(); + } + + @Override + public Long getIdByUsername(String username) { + User u = this.userrepository.getUserByUsername(username); + return u.getId(); + } +} diff --git a/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/web/Controller.java b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/web/Controller.java new file mode 100644 index 00000000..dd896357 --- /dev/null +++ b/FinalProject/src/main/java/com/javabootcamp/finalproject/data/jpa/web/Controller.java @@ -0,0 +1,86 @@ + +package com.javabootcamp.finalproject.data.jpa.web; + +import com.javabootcamp.finalproject.data.jpa.domain.Product; +import com.javabootcamp.finalproject.data.jpa.domain.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import com.javabootcamp.finalproject.data.jpa.service.ProductService; +import com.javabootcamp.finalproject.data.jpa.service.ShoppingService; +import com.javabootcamp.finalproject.data.jpa.service.UserService; +import java.util.List; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class Controller { + + @Autowired + private ProductService productService; + + @Autowired + private UserService userService; + + @Autowired + private ShoppingService shoppingService; + + @RequestMapping(value = "/shop/product", method = RequestMethod.GET) + @ResponseBody + @Transactional(readOnly = true) + public List findAll() { + return this.productService.findAll(); + } + + @RequestMapping(value = "/shop/product/id/{productid}", method = RequestMethod.GET) + @ResponseBody + @Transactional(readOnly = true) + public Product findById(@PathVariable int productid){ + Long x = (long) productid; + return this.productService.findByIdproduct(x); + + } + + @RequestMapping(value = "/shop/product/category/{category}", method = RequestMethod.GET) + @ResponseBody + @Transactional(readOnly = true) + public List findAllByCategory(@PathVariable String category){ + return this.productService.findAllByCategory(category); + } + + @RequestMapping(value = "/shop/user", method = RequestMethod.POST) + public User createUser(@RequestParam String username, @RequestParam String password){ + return this.userService.createUser(username, password); + } + + @RequestMapping(value = "/shop/{name}", method = RequestMethod.PUT) + public Product addToCart(@PathVariable String name, @RequestParam String username, @RequestParam String password){ + return this.shoppingService.addToCart(name, username, password); + } + + @RequestMapping(value = "/shop/item/{name}", method = RequestMethod.PUT) + public Product addToCartItems(@PathVariable String name,@RequestParam int quantity, @RequestParam String username, @RequestParam String password){ + return this.shoppingService.addToCartItems(quantity,name, username, password); + } + + @RequestMapping(value = "/shop/{name}", method = RequestMethod.DELETE) + public String removeFromCart(@PathVariable String name, @RequestParam int quantity, @RequestParam String username, @RequestParam String password){ + return this.shoppingService.removeFromCart(quantity, name, username, password); + } + + + @RequestMapping(value = "/shop/user", method = RequestMethod.GET) + public String getCart(@RequestParam String username, @RequestParam String password){ + return this.shoppingService.getCart(username, password); + } + + @RequestMapping(value = "/shop/user/clear", method = RequestMethod.DELETE) + public String clearCart(@RequestParam String username, @RequestParam String password){ + return this.shoppingService.clearCart(username, password); + } + + +} diff --git a/FinalProject/src/main/resources/application.properties b/FinalProject/src/main/resources/application.properties new file mode 100644 index 00000000..0ce8e64d --- /dev/null +++ b/FinalProject/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.datasource.driverClassName=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/shoppingcart +spring.datasource.username=root +spring.datasource.password=mysql +hibernate.hbm2dll.auto=update