diff --git a/finalProject/shopcart/.gitignore b/finalProject/shopcart/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/finalProject/shopcart/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/finalProject/shopcart/nb-configuration.xml b/finalProject/shopcart/nb-configuration.xml new file mode 100644 index 00000000..ae15d8b6 --- /dev/null +++ b/finalProject/shopcart/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + JDK 1.7 + + diff --git a/finalProject/shopcart/pom.xml b/finalProject/shopcart/pom.xml new file mode 100644 index 00000000..83536dfc --- /dev/null +++ b/finalProject/shopcart/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + javabootcamp + shopcart + 1.0.0-SNAPSHOT + war + + shopcart + + org.springframework.boot + spring-boot-starter-parent + 1.2.1.RELEASE + + + javabootcamp.shopcart.Application + UTF-8 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.hibernate + hibernate-entitymanager + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-security + + + org.apache.derby + derby + 10.11.1.1 + + + mysql + mysql-connector-java + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + + + + + + + diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/Application.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/Application.java new file mode 100644 index 00000000..ac77050d --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/Application.java @@ -0,0 +1,17 @@ +package javabootcamp.shopcart; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * + * Class with main method, starts the application + * + * @author roberta + */ + +@SpringBootApplication +public class Application{ + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/CartController.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/CartController.java new file mode 100644 index 00000000..8859127d --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/CartController.java @@ -0,0 +1,136 @@ +package javabootcamp.shopcart; + +import java.math.BigDecimal; +import java.util.List; +import javabootcamp.shopcart.model.Category; +import javabootcamp.shopcart.model.PaymentType; +import javabootcamp.shopcart.model.Product; +import javabootcamp.shopcart.model.ShopCart; +import javabootcamp.shopcart.model.ShopCartItem; +import javabootcamp.shopcart.repository.CategoryRepository; +import javabootcamp.shopcart.repository.ItemRepository; +import javabootcamp.shopcart.repository.ProductRepository; +import javabootcamp.shopcart.repository.ShopCartRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author roberta + */ + + +@RestController(value = "shop") +public class CartController { + private ShopCart cart; + private ConfigurableApplicationContext context; + @Autowired + private ProductRepository productRepository; + @Autowired + private ShopCartRepository cartRepository; + @Autowired + private ItemRepository itemRepository; + @Autowired + private CategoryRepository categoryRepository; + + @RequestMapping("/ping") + public String getGreeting() { + return "Hello World!"; + } + + @RequestMapping("/createCart") + public String createCart() { + if (cart == null) { + cart = new ShopCart(); + return "Cart created succesfully!"; + } else { + return "Cart already created!"; + } + } + + @RequestMapping("/addProduct") + public boolean addProduct(@RequestParam(value = "idProd", required = true) Long productId, + @RequestParam(value = "quantity", required = false, defaultValue = "1") Integer quantity) { + + createCart(); + Product product = productRepository.findOne(productId); + if (product == null) { + return false; + } + ShopCartItem item = new ShopCartItem(quantity, product, product.getPrice().multiply(new BigDecimal(quantity)), cart); + if (cart.getCartItems() == null) { + cart.setCartItems(new java.util.ArrayList()); + } + cart.getCartItems().add(item); + return true; + } + + @RequestMapping("/removeProduct") + public boolean removeProduct(@RequestParam(value = "idProd", required = true) Long productId) { + + int index = -1; + + for (int i = 0; i < cart.getCartItems().size(); i++) { + if (cart.getCartItems().get(i).getProduct().getId().equals(productId)) { + index = i; + } + + } + if (index > -1) { + cart.getCartItems().remove(index); + return true; + } + return false; + + } + + @RequestMapping("/listItems") + public String listCartItems() { + if (cart != null) { + StringBuilder sb = new StringBuilder(); + sb.append("Product\t\t\tQuantity\t\t\tSubTotal\n"); + for (ShopCartItem item : cart.getCartItems()) { + sb.append(item.getProduct().getName()) + .append("\t\t\t").append(item.getQuantity()) + .append("\t\t\t") + .append(item.getSubTotal().toPlainString()) + .append("\n"); + } + return sb.toString(); + } + return null; + } + + @RequestMapping("/confirm") + public String confirm(@RequestParam(value = "paymentType", required = false, defaultValue = "CASH") String paymentType) { + PaymentType payment = PaymentType.valueOf(paymentType); + if (cart != null) { + if (cart.getId() != null) { + return "You have yust checked out!"; + } + cart.setPaymentType(payment); + cartRepository.save(cart); + itemRepository.save(cart.getCartItems()); + + return "Your invoce number: " + cart.getId() + " was generated for a total of: $" + cart.getTotal().toPlainString(); + + } + return "You haven't a shop cart yet..."; + } + + @RequestMapping(value = "/findProductsByCategory", produces = "application/json") + public List findByCategory(@RequestParam(value = "categoryId", required = true) Long category) { + Category findOne = categoryRepository.findOne(category); + return productRepository.findByCategory(findOne); + } + + @RequestMapping(value = "/findProductsByName", produces = "application/json") + public List findByName(@RequestParam(value = "name") String name) { + return productRepository.findByName(name); + + } +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/MvcConfig.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/MvcConfig.java new file mode 100644 index 00000000..65526cc5 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/MvcConfig.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +public class MvcConfig extends WebMvcConfigurerAdapter { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/home").setViewName("home"); + registry.addViewController("/").setViewName("home"); + registry.addViewController("/hello").setViewName("hello"); + registry.addViewController("/login").setViewName("login"); + } + +} \ No newline at end of file diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/PersistenceContext.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/PersistenceContext.java new file mode 100644 index 00000000..7e188362 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/PersistenceContext.java @@ -0,0 +1,60 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart; + +import javax.sql.DataSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; +import java.util.Properties; + +/** + * + * @author roberta + */ +@Configuration +public class PersistenceContext { + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://localhost:3306/shopCart"); + dataSource.setUsername("root"); + dataSource.setPassword("famas"); + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + + LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); + factory.setJpaVendorAdapter(vendorAdapter); + factory.setPackagesToScan("javabootcamp.shopcart.model"); + factory.setDataSource(dataSource()); + Properties prop = new Properties(); + prop.setProperty("spring.jpa.hibernate.ddl-auto", "create-drop"); + factory.setJpaProperties(prop); + factory.afterPropertiesSet(); + + return factory; + } + + @Bean + public PlatformTransactionManager transactionManager() { + + JpaTransactionManager txManager = new JpaTransactionManager(); + txManager.setEntityManagerFactory(entityManagerFactory().getNativeEntityManagerFactory()); + return txManager; + } +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/WebSecurityConfig.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/WebSecurityConfig.java new file mode 100644 index 00000000..9ed2ebe7 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/WebSecurityConfig.java @@ -0,0 +1,66 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart; + +import java.util.ArrayList; +import java.util.List; +import javabootcamp.shopcart.model.ShopUser; +import javabootcamp.shopcart.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.JdbcUserDetailsManager; + +@Configuration +@EnableWebMvcSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private PersistenceContext persistence; + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/", "/home").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .permitAll() + .and() + .logout() + .permitAll(); + } + +// @Autowired +// private UserRepository userRepository; + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + JdbcUserDetailsManager userDetailsService = new JdbcUserDetailsManager(); + userDetailsService.setDataSource(persistence.dataSource()); + PasswordEncoder encoder = new BCryptPasswordEncoder(); + + auth.userDetailsService(userDetailsService).passwordEncoder(encoder); + auth.jdbcAuthentication().dataSource(persistence.dataSource()); + + if (!userDetailsService.userExists("user")) { + List authorities = new ArrayList(); + authorities.add(new SimpleGrantedAuthority("USER")); + User userDetails = new User("user", encoder.encode("password"), authorities); + + userDetailsService.createUser(userDetails); + } + } +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Category.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Category.java new file mode 100644 index 00000000..a68ac31a --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Category.java @@ -0,0 +1,74 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +/** + * + * @author roberta + */ +@Entity +public class Category implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column + private String name; + + public Category() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + Objects.hashCode(this.id); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Category other = (Category) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/PaymentType.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/PaymentType.java new file mode 100644 index 00000000..67aa8853 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/PaymentType.java @@ -0,0 +1,18 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +/** + * + * @author roberta + */ +public enum PaymentType { + + CASH, + CREDIT_CARD + + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Product.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Product.java new file mode 100644 index 00000000..ba556b8c --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/Product.java @@ -0,0 +1,141 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Version; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * + * @author roberta + */ +@Entity +public class Product implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Version + private Long version; + + @Column() + @NotNull + @Size(max = 100) + private String name; + + @Column() + @Size(max = 2000) + private String productDescription; + + @Column(precision = 19, scale = 2) + @NotNull + private BigDecimal price; + + @ManyToOne + private Category category; + + public Product() { + } + + public Product(String productName, String productDescription, BigDecimal price, + Category category) { + this.name = productName; + this.productDescription = productDescription; + this.price = price; + this.category = category; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getProductDescription() { + return productDescription; + } + + public void setProductDescription(String productDescription) { + this.productDescription = productDescription; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 53 * hash + Objects.hashCode(this.id); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Product other = (Product) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Product{"); + return sb.append("id=").append(id).append(", version=").append(version) + .append(", name=").append(name) + .append(", productDescription=").append(productDescription) + .append(", price=").append(price).append('}').toString(); + } + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCart.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCart.java new file mode 100644 index 00000000..53063939 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCart.java @@ -0,0 +1,93 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Temporal; +import javax.persistence.Version; + +/** + * + * @author roberta + */ +@Entity +public class ShopCart implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Version + private Long version; + + @Column() + @Temporal(javax.persistence.TemporalType.TIMESTAMP) + private final Date creationDate; + + @OneToMany(mappedBy = "cart") + private List cartItems; + + @Column + private BigDecimal total; + + @Enumerated + private PaymentType paymentType; + + public ShopCart() { + this.creationDate = new Date(); + } + + public List getCartItems() { + return cartItems; + } + + public void setCartItems(List cartItems) { + this.cartItems = cartItems; + } + + public BigDecimal getTotal() { + total = BigDecimal.ZERO; + for (ShopCartItem it : getCartItems()) { + total = total.add(it.getSubTotal()); + } + return total; + } + + public void setTotal(BigDecimal total) { + this.total = total; + } + + public PaymentType getPaymentType() { + return paymentType; + } + + public void setPaymentType(PaymentType paymentType) { + this.paymentType = paymentType; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreationDate() { + return creationDate; + } + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCartItem.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCartItem.java new file mode 100644 index 00000000..828c625c --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopCartItem.java @@ -0,0 +1,131 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Version; +import javax.validation.constraints.NotNull; + +/** + * + * @author roberta + */ +@Entity +public class ShopCartItem implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Version + private Long version; + + @NotNull + @Column + private Integer quantity; + + @ManyToOne + private Product product; + + @Column + private BigDecimal subTotal; + + @ManyToOne() + private ShopCart cart; + + public ShopCartItem() { + } + + public ShopCartItem(Integer quantity, Product product, BigDecimal subTotal, ShopCart cart) { + this.quantity = quantity; + this.product = product; + this.subTotal = subTotal; + this.cart = cart; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public Integer getQuantity() { + return quantity; + } + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + public Product getProduct() { + return product; + } + + public void setProduct(Product product) { + this.product = product; + } + + public BigDecimal getSubTotal() { + if (product != null) { + subTotal = this.product.getPrice().multiply(new BigDecimal(quantity)); + return subTotal; + } + return BigDecimal.ZERO; + } + + public void setSubTotal(BigDecimal subTotal) { + this.subTotal = subTotal; + } + + public ShopCart getCart() { + return cart; + } + + public void setCart(ShopCart cart) { + this.cart = cart; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 11 * hash + Objects.hashCode(this.id); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ShopCartItem other = (ShopCartItem) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopUser.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopUser.java new file mode 100644 index 00000000..8c87d7e0 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/ShopUser.java @@ -0,0 +1,91 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +/** + * + * @author roberta + */ +@Entity +@Table(name = "users") +public class ShopUser implements Serializable { + + @Id + @Size(max = 50) + private String username; + + @Column + private String password; + + @Column + private boolean enabled; + + public ShopUser() { + } + + public ShopUser(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 73 * hash + Objects.hashCode(this.username); + return hash; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ShopUser other = (ShopUser) obj; + if (!Objects.equals(this.username, other.username)) { + return false; + } + return true; + } + + + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/UserAuthority.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/UserAuthority.java new file mode 100644 index 00000000..d605d018 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/model/UserAuthority.java @@ -0,0 +1,82 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.model; + +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +/** + * + * @author roberta + */ +@Entity +@Table(name = "authorities") +public class UserAuthority implements Serializable { + + @JoinColumn(name = "username", referencedColumnName = "username",columnDefinition = "varchar(50)") + @Size(max = 50) + @Id + @ManyToOne + private ShopUser username; + + @Column + @Id + @Size(max = 50) + private String authority; + + public UserAuthority() { + } + + public ShopUser getUsername() { + return username; + } + + public void setUsername(ShopUser username) { + this.username = username; + } + + public String getAuthority() { + return authority; + } + + public void setAuthority(String authority) { + this.authority = authority; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 43 * hash + Objects.hashCode(this.username); + hash = 43 * hash + Objects.hashCode(this.authority); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final UserAuthority other = (UserAuthority) obj; + if (!Objects.equals(this.username, other.username)) { + return false; + } + if (!Objects.equals(this.authority, other.authority)) { + return false; + } + return true; + } + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/CategoryRepository.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/CategoryRepository.java new file mode 100644 index 00000000..aaf3f18c --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/CategoryRepository.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.repository; + +import javabootcamp.shopcart.model.Category; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author roberta + */ +public interface CategoryRepository extends CrudRepository { + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ItemRepository.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ItemRepository.java new file mode 100644 index 00000000..1c9c58b8 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ItemRepository.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.repository; + +import javabootcamp.shopcart.model.ShopCartItem; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author roberta + */ +public interface ItemRepository extends CrudRepository { + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ProductRepository.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ProductRepository.java new file mode 100644 index 00000000..9027da58 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ProductRepository.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.repository; + +import java.util.List; +import javabootcamp.shopcart.model.Category; +import javabootcamp.shopcart.model.Product; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author roberta + */ +public interface ProductRepository extends CrudRepository { + + List findByName(String name); + List findByCategory(Category category); + + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ShopCartRepository.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ShopCartRepository.java new file mode 100644 index 00000000..962de376 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/ShopCartRepository.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.repository; + +import javabootcamp.shopcart.model.ShopCart; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author roberta + */ +public interface ShopCartRepository extends CrudRepository { + +} diff --git a/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/UserRepository.java b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/UserRepository.java new file mode 100644 index 00000000..5ddf4895 --- /dev/null +++ b/finalProject/shopcart/src/main/java/javabootcamp/shopcart/repository/UserRepository.java @@ -0,0 +1,17 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javabootcamp.shopcart.repository; + +import javabootcamp.shopcart.model.ShopUser; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author roberta + */ +public interface UserRepository extends CrudRepository { + +} diff --git a/finalProject/shopcart/src/main/resources/application.properties b/finalProject/shopcart/src/main/resources/application.properties new file mode 100644 index 00000000..601ea064 --- /dev/null +++ b/finalProject/shopcart/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file diff --git a/finalProject/shopcart/src/main/resources/templates/login.html b/finalProject/shopcart/src/main/resources/templates/login.html new file mode 100644 index 00000000..5b9ee6cc --- /dev/null +++ b/finalProject/shopcart/src/main/resources/templates/login.html @@ -0,0 +1,20 @@ + + + + Shop Cart Login + + +
+ Invalid username and password. +
+
+ You have been logged out. +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/finalProject/shopcart/src/main/webapp/index.html b/finalProject/shopcart/src/main/webapp/index.html new file mode 100644 index 00000000..3368e9c3 --- /dev/null +++ b/finalProject/shopcart/src/main/webapp/index.html @@ -0,0 +1,10 @@ + + + + Start Page + + + +

Hello World!

+ +