diff --git a/.jhipster/Cart.json b/.jhipster/Cart.json new file mode 100644 index 0000000..7a5cc43 --- /dev/null +++ b/.jhipster/Cart.json @@ -0,0 +1,25 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "one-to-many", + "relationshipName": "item", + "otherEntityName": "item", + "otherEntityRelationshipName": "cart" + }, + { + "relationshipType": "one-to-one", + "relationshipName": "customer", + "otherEntityName": "customer", + "ownerSide": false, + "otherEntityRelationshipName": "cart" + } + ], + "fields": [], + "changelogDate": "20171208125341", + "entityTableName": "cart", + "dto": "no", + "pagination": "no", + "service": "no", + "jpaMetamodelFiltering": false +} \ No newline at end of file diff --git a/.jhipster/Category.json b/.jhipster/Category.json new file mode 100644 index 0000000..4bab44a --- /dev/null +++ b/.jhipster/Category.json @@ -0,0 +1,32 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "one-to-many", + "relationshipName": "item", + "otherEntityName": "item", + "otherEntityRelationshipName": "category" + }, + { + "relationshipType": "many-to-one", + "relationshipName": "parent", + "otherEntityName": "category", + "otherEntityField": "id" + } + ], + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + } + ], + "changelogDate": "20171118104227", + "entityTableName": "category", + "dto": "no", + "pagination": "pagination", + "service": "serviceClass", + "jpaMetamodelFiltering": false +} \ No newline at end of file diff --git a/.jhipster/Customer.json b/.jhipster/Customer.json new file mode 100644 index 0000000..d681b33 --- /dev/null +++ b/.jhipster/Customer.json @@ -0,0 +1,37 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "one-to-one", + "relationshipName": "cart", + "otherEntityName": "cart", + "otherEntityField": "id", + "ownerSide": true, + "otherEntityRelationshipName": "customer" + } + ], + "fields": [ + { + "fieldName": "firstName", + "fieldType": "String" + }, + { + "fieldName": "lastName", + "fieldType": "String" + }, + { + "fieldName": "email", + "fieldType": "String" + }, + { + "fieldName": "telephone", + "fieldType": "String" + } + ], + "changelogDate": "20171118104228", + "entityTableName": "customer", + "dto": "no", + "pagination": "pagination", + "service": "no", + "jpaMetamodelFiltering": false +} \ No newline at end of file diff --git a/.jhipster/Item.json b/.jhipster/Item.json new file mode 100644 index 0000000..e7fca8d --- /dev/null +++ b/.jhipster/Item.json @@ -0,0 +1,40 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "many-to-one", + "relationshipName": "category", + "otherEntityName": "category", + "otherEntityField": "id" + }, + { + "relationshipName": "cart", + "otherEntityName": "cart", + "relationshipType": "many-to-one", + "otherEntityField": "id" + } + ], + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + }, + { + "fieldName": "description", + "fieldType": "String" + }, + { + "fieldName": "price", + "fieldType": "Integer" + } + ], + "changelogDate": "20171118104226", + "entityTableName": "item", + "dto": "no", + "pagination": "pagination", + "service": "serviceClass", + "jpaMetamodelFiltering": false +} \ No newline at end of file diff --git a/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java b/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java index 2c26447..b01b3fd 100644 --- a/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java +++ b/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java @@ -47,6 +47,14 @@ public JCacheManagerCustomizer cacheManagerCustomizer() { cm.createCache(org.apeps.firstapp.domain.Offering.class.getName() + ".prices", jcacheConfiguration); cm.createCache(org.apeps.firstapp.domain.Offering.class.getName() + ".childs", jcacheConfiguration); cm.createCache(org.apeps.firstapp.domain.Price.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Item.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Category.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Category.class.getName() + ".items", jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Customer.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Customer.class.getName() + ".items", jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Cart.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Cart.class.getName() + ".items", jcacheConfiguration); + // jhipster-needle-ehcache-add-entry }; } diff --git a/src/main/java/org/apeps/firstapp/domain/Cart.java b/src/main/java/org/apeps/firstapp/domain/Cart.java new file mode 100644 index 0000000..b46874b --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Cart.java @@ -0,0 +1,111 @@ +package org.apeps.firstapp.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; +import java.util.Objects; + +/** + * A Cart. + */ +@Entity +@Table(name = "cart") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Cart implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @OneToMany(mappedBy = "cart") + @JsonIgnore + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + private Set items = new HashSet<>(); + + @OneToOne(mappedBy = "cart") + @JsonIgnore + private Customer customer; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Set getItems() { + return items; + } + + public Cart items(Set items) { + this.items = items; + return this; + } + + public Cart addItem(Item item) { + this.items.add(item); + item.setCart(this); + return this; + } + + public Cart removeItem(Item item) { + this.items.remove(item); + item.setCart(null); + return this; + } + + public void setItems(Set items) { + this.items = items; + } + + public Customer getCustomer() { + return customer; + } + + public Cart customer(Customer customer) { + this.customer = customer; + return this; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Cart cart = (Cart) o; + if (cart.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), cart.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Cart{" + + "id=" + getId() + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/domain/Category.java b/src/main/java/org/apeps/firstapp/domain/Category.java new file mode 100644 index 0000000..a951117 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Category.java @@ -0,0 +1,129 @@ +package org.apeps.firstapp.domain; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.*; +import javax.validation.constraints.*; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; +import java.util.Objects; + +/** + * A Category. + */ +@Entity +@Table(name = "category") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Category implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @NotNull + @Column(name = "name", nullable = false) + private String name; + + @OneToMany(mappedBy = "category") + @JsonIgnore + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + private Set items = new HashSet<>(); + + @ManyToOne + private Category parent; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public Category name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public Set getItems() { + return items; + } + + public Category items(Set items) { + this.items = items; + return this; + } + + public Category addItem(Item item) { + this.items.add(item); + item.setCategory(this); + return this; + } + + public Category removeItem(Item item) { + this.items.remove(item); + item.setCategory(null); + return this; + } + + public void setItems(Set items) { + this.items = items; + } + + public Category getParent() { + return parent; + } + + public Category parent(Category category) { + this.parent = category; + return this; + } + + public void setParent(Category category) { + this.parent = category; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + if (category.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), category.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Category{" + + "id=" + getId() + + ", name='" + getName() + "'" + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/domain/Customer.java b/src/main/java/org/apeps/firstapp/domain/Customer.java new file mode 100644 index 0000000..6b590d9 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Customer.java @@ -0,0 +1,146 @@ +package org.apeps.firstapp.domain; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Objects; + +/** + * A Customer. + */ +@Entity +@Table(name = "customer") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Customer implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @Column(name = "first_name") + private String firstName; + + @Column(name = "last_name") + private String lastName; + + @Column(name = "email") + private String email; + + @Column(name = "telephone") + private String telephone; + + @OneToOne + @JoinColumn(unique = true) + private Cart cart; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public Customer firstName(String firstName) { + this.firstName = firstName; + return this; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public Customer lastName(String lastName) { + this.lastName = lastName; + return this; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public Customer email(String email) { + this.email = email; + return this; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getTelephone() { + return telephone; + } + + public Customer telephone(String telephone) { + this.telephone = telephone; + return this; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + public Cart getCart() { + return cart; + } + + public Customer cart(Cart cart) { + this.cart = cart; + return this; + } + + public void setCart(Cart cart) { + this.cart = cart; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Customer customer = (Customer) o; + if (customer.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), customer.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Customer{" + + "id=" + getId() + + ", firstName='" + getFirstName() + "'" + + ", lastName='" + getLastName() + "'" + + ", email='" + getEmail() + "'" + + ", telephone='" + getTelephone() + "'" + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/domain/Item.java b/src/main/java/org/apeps/firstapp/domain/Item.java new file mode 100644 index 0000000..40626ab --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Item.java @@ -0,0 +1,146 @@ +package org.apeps.firstapp.domain; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.*; +import javax.validation.constraints.*; +import java.io.Serializable; +import java.util.Objects; + +/** + * A Item. + */ +@Entity +@Table(name = "item") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Item implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @NotNull + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "description") + private String description; + + @Column(name = "price") + private Integer price; + + @ManyToOne + private Category category; + + @ManyToOne + private Cart cart; + + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public Item name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public Item description(String description) { + this.description = description; + return this; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getPrice() { + return price; + } + + public Item price(Integer price) { + this.price = price; + return this; + } + + public void setPrice(Integer price) { + this.price = price; + } + + public Category getCategory() { + return category; + } + + public Item category(Category category) { + this.category = category; + return this; + } + + public void setCategory(Category category) { + this.category = category; + } + + public Cart getCart() { + return cart; + } + + public Item cart(Cart cart) { + this.cart = cart; + return this; + } + + public void setCart(Cart cart) { + this.cart = cart; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Item item = (Item) o; + if (item.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), item.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Item{" + + "id=" + getId() + + ", name='" + getName() + "'" + + ", description='" + getDescription() + "'" + + ", price='" + getPrice() + "'" + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/repository/CartRepository.java b/src/main/java/org/apeps/firstapp/repository/CartRepository.java new file mode 100644 index 0000000..47ad7f1 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/CartRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Cart; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Cart entity. + */ +@SuppressWarnings("unused") +@Repository +public interface CartRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/repository/CategoryRepository.java b/src/main/java/org/apeps/firstapp/repository/CategoryRepository.java new file mode 100644 index 0000000..5237185 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/CategoryRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Category; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Category entity. + */ +@SuppressWarnings("unused") +@Repository +public interface CategoryRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/repository/CustomerRepository.java b/src/main/java/org/apeps/firstapp/repository/CustomerRepository.java new file mode 100644 index 0000000..345cefc --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/CustomerRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Customer; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Customer entity. + */ +@SuppressWarnings("unused") +@Repository +public interface CustomerRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/repository/ItemRepository.java b/src/main/java/org/apeps/firstapp/repository/ItemRepository.java new file mode 100644 index 0000000..d5c55fb --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/ItemRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Item; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Item entity. + */ +@SuppressWarnings("unused") +@Repository +public interface ItemRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/service/CategoryService.java b/src/main/java/org/apeps/firstapp/service/CategoryService.java new file mode 100644 index 0000000..efb17a4 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/service/CategoryService.java @@ -0,0 +1,72 @@ +package org.apeps.firstapp.service; + +import org.apeps.firstapp.domain.Category; +import org.apeps.firstapp.repository.CategoryRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +/** + * Service Implementation for managing Category. + */ +@Service +@Transactional +public class CategoryService { + + private final Logger log = LoggerFactory.getLogger(CategoryService.class); + + private final CategoryRepository categoryRepository; + + public CategoryService(CategoryRepository categoryRepository) { + this.categoryRepository = categoryRepository; + } + + /** + * Save a category. + * + * @param category the entity to save + * @return the persisted entity + */ + public Category save(Category category) { + log.debug("Request to save Category : {}", category); + return categoryRepository.save(category); + } + + /** + * Get all the categories. + * + * @param pageable the pagination information + * @return the list of entities + */ + @Transactional(readOnly = true) + public Page findAll(Pageable pageable) { + log.debug("Request to get all Categories"); + return categoryRepository.findAll(pageable); + } + + /** + * Get one category by id. + * + * @param id the id of the entity + * @return the entity + */ + @Transactional(readOnly = true) + public Category findOne(Long id) { + log.debug("Request to get Category : {}", id); + return categoryRepository.findOne(id); + } + + /** + * Delete the category by id. + * + * @param id the id of the entity + */ + public void delete(Long id) { + log.debug("Request to delete Category : {}", id); + categoryRepository.delete(id); + } +} diff --git a/src/main/java/org/apeps/firstapp/service/ItemService.java b/src/main/java/org/apeps/firstapp/service/ItemService.java new file mode 100644 index 0000000..ae8236b --- /dev/null +++ b/src/main/java/org/apeps/firstapp/service/ItemService.java @@ -0,0 +1,72 @@ +package org.apeps.firstapp.service; + +import org.apeps.firstapp.domain.Item; +import org.apeps.firstapp.repository.ItemRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +/** + * Service Implementation for managing Item. + */ +@Service +@Transactional +public class ItemService { + + private final Logger log = LoggerFactory.getLogger(ItemService.class); + + private final ItemRepository itemRepository; + + public ItemService(ItemRepository itemRepository) { + this.itemRepository = itemRepository; + } + + /** + * Save a item. + * + * @param item the entity to save + * @return the persisted entity + */ + public Item save(Item item) { + log.debug("Request to save Item : {}", item); + return itemRepository.save(item); + } + + /** + * Get all the items. + * + * @param pageable the pagination information + * @return the list of entities + */ + @Transactional(readOnly = true) + public Page findAll(Pageable pageable) { + log.debug("Request to get all Items"); + return itemRepository.findAll(pageable); + } + + /** + * Get one item by id. + * + * @param id the id of the entity + * @return the entity + */ + @Transactional(readOnly = true) + public Item findOne(Long id) { + log.debug("Request to get Item : {}", id); + return itemRepository.findOne(id); + } + + /** + * Delete the item by id. + * + * @param id the id of the entity + */ + public void delete(Long id) { + log.debug("Request to delete Item : {}", id); + itemRepository.delete(id); + } +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/CartResource.java b/src/main/java/org/apeps/firstapp/web/rest/CartResource.java new file mode 100644 index 0000000..265eb56 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/CartResource.java @@ -0,0 +1,129 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Cart; + +import org.apeps.firstapp.repository.CartRepository; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +/** + * REST controller for managing Cart. + */ +@RestController +@RequestMapping("/api") +public class CartResource { + + private final Logger log = LoggerFactory.getLogger(CartResource.class); + + private static final String ENTITY_NAME = "cart"; + + private final CartRepository cartRepository; + + public CartResource(CartRepository cartRepository) { + this.cartRepository = cartRepository; + } + + /** + * POST /carts : Create a new cart. + * + * @param cart the cart to create + * @return the ResponseEntity with status 201 (Created) and with body the new cart, or with status 400 (Bad Request) if the cart has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/carts") + @Timed + public ResponseEntity createCart(@RequestBody Cart cart) throws URISyntaxException { + log.debug("REST request to save Cart : {}", cart); + if (cart.getId() != null) { + throw new BadRequestAlertException("A new cart cannot already have an ID", ENTITY_NAME, "idexists"); + } + Cart result = cartRepository.save(cart); + return ResponseEntity.created(new URI("/api/carts/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /carts : Updates an existing cart. + * + * @param cart the cart to update + * @return the ResponseEntity with status 200 (OK) and with body the updated cart, + * or with status 400 (Bad Request) if the cart is not valid, + * or with status 500 (Internal Server Error) if the cart couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/carts") + @Timed + public ResponseEntity updateCart(@RequestBody Cart cart) throws URISyntaxException { + log.debug("REST request to update Cart : {}", cart); + if (cart.getId() == null) { + return createCart(cart); + } + Cart result = cartRepository.save(cart); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, cart.getId().toString())) + .body(result); + } + + /** + * GET /carts : get all the carts. + * + * @param filter the filter of the request + * @return the ResponseEntity with status 200 (OK) and the list of carts in body + */ + @GetMapping("/carts") + @Timed + public List getAllCarts(@RequestParam(required = false) String filter) { + if ("customer-is-null".equals(filter)) { + log.debug("REST request to get all Carts where customer is null"); + return StreamSupport + .stream(cartRepository.findAll().spliterator(), false) + .filter(cart -> cart.getCustomer() == null) + .collect(Collectors.toList()); + } + log.debug("REST request to get all Carts"); + return cartRepository.findAll(); + } + + /** + * GET /carts/:id : get the "id" cart. + * + * @param id the id of the cart to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the cart, or with status 404 (Not Found) + */ + @GetMapping("/carts/{id}") + @Timed + public ResponseEntity getCart(@PathVariable Long id) { + log.debug("REST request to get Cart : {}", id); + Cart cart = cartRepository.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(cart)); + } + + /** + * DELETE /carts/:id : delete the "id" cart. + * + * @param id the id of the cart to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/carts/{id}") + @Timed + public ResponseEntity deleteCart(@PathVariable Long id) { + log.debug("REST request to delete Cart : {}", id); + cartRepository.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/CategoryResource.java b/src/main/java/org/apeps/firstapp/web/rest/CategoryResource.java new file mode 100644 index 0000000..7e885c3 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/CategoryResource.java @@ -0,0 +1,128 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Category; +import org.apeps.firstapp.service.CategoryService; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import org.apeps.firstapp.web.rest.util.PaginationUtil; +import io.swagger.annotations.ApiParam; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Category. + */ +@RestController +@RequestMapping("/api") +public class CategoryResource { + + private final Logger log = LoggerFactory.getLogger(CategoryResource.class); + + private static final String ENTITY_NAME = "category"; + + private final CategoryService categoryService; + + public CategoryResource(CategoryService categoryService) { + this.categoryService = categoryService; + } + + /** + * POST /categories : Create a new category. + * + * @param category the category to create + * @return the ResponseEntity with status 201 (Created) and with body the new category, or with status 400 (Bad Request) if the category has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/categories") + @Timed + public ResponseEntity createCategory(@Valid @RequestBody Category category) throws URISyntaxException { + log.debug("REST request to save Category : {}", category); + if (category.getId() != null) { + throw new BadRequestAlertException("A new category cannot already have an ID", ENTITY_NAME, "idexists"); + } + Category result = categoryService.save(category); + return ResponseEntity.created(new URI("/api/categories/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /categories : Updates an existing category. + * + * @param category the category to update + * @return the ResponseEntity with status 200 (OK) and with body the updated category, + * or with status 400 (Bad Request) if the category is not valid, + * or with status 500 (Internal Server Error) if the category couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/categories") + @Timed + public ResponseEntity updateCategory(@Valid @RequestBody Category category) throws URISyntaxException { + log.debug("REST request to update Category : {}", category); + if (category.getId() == null) { + return createCategory(category); + } + Category result = categoryService.save(category); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, category.getId().toString())) + .body(result); + } + + /** + * GET /categories : get all the categories. + * + * @param pageable the pagination information + * @return the ResponseEntity with status 200 (OK) and the list of categories in body + */ + @GetMapping("/categories") + @Timed + public ResponseEntity> getAllCategories(@ApiParam Pageable pageable) { + log.debug("REST request to get a page of Categories"); + Page page = categoryService.findAll(pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/categories"); + return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); + } + + /** + * GET /categories/:id : get the "id" category. + * + * @param id the id of the category to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the category, or with status 404 (Not Found) + */ + @GetMapping("/categories/{id}") + @Timed + public ResponseEntity getCategory(@PathVariable Long id) { + log.debug("REST request to get Category : {}", id); + Category category = categoryService.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(category)); + } + + /** + * DELETE /categories/:id : delete the "id" category. + * + * @param id the id of the category to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/categories/{id}") + @Timed + public ResponseEntity deleteCategory(@PathVariable Long id) { + log.debug("REST request to delete Category : {}", id); + categoryService.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/CustomerResource.java b/src/main/java/org/apeps/firstapp/web/rest/CustomerResource.java new file mode 100644 index 0000000..c809658 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/CustomerResource.java @@ -0,0 +1,128 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Customer; + +import org.apeps.firstapp.repository.CustomerRepository; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import org.apeps.firstapp.web.rest.util.PaginationUtil; +import io.swagger.annotations.ApiParam; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Customer. + */ +@RestController +@RequestMapping("/api") +public class CustomerResource { + + private final Logger log = LoggerFactory.getLogger(CustomerResource.class); + + private static final String ENTITY_NAME = "customer"; + + private final CustomerRepository customerRepository; + + public CustomerResource(CustomerRepository customerRepository) { + this.customerRepository = customerRepository; + } + + /** + * POST /customers : Create a new customer. + * + * @param customer the customer to create + * @return the ResponseEntity with status 201 (Created) and with body the new customer, or with status 400 (Bad Request) if the customer has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/customers") + @Timed + public ResponseEntity createCustomer(@RequestBody Customer customer) throws URISyntaxException { + log.debug("REST request to save Customer : {}", customer); + if (customer.getId() != null) { + throw new BadRequestAlertException("A new customer cannot already have an ID", ENTITY_NAME, "idexists"); + } + Customer result = customerRepository.save(customer); + return ResponseEntity.created(new URI("/api/customers/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /customers : Updates an existing customer. + * + * @param customer the customer to update + * @return the ResponseEntity with status 200 (OK) and with body the updated customer, + * or with status 400 (Bad Request) if the customer is not valid, + * or with status 500 (Internal Server Error) if the customer couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/customers") + @Timed + public ResponseEntity updateCustomer(@RequestBody Customer customer) throws URISyntaxException { + log.debug("REST request to update Customer : {}", customer); + if (customer.getId() == null) { + return createCustomer(customer); + } + Customer result = customerRepository.save(customer); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, customer.getId().toString())) + .body(result); + } + + /** + * GET /customers : get all the customers. + * + * @param pageable the pagination information + * @return the ResponseEntity with status 200 (OK) and the list of customers in body + */ + @GetMapping("/customers") + @Timed + public ResponseEntity> getAllCustomers(@ApiParam Pageable pageable) { + log.debug("REST request to get a page of Customers"); + Page page = customerRepository.findAll(pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/customers"); + return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); + } + + /** + * GET /customers/:id : get the "id" customer. + * + * @param id the id of the customer to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the customer, or with status 404 (Not Found) + */ + @GetMapping("/customers/{id}") + @Timed + public ResponseEntity getCustomer(@PathVariable Long id) { + log.debug("REST request to get Customer : {}", id); + Customer customer = customerRepository.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(customer)); + } + + /** + * DELETE /customers/:id : delete the "id" customer. + * + * @param id the id of the customer to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/customers/{id}") + @Timed + public ResponseEntity deleteCustomer(@PathVariable Long id) { + log.debug("REST request to delete Customer : {}", id); + customerRepository.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/ItemResource.java b/src/main/java/org/apeps/firstapp/web/rest/ItemResource.java new file mode 100644 index 0000000..973cc7b --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/ItemResource.java @@ -0,0 +1,128 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Item; +import org.apeps.firstapp.service.ItemService; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import org.apeps.firstapp.web.rest.util.PaginationUtil; +import io.swagger.annotations.ApiParam; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Item. + */ +@RestController +@RequestMapping("/api") +public class ItemResource { + + private final Logger log = LoggerFactory.getLogger(ItemResource.class); + + private static final String ENTITY_NAME = "item"; + + private final ItemService itemService; + + public ItemResource(ItemService itemService) { + this.itemService = itemService; + } + + /** + * POST /items : Create a new item. + * + * @param item the item to create + * @return the ResponseEntity with status 201 (Created) and with body the new item, or with status 400 (Bad Request) if the item has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/items") + @Timed + public ResponseEntity createItem(@Valid @RequestBody Item item) throws URISyntaxException { + log.debug("REST request to save Item : {}", item); + if (item.getId() != null) { + throw new BadRequestAlertException("A new item cannot already have an ID", ENTITY_NAME, "idexists"); + } + Item result = itemService.save(item); + return ResponseEntity.created(new URI("/api/items/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /items : Updates an existing item. + * + * @param item the item to update + * @return the ResponseEntity with status 200 (OK) and with body the updated item, + * or with status 400 (Bad Request) if the item is not valid, + * or with status 500 (Internal Server Error) if the item couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/items") + @Timed + public ResponseEntity updateItem(@Valid @RequestBody Item item) throws URISyntaxException { + log.debug("REST request to update Item : {}", item); + if (item.getId() == null) { + return createItem(item); + } + Item result = itemService.save(item); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, item.getId().toString())) + .body(result); + } + + /** + * GET /items : get all the items. + * + * @param pageable the pagination information + * @return the ResponseEntity with status 200 (OK) and the list of items in body + */ + @GetMapping("/items") + @Timed + public ResponseEntity> getAllItems(@ApiParam Pageable pageable) { + log.debug("REST request to get a page of Items"); + Page page = itemService.findAll(pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/items"); + return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); + } + + /** + * GET /items/:id : get the "id" item. + * + * @param id the id of the item to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the item, or with status 404 (Not Found) + */ + @GetMapping("/items/{id}") + @Timed + public ResponseEntity getItem(@PathVariable Long id) { + log.debug("REST request to get Item : {}", id); + Item item = itemService.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(item)); + } + + /** + * DELETE /items/:id : delete the "id" item. + * + * @param id the id of the item to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/items/{id}") + @Timed + public ResponseEntity deleteItem(@PathVariable Long id) { + log.debug("REST request to delete Item : {}", id); + itemService.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_Item.xml b/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_Item.xml new file mode 100644 index 0000000..7bf2e55 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_Item.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_constraints_Item.xml b/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_constraints_Item.xml new file mode 100644 index 0000000..ae17d33 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104226_added_entity_constraints_Item.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_Category.xml b/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_Category.xml new file mode 100644 index 0000000..cf87d78 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_Category.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_constraints_Category.xml b/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_constraints_Category.xml new file mode 100644 index 0000000..9033788 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104227_added_entity_constraints_Category.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_Customer.xml b/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_Customer.xml new file mode 100644 index 0000000..7b6c814 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_Customer.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_constraints_Customer.xml b/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_constraints_Customer.xml new file mode 100644 index 0000000..59f34ba --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_constraints_Customer.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171208125341_added_entity_Cart.xml b/src/main/resources/config/liquibase/changelog/20171208125341_added_entity_Cart.xml new file mode 100644 index 0000000..e0fc9bf --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171208125341_added_entity_Cart.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 1bf7f66..b2e460e 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -7,8 +7,15 @@ + + + + + + + diff --git a/src/main/webapp/app/entities/cart/cart-delete-dialog.controller.js b/src/main/webapp/app/entities/cart/cart-delete-dialog.controller.js new file mode 100644 index 0000000..66bf5a9 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CartDeleteController',CartDeleteController); + + CartDeleteController.$inject = ['$uibModalInstance', 'entity', 'Cart']; + + function CartDeleteController($uibModalInstance, entity, Cart) { + var vm = this; + + vm.cart = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Cart.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/cart/cart-delete-dialog.html b/src/main/webapp/app/entities/cart/cart-delete-dialog.html new file mode 100644 index 0000000..413db89 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/cart/cart-detail.controller.js b/src/main/webapp/app/entities/cart/cart-detail.controller.js new file mode 100644 index 0000000..c5ff8a0 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CartDetailController', CartDetailController); + + CartDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Cart', 'Item', 'Customer']; + + function CartDetailController($scope, $rootScope, $stateParams, previousState, entity, Cart, Item, Customer) { + var vm = this; + + vm.cart = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:cartUpdate', function(event, result) { + vm.cart = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/cart/cart-detail.html b/src/main/webapp/app/entities/cart/cart-detail.html new file mode 100644 index 0000000..0dbeb26 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-detail.html @@ -0,0 +1,19 @@ + +
+

Cart {{vm.cart.id}}

+
+ +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/cart/cart-dialog.controller.js b/src/main/webapp/app/entities/cart/cart-dialog.controller.js new file mode 100644 index 0000000..82e80ef --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-dialog.controller.js @@ -0,0 +1,48 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CartDialogController', CartDialogController); + + CartDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Cart', 'Item', 'Customer']; + + function CartDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Cart, Item, Customer) { + var vm = this; + + vm.cart = entity; + vm.clear = clear; + vm.save = save; + vm.items = Item.query(); + vm.customers = Customer.query(); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.cart.id !== null) { + Cart.update(vm.cart, onSaveSuccess, onSaveError); + } else { + Cart.save(vm.cart, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:cartUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/cart/cart-dialog.html b/src/main/webapp/app/entities/cart/cart-dialog.html new file mode 100644 index 0000000..f4b9d3f --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart-dialog.html @@ -0,0 +1,26 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/cart/cart.controller.js b/src/main/webapp/app/entities/cart/cart.controller.js new file mode 100644 index 0000000..60d6f31 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart.controller.js @@ -0,0 +1,25 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CartController', CartController); + + CartController.$inject = ['Cart']; + + function CartController(Cart) { + + var vm = this; + + vm.carts = []; + + loadAll(); + + function loadAll() { + Cart.query(function(result) { + vm.carts = result; + vm.searchQuery = null; + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/cart/cart.service.js b/src/main/webapp/app/entities/cart/cart.service.js new file mode 100644 index 0000000..6f95787 --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Cart', Cart); + + Cart.$inject = ['$resource']; + + function Cart ($resource) { + var resourceUrl = 'api/carts/:id'; + + return $resource(resourceUrl, {}, { + 'query': { method: 'GET', isArray: true}, + 'get': { + method: 'GET', + transformResponse: function (data) { + if (data) { + data = angular.fromJson(data); + } + return data; + } + }, + 'update': { method:'PUT' } + }); + } +})(); diff --git a/src/main/webapp/app/entities/cart/cart.state.js b/src/main/webapp/app/entities/cart/cart.state.js new file mode 100644 index 0000000..057a9fe --- /dev/null +++ b/src/main/webapp/app/entities/cart/cart.state.js @@ -0,0 +1,160 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('cart', { + parent: 'entity', + url: '/cart', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Carts' + }, + views: { + 'content@': { + templateUrl: 'app/entities/cart/carts.html', + controller: 'CartController', + controllerAs: 'vm' + } + }, + resolve: { + } + }) + .state('cart-detail', { + parent: 'cart', + url: '/cart/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Cart' + }, + views: { + 'content@': { + templateUrl: 'app/entities/cart/cart-detail.html', + controller: 'CartDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Cart', function($stateParams, Cart) { + return Cart.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'cart', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('cart-detail.edit', { + parent: 'cart-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/cart/cart-dialog.html', + controller: 'CartDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Cart', function(Cart) { + return Cart.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('cart.new', { + parent: 'cart', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/cart/cart-dialog.html', + controller: 'CartDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + id: null + }; + } + } + }).result.then(function() { + $state.go('cart', null, { reload: 'cart' }); + }, function() { + $state.go('cart'); + }); + }] + }) + .state('cart.edit', { + parent: 'cart', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/cart/cart-dialog.html', + controller: 'CartDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Cart', function(Cart) { + return Cart.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('cart', null, { reload: 'cart' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('cart.delete', { + parent: 'cart', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/cart/cart-delete-dialog.html', + controller: 'CartDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Cart', function(Cart) { + return Cart.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('cart', null, { reload: 'cart' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/cart/carts.html b/src/main/webapp/app/entities/cart/carts.html new file mode 100644 index 0000000..961f74f --- /dev/null +++ b/src/main/webapp/app/entities/cart/carts.html @@ -0,0 +1,54 @@ +
+

Carts

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + +
ID
{{cart.id}} +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/entities/category/categories.html b/src/main/webapp/app/entities/category/categories.html new file mode 100644 index 0000000..119b27f --- /dev/null +++ b/src/main/webapp/app/entities/category/categories.html @@ -0,0 +1,64 @@ +
+

Categories

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + +
ID Name Parent
{{category.id}}{{category.name}} + {{category.parent.id}} + +
+ + + +
+
+
+
+ + +
+
diff --git a/src/main/webapp/app/entities/category/category-delete-dialog.controller.js b/src/main/webapp/app/entities/category/category-delete-dialog.controller.js new file mode 100644 index 0000000..78cf94c --- /dev/null +++ b/src/main/webapp/app/entities/category/category-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CategoryDeleteController',CategoryDeleteController); + + CategoryDeleteController.$inject = ['$uibModalInstance', 'entity', 'Category']; + + function CategoryDeleteController($uibModalInstance, entity, Category) { + var vm = this; + + vm.category = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Category.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/category/category-delete-dialog.html b/src/main/webapp/app/entities/category/category-delete-dialog.html new file mode 100644 index 0000000..9326345 --- /dev/null +++ b/src/main/webapp/app/entities/category/category-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/category/category-detail.controller.js b/src/main/webapp/app/entities/category/category-detail.controller.js new file mode 100644 index 0000000..9b0c228 --- /dev/null +++ b/src/main/webapp/app/entities/category/category-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CategoryDetailController', CategoryDetailController); + + CategoryDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Category', 'Item']; + + function CategoryDetailController($scope, $rootScope, $stateParams, previousState, entity, Category, Item) { + var vm = this; + + vm.category = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:categoryUpdate', function(event, result) { + vm.category = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/category/category-detail.html b/src/main/webapp/app/entities/category/category-detail.html new file mode 100644 index 0000000..7376130 --- /dev/null +++ b/src/main/webapp/app/entities/category/category-detail.html @@ -0,0 +1,27 @@ + +
+

Category {{vm.category.id}}

+
+ +
+
Name
+
+ {{vm.category.name}} +
+
Parent
+
+ {{vm.category.parent.id}} +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/category/category-dialog.controller.js b/src/main/webapp/app/entities/category/category-dialog.controller.js new file mode 100644 index 0000000..6b1eb3e --- /dev/null +++ b/src/main/webapp/app/entities/category/category-dialog.controller.js @@ -0,0 +1,48 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CategoryDialogController', CategoryDialogController); + + CategoryDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Category', 'Item']; + + function CategoryDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Category, Item) { + var vm = this; + + vm.category = entity; + vm.clear = clear; + vm.save = save; + vm.items = Item.query(); + vm.categories = Category.query(); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.category.id !== null) { + Category.update(vm.category, onSaveSuccess, onSaveError); + } else { + Category.save(vm.category, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:categoryUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/category/category-dialog.html b/src/main/webapp/app/entities/category/category-dialog.html new file mode 100644 index 0000000..ecc4957 --- /dev/null +++ b/src/main/webapp/app/entities/category/category-dialog.html @@ -0,0 +1,44 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/category/category.controller.js b/src/main/webapp/app/entities/category/category.controller.js new file mode 100644 index 0000000..1020d5f --- /dev/null +++ b/src/main/webapp/app/entities/category/category.controller.js @@ -0,0 +1,60 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CategoryController', CategoryController); + + CategoryController.$inject = ['$state', 'Category', 'ParseLinks', 'AlertService', 'paginationConstants', 'pagingParams']; + + function CategoryController($state, Category, ParseLinks, AlertService, paginationConstants, pagingParams) { + + var vm = this; + + vm.loadPage = loadPage; + vm.predicate = pagingParams.predicate; + vm.reverse = pagingParams.ascending; + vm.transition = transition; + vm.itemsPerPage = paginationConstants.itemsPerPage; + + loadAll(); + + function loadAll () { + Category.query({ + page: pagingParams.page - 1, + size: vm.itemsPerPage, + sort: sort() + }, onSuccess, onError); + function sort() { + var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')]; + if (vm.predicate !== 'id') { + result.push('id'); + } + return result; + } + function onSuccess(data, headers) { + vm.links = ParseLinks.parse(headers('link')); + vm.totalItems = headers('X-Total-Count'); + vm.queryCount = vm.totalItems; + vm.categories = data; + vm.page = pagingParams.page; + } + function onError(error) { + AlertService.error(error.data.message); + } + } + + function loadPage(page) { + vm.page = page; + vm.transition(); + } + + function transition() { + $state.transitionTo($state.$current, { + page: vm.page, + sort: vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc'), + search: vm.currentSearch + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/category/category.service.js b/src/main/webapp/app/entities/category/category.service.js new file mode 100644 index 0000000..d54892c --- /dev/null +++ b/src/main/webapp/app/entities/category/category.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Category', Category); + + Category.$inject = ['$resource']; + + function Category ($resource) { + var resourceUrl = 'api/categories/:id'; + + return $resource(resourceUrl, {}, { + 'query': { method: 'GET', isArray: true}, + 'get': { + method: 'GET', + transformResponse: function (data) { + if (data) { + data = angular.fromJson(data); + } + return data; + } + }, + 'update': { method:'PUT' } + }); + } +})(); diff --git a/src/main/webapp/app/entities/category/category.state.js b/src/main/webapp/app/entities/category/category.state.js new file mode 100644 index 0000000..5ccc4d7 --- /dev/null +++ b/src/main/webapp/app/entities/category/category.state.js @@ -0,0 +1,181 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('category', { + parent: 'entity', + url: '/category?page&sort&search', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Categories' + }, + views: { + 'content@': { + templateUrl: 'app/entities/category/categories.html', + controller: 'CategoryController', + controllerAs: 'vm' + } + }, + params: { + page: { + value: '1', + squash: true + }, + sort: { + value: 'id,asc', + squash: true + }, + search: null + }, + resolve: { + pagingParams: ['$stateParams', 'PaginationUtil', function ($stateParams, PaginationUtil) { + return { + page: PaginationUtil.parsePage($stateParams.page), + sort: $stateParams.sort, + predicate: PaginationUtil.parsePredicate($stateParams.sort), + ascending: PaginationUtil.parseAscending($stateParams.sort), + search: $stateParams.search + }; + }], + } + }) + .state('category-detail', { + parent: 'category', + url: '/category/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Category' + }, + views: { + 'content@': { + templateUrl: 'app/entities/category/category-detail.html', + controller: 'CategoryDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Category', function($stateParams, Category) { + return Category.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'category', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('category-detail.edit', { + parent: 'category-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/category/category-dialog.html', + controller: 'CategoryDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Category', function(Category) { + return Category.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('category.new', { + parent: 'category', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/category/category-dialog.html', + controller: 'CategoryDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + name: null, + id: null + }; + } + } + }).result.then(function() { + $state.go('category', null, { reload: 'category' }); + }, function() { + $state.go('category'); + }); + }] + }) + .state('category.edit', { + parent: 'category', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/category/category-dialog.html', + controller: 'CategoryDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Category', function(Category) { + return Category.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('category', null, { reload: 'category' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('category.delete', { + parent: 'category', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/category/category-delete-dialog.html', + controller: 'CategoryDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Category', function(Category) { + return Category.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('category', null, { reload: 'category' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/customer/customer-delete-dialog.controller.js b/src/main/webapp/app/entities/customer/customer-delete-dialog.controller.js new file mode 100644 index 0000000..86efcf9 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CustomerDeleteController',CustomerDeleteController); + + CustomerDeleteController.$inject = ['$uibModalInstance', 'entity', 'Customer']; + + function CustomerDeleteController($uibModalInstance, entity, Customer) { + var vm = this; + + vm.customer = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Customer.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/customer/customer-delete-dialog.html b/src/main/webapp/app/entities/customer/customer-delete-dialog.html new file mode 100644 index 0000000..a4cb76a --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/customer/customer-detail.controller.js b/src/main/webapp/app/entities/customer/customer-detail.controller.js new file mode 100644 index 0000000..936cdf5 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CustomerDetailController', CustomerDetailController); + + CustomerDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Customer', 'Cart']; + + function CustomerDetailController($scope, $rootScope, $stateParams, previousState, entity, Customer, Cart) { + var vm = this; + + vm.customer = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:customerUpdate', function(event, result) { + vm.customer = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/customer/customer-detail.html b/src/main/webapp/app/entities/customer/customer-detail.html new file mode 100644 index 0000000..f9eb809 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-detail.html @@ -0,0 +1,39 @@ + +
+

Customer {{vm.customer.id}}

+
+ +
+
First Name
+
+ {{vm.customer.firstName}} +
+
Last Name
+
+ {{vm.customer.lastName}} +
+
Email
+
+ {{vm.customer.email}} +
+
Telephone
+
+ {{vm.customer.telephone}} +
+
Cart
+
+ {{vm.customer.cart.id}} +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/customer/customer-dialog.controller.js b/src/main/webapp/app/entities/customer/customer-dialog.controller.js new file mode 100644 index 0000000..746feca --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-dialog.controller.js @@ -0,0 +1,55 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CustomerDialogController', CustomerDialogController); + + CustomerDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', '$q', 'entity', 'Customer', 'Cart']; + + function CustomerDialogController ($timeout, $scope, $stateParams, $uibModalInstance, $q, entity, Customer, Cart) { + var vm = this; + + vm.customer = entity; + vm.clear = clear; + vm.save = save; + vm.carts = Cart.query({filter: 'customer-is-null'}); + $q.all([vm.customer.$promise, vm.carts.$promise]).then(function() { + if (!vm.customer.cart || !vm.customer.cart.id) { + return $q.reject(); + } + return Cart.get({id : vm.customer.cart.id}).$promise; + }).then(function(cart) { + vm.carts.push(cart); + }); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.customer.id !== null) { + Customer.update(vm.customer, onSaveSuccess, onSaveError); + } else { + Customer.save(vm.customer, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:customerUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/customer/customer-dialog.html b/src/main/webapp/app/entities/customer/customer-dialog.html new file mode 100644 index 0000000..716cb29 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-dialog.html @@ -0,0 +1,56 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/customer/customer.controller.js b/src/main/webapp/app/entities/customer/customer.controller.js new file mode 100644 index 0000000..e23111d --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer.controller.js @@ -0,0 +1,60 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CustomerController', CustomerController); + + CustomerController.$inject = ['$state', 'Customer', 'ParseLinks', 'AlertService', 'paginationConstants', 'pagingParams']; + + function CustomerController($state, Customer, ParseLinks, AlertService, paginationConstants, pagingParams) { + + var vm = this; + + vm.loadPage = loadPage; + vm.predicate = pagingParams.predicate; + vm.reverse = pagingParams.ascending; + vm.transition = transition; + vm.itemsPerPage = paginationConstants.itemsPerPage; + + loadAll(); + + function loadAll () { + Customer.query({ + page: pagingParams.page - 1, + size: vm.itemsPerPage, + sort: sort() + }, onSuccess, onError); + function sort() { + var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')]; + if (vm.predicate !== 'id') { + result.push('id'); + } + return result; + } + function onSuccess(data, headers) { + vm.links = ParseLinks.parse(headers('link')); + vm.totalItems = headers('X-Total-Count'); + vm.queryCount = vm.totalItems; + vm.customers = data; + vm.page = pagingParams.page; + } + function onError(error) { + AlertService.error(error.data.message); + } + } + + function loadPage(page) { + vm.page = page; + vm.transition(); + } + + function transition() { + $state.transitionTo($state.$current, { + page: vm.page, + sort: vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc'), + search: vm.currentSearch + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/customer/customer.service.js b/src/main/webapp/app/entities/customer/customer.service.js new file mode 100644 index 0000000..804c64d --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Customer', Customer); + + Customer.$inject = ['$resource']; + + function Customer ($resource) { + var resourceUrl = 'api/customers/:id'; + + return $resource(resourceUrl, {}, { + 'query': { method: 'GET', isArray: true}, + 'get': { + method: 'GET', + transformResponse: function (data) { + if (data) { + data = angular.fromJson(data); + } + return data; + } + }, + 'update': { method:'PUT' } + }); + } +})(); diff --git a/src/main/webapp/app/entities/customer/customer.state.js b/src/main/webapp/app/entities/customer/customer.state.js new file mode 100644 index 0000000..8790729 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer.state.js @@ -0,0 +1,184 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('customer', { + parent: 'entity', + url: '/customer?page&sort&search', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Customers' + }, + views: { + 'content@': { + templateUrl: 'app/entities/customer/customers.html', + controller: 'CustomerController', + controllerAs: 'vm' + } + }, + params: { + page: { + value: '1', + squash: true + }, + sort: { + value: 'id,asc', + squash: true + }, + search: null + }, + resolve: { + pagingParams: ['$stateParams', 'PaginationUtil', function ($stateParams, PaginationUtil) { + return { + page: PaginationUtil.parsePage($stateParams.page), + sort: $stateParams.sort, + predicate: PaginationUtil.parsePredicate($stateParams.sort), + ascending: PaginationUtil.parseAscending($stateParams.sort), + search: $stateParams.search + }; + }], + } + }) + .state('customer-detail', { + parent: 'customer', + url: '/customer/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Customer' + }, + views: { + 'content@': { + templateUrl: 'app/entities/customer/customer-detail.html', + controller: 'CustomerDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Customer', function($stateParams, Customer) { + return Customer.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'customer', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('customer-detail.edit', { + parent: 'customer-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/customer/customer-dialog.html', + controller: 'CustomerDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Customer', function(Customer) { + return Customer.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('customer.new', { + parent: 'customer', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/customer/customer-dialog.html', + controller: 'CustomerDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + firstName: null, + lastName: null, + email: null, + telephone: null, + id: null + }; + } + } + }).result.then(function() { + $state.go('customer', null, { reload: 'customer' }); + }, function() { + $state.go('customer'); + }); + }] + }) + .state('customer.edit', { + parent: 'customer', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/customer/customer-dialog.html', + controller: 'CustomerDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Customer', function(Customer) { + return Customer.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('customer', null, { reload: 'customer' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('customer.delete', { + parent: 'customer', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/customer/customer-delete-dialog.html', + controller: 'CustomerDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Customer', function(Customer) { + return Customer.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('customer', null, { reload: 'customer' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/customer/customers.html b/src/main/webapp/app/entities/customer/customers.html new file mode 100644 index 0000000..f9cee27 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customers.html @@ -0,0 +1,70 @@ +
+

Customers

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
ID First Name Last Name Email Telephone Cart
{{customer.id}}{{customer.firstName}}{{customer.lastName}}{{customer.email}}{{customer.telephone}} + {{customer.cart.id}} + +
+ + + +
+
+
+
+ + +
+
diff --git a/src/main/webapp/app/entities/item/item-delete-dialog.controller.js b/src/main/webapp/app/entities/item/item-delete-dialog.controller.js new file mode 100644 index 0000000..666d1f0 --- /dev/null +++ b/src/main/webapp/app/entities/item/item-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('ItemDeleteController',ItemDeleteController); + + ItemDeleteController.$inject = ['$uibModalInstance', 'entity', 'Item']; + + function ItemDeleteController($uibModalInstance, entity, Item) { + var vm = this; + + vm.item = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Item.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/item/item-delete-dialog.html b/src/main/webapp/app/entities/item/item-delete-dialog.html new file mode 100644 index 0000000..449c7e3 --- /dev/null +++ b/src/main/webapp/app/entities/item/item-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/item/item-detail.controller.js b/src/main/webapp/app/entities/item/item-detail.controller.js new file mode 100644 index 0000000..170fe3d --- /dev/null +++ b/src/main/webapp/app/entities/item/item-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('ItemDetailController', ItemDetailController); + + ItemDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Item', 'Category', 'Cart']; + + function ItemDetailController($scope, $rootScope, $stateParams, previousState, entity, Item, Category, Cart) { + var vm = this; + + vm.item = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:itemUpdate', function(event, result) { + vm.item = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/item/item-detail.html b/src/main/webapp/app/entities/item/item-detail.html new file mode 100644 index 0000000..b87b815 --- /dev/null +++ b/src/main/webapp/app/entities/item/item-detail.html @@ -0,0 +1,39 @@ + +
+

Item {{vm.item.id}}

+
+ +
+
Name
+
+ {{vm.item.name}} +
+
Description
+
+ {{vm.item.description}} +
+
Price
+
+ {{vm.item.price}} +
+
Category
+
+ {{vm.item.category.id}} +
+
Cart
+
+ {{vm.item.cart.id}} +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/item/item-dialog.controller.js b/src/main/webapp/app/entities/item/item-dialog.controller.js new file mode 100644 index 0000000..4ddfa86 --- /dev/null +++ b/src/main/webapp/app/entities/item/item-dialog.controller.js @@ -0,0 +1,48 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('ItemDialogController', ItemDialogController); + + ItemDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Item', 'Category', 'Cart']; + + function ItemDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Item, Category, Cart) { + var vm = this; + + vm.item = entity; + vm.clear = clear; + vm.save = save; + vm.categories = Category.query(); + vm.carts = Cart.query(); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.item.id !== null) { + Item.update(vm.item, onSaveSuccess, onSaveError); + } else { + Item.save(vm.item, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:itemUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/item/item-dialog.html b/src/main/webapp/app/entities/item/item-dialog.html new file mode 100644 index 0000000..1ef7fe1 --- /dev/null +++ b/src/main/webapp/app/entities/item/item-dialog.html @@ -0,0 +1,62 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/item/item.controller.js b/src/main/webapp/app/entities/item/item.controller.js new file mode 100644 index 0000000..fce0de8 --- /dev/null +++ b/src/main/webapp/app/entities/item/item.controller.js @@ -0,0 +1,60 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('ItemController', ItemController); + + ItemController.$inject = ['$state', 'Item', 'ParseLinks', 'AlertService', 'paginationConstants', 'pagingParams']; + + function ItemController($state, Item, ParseLinks, AlertService, paginationConstants, pagingParams) { + + var vm = this; + + vm.loadPage = loadPage; + vm.predicate = pagingParams.predicate; + vm.reverse = pagingParams.ascending; + vm.transition = transition; + vm.itemsPerPage = paginationConstants.itemsPerPage; + + loadAll(); + + function loadAll () { + Item.query({ + page: pagingParams.page - 1, + size: vm.itemsPerPage, + sort: sort() + }, onSuccess, onError); + function sort() { + var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')]; + if (vm.predicate !== 'id') { + result.push('id'); + } + return result; + } + function onSuccess(data, headers) { + vm.links = ParseLinks.parse(headers('link')); + vm.totalItems = headers('X-Total-Count'); + vm.queryCount = vm.totalItems; + vm.items = data; + vm.page = pagingParams.page; + } + function onError(error) { + AlertService.error(error.data.message); + } + } + + function loadPage(page) { + vm.page = page; + vm.transition(); + } + + function transition() { + $state.transitionTo($state.$current, { + page: vm.page, + sort: vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc'), + search: vm.currentSearch + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/item/item.service.js b/src/main/webapp/app/entities/item/item.service.js new file mode 100644 index 0000000..2621883 --- /dev/null +++ b/src/main/webapp/app/entities/item/item.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Item', Item); + + Item.$inject = ['$resource']; + + function Item ($resource) { + var resourceUrl = 'api/items/:id'; + + return $resource(resourceUrl, {}, { + 'query': { method: 'GET', isArray: true}, + 'get': { + method: 'GET', + transformResponse: function (data) { + if (data) { + data = angular.fromJson(data); + } + return data; + } + }, + 'update': { method:'PUT' } + }); + } +})(); diff --git a/src/main/webapp/app/entities/item/item.state.js b/src/main/webapp/app/entities/item/item.state.js new file mode 100644 index 0000000..1a5f328 --- /dev/null +++ b/src/main/webapp/app/entities/item/item.state.js @@ -0,0 +1,183 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('item', { + parent: 'entity', + url: '/item?page&sort&search', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Items' + }, + views: { + 'content@': { + templateUrl: 'app/entities/item/items.html', + controller: 'ItemController', + controllerAs: 'vm' + } + }, + params: { + page: { + value: '1', + squash: true + }, + sort: { + value: 'id,asc', + squash: true + }, + search: null + }, + resolve: { + pagingParams: ['$stateParams', 'PaginationUtil', function ($stateParams, PaginationUtil) { + return { + page: PaginationUtil.parsePage($stateParams.page), + sort: $stateParams.sort, + predicate: PaginationUtil.parsePredicate($stateParams.sort), + ascending: PaginationUtil.parseAscending($stateParams.sort), + search: $stateParams.search + }; + }], + } + }) + .state('item-detail', { + parent: 'item', + url: '/item/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Item' + }, + views: { + 'content@': { + templateUrl: 'app/entities/item/item-detail.html', + controller: 'ItemDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Item', function($stateParams, Item) { + return Item.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'item', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('item-detail.edit', { + parent: 'item-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/item/item-dialog.html', + controller: 'ItemDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Item', function(Item) { + return Item.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('item.new', { + parent: 'item', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/item/item-dialog.html', + controller: 'ItemDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + name: null, + description: null, + price: null, + id: null + }; + } + } + }).result.then(function() { + $state.go('item', null, { reload: 'item' }); + }, function() { + $state.go('item'); + }); + }] + }) + .state('item.edit', { + parent: 'item', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/item/item-dialog.html', + controller: 'ItemDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Item', function(Item) { + return Item.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('item', null, { reload: 'item' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('item.delete', { + parent: 'item', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/item/item-delete-dialog.html', + controller: 'ItemDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Item', function(Item) { + return Item.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('item', null, { reload: 'item' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/item/items.html b/src/main/webapp/app/entities/item/items.html new file mode 100644 index 0000000..a2caacd --- /dev/null +++ b/src/main/webapp/app/entities/item/items.html @@ -0,0 +1,72 @@ +
+

Items

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
ID Name Description Price Category Cart
{{item.id}}{{item.name}}{{item.description}}{{item.price}} + {{item.category.id}} + + {{item.cart.id}} + +
+ + + +
+
+
+
+ + +
+
diff --git a/src/main/webapp/app/layouts/navbar/navbar.html b/src/main/webapp/app/layouts/navbar/navbar.html index f5332bb..3999ecf 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.html +++ b/src/main/webapp/app/layouts/navbar/navbar.html @@ -44,6 +44,48 @@ Price +
  • + +   + Item + +
  • +
  • + +   + Category + +
  • +
  • + +   + Customer + +
  • +
  • + +   + Item + +
  • +
  • + +   + Category + +
  • +
  • + +   + Customer + +
  • +
  • + +   + Cart + +
  • diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index a52cdee..846aab8 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -300,7 +300,31 @@

    Connect to Start Bootstrap:

    + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/apeps/firstapp/web/rest/CartResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/CartResourceIntTest.java new file mode 100644 index 0000000..57a716c --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/CartResourceIntTest.java @@ -0,0 +1,225 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Cart; +import org.apeps.firstapp.repository.CartRepository; +import org.apeps.firstapp.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the CartResource REST controller. + * + * @see CartResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class CartResourceIntTest { + + @Autowired + private CartRepository cartRepository; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restCartMockMvc; + + private Cart cart; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final CartResource cartResource = new CartResource(cartRepository); + this.restCartMockMvc = MockMvcBuilders.standaloneSetup(cartResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setMessageConverters(jacksonMessageConverter).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Cart createEntity(EntityManager em) { + Cart cart = new Cart(); + return cart; + } + + @Before + public void initTest() { + cart = createEntity(em); + } + + @Test + @Transactional + public void createCart() throws Exception { + int databaseSizeBeforeCreate = cartRepository.findAll().size(); + + // Create the Cart + restCartMockMvc.perform(post("/api/carts") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(cart))) + .andExpect(status().isCreated()); + + // Validate the Cart in the database + List cartList = cartRepository.findAll(); + assertThat(cartList).hasSize(databaseSizeBeforeCreate + 1); + Cart testCart = cartList.get(cartList.size() - 1); + } + + @Test + @Transactional + public void createCartWithExistingId() throws Exception { + int databaseSizeBeforeCreate = cartRepository.findAll().size(); + + // Create the Cart with an existing ID + cart.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restCartMockMvc.perform(post("/api/carts") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(cart))) + .andExpect(status().isBadRequest()); + + // Validate the Cart in the database + List cartList = cartRepository.findAll(); + assertThat(cartList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void getAllCarts() throws Exception { + // Initialize the database + cartRepository.saveAndFlush(cart); + + // Get all the cartList + restCartMockMvc.perform(get("/api/carts?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(cart.getId().intValue()))); + } + + @Test + @Transactional + public void getCart() throws Exception { + // Initialize the database + cartRepository.saveAndFlush(cart); + + // Get the cart + restCartMockMvc.perform(get("/api/carts/{id}", cart.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(cart.getId().intValue())); + } + + @Test + @Transactional + public void getNonExistingCart() throws Exception { + // Get the cart + restCartMockMvc.perform(get("/api/carts/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateCart() throws Exception { + // Initialize the database + cartRepository.saveAndFlush(cart); + int databaseSizeBeforeUpdate = cartRepository.findAll().size(); + + // Update the cart + Cart updatedCart = cartRepository.findOne(cart.getId()); + + restCartMockMvc.perform(put("/api/carts") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedCart))) + .andExpect(status().isOk()); + + // Validate the Cart in the database + List cartList = cartRepository.findAll(); + assertThat(cartList).hasSize(databaseSizeBeforeUpdate); + Cart testCart = cartList.get(cartList.size() - 1); + } + + @Test + @Transactional + public void updateNonExistingCart() throws Exception { + int databaseSizeBeforeUpdate = cartRepository.findAll().size(); + + // Create the Cart + + // If the entity doesn't have an ID, it will be created instead of just being updated + restCartMockMvc.perform(put("/api/carts") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(cart))) + .andExpect(status().isCreated()); + + // Validate the Cart in the database + List cartList = cartRepository.findAll(); + assertThat(cartList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deleteCart() throws Exception { + // Initialize the database + cartRepository.saveAndFlush(cart); + int databaseSizeBeforeDelete = cartRepository.findAll().size(); + + // Get the cart + restCartMockMvc.perform(delete("/api/carts/{id}", cart.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List cartList = cartRepository.findAll(); + assertThat(cartList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Cart.class); + Cart cart1 = new Cart(); + cart1.setId(1L); + Cart cart2 = new Cart(); + cart2.setId(cart1.getId()); + assertThat(cart1).isEqualTo(cart2); + cart2.setId(2L); + assertThat(cart1).isNotEqualTo(cart2); + cart1.setId(null); + assertThat(cart1).isNotEqualTo(cart2); + } +} diff --git a/src/test/java/org/apeps/firstapp/web/rest/CategoryResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/CategoryResourceIntTest.java new file mode 100644 index 0000000..46a6f56 --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/CategoryResourceIntTest.java @@ -0,0 +1,259 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Category; +import org.apeps.firstapp.repository.CategoryRepository; +import org.apeps.firstapp.service.CategoryService; +import org.apeps.firstapp.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the CategoryResource REST controller. + * + * @see CategoryResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class CategoryResourceIntTest { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + @Autowired + private CategoryRepository categoryRepository; + + @Autowired + private CategoryService categoryService; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restCategoryMockMvc; + + private Category category; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final CategoryResource categoryResource = new CategoryResource(categoryService); + this.restCategoryMockMvc = MockMvcBuilders.standaloneSetup(categoryResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setMessageConverters(jacksonMessageConverter).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Category createEntity(EntityManager em) { + Category category = new Category() + .name(DEFAULT_NAME); + return category; + } + + @Before + public void initTest() { + category = createEntity(em); + } + + @Test + @Transactional + public void createCategory() throws Exception { + int databaseSizeBeforeCreate = categoryRepository.findAll().size(); + + // Create the Category + restCategoryMockMvc.perform(post("/api/categories") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(category))) + .andExpect(status().isCreated()); + + // Validate the Category in the database + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeCreate + 1); + Category testCategory = categoryList.get(categoryList.size() - 1); + assertThat(testCategory.getName()).isEqualTo(DEFAULT_NAME); + } + + @Test + @Transactional + public void createCategoryWithExistingId() throws Exception { + int databaseSizeBeforeCreate = categoryRepository.findAll().size(); + + // Create the Category with an existing ID + category.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restCategoryMockMvc.perform(post("/api/categories") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(category))) + .andExpect(status().isBadRequest()); + + // Validate the Category in the database + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = categoryRepository.findAll().size(); + // set the field null + category.setName(null); + + // Create the Category, which fails. + + restCategoryMockMvc.perform(post("/api/categories") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(category))) + .andExpect(status().isBadRequest()); + + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void getAllCategories() throws Exception { + // Initialize the database + categoryRepository.saveAndFlush(category); + + // Get all the categoryList + restCategoryMockMvc.perform(get("/api/categories?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(category.getId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))); + } + + @Test + @Transactional + public void getCategory() throws Exception { + // Initialize the database + categoryRepository.saveAndFlush(category); + + // Get the category + restCategoryMockMvc.perform(get("/api/categories/{id}", category.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(category.getId().intValue())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())); + } + + @Test + @Transactional + public void getNonExistingCategory() throws Exception { + // Get the category + restCategoryMockMvc.perform(get("/api/categories/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateCategory() throws Exception { + // Initialize the database + categoryService.save(category); + + int databaseSizeBeforeUpdate = categoryRepository.findAll().size(); + + // Update the category + Category updatedCategory = categoryRepository.findOne(category.getId()); + updatedCategory + .name(UPDATED_NAME); + + restCategoryMockMvc.perform(put("/api/categories") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedCategory))) + .andExpect(status().isOk()); + + // Validate the Category in the database + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeUpdate); + Category testCategory = categoryList.get(categoryList.size() - 1); + assertThat(testCategory.getName()).isEqualTo(UPDATED_NAME); + } + + @Test + @Transactional + public void updateNonExistingCategory() throws Exception { + int databaseSizeBeforeUpdate = categoryRepository.findAll().size(); + + // Create the Category + + // If the entity doesn't have an ID, it will be created instead of just being updated + restCategoryMockMvc.perform(put("/api/categories") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(category))) + .andExpect(status().isCreated()); + + // Validate the Category in the database + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deleteCategory() throws Exception { + // Initialize the database + categoryService.save(category); + + int databaseSizeBeforeDelete = categoryRepository.findAll().size(); + + // Get the category + restCategoryMockMvc.perform(delete("/api/categories/{id}", category.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List categoryList = categoryRepository.findAll(); + assertThat(categoryList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Category.class); + Category category1 = new Category(); + category1.setId(1L); + Category category2 = new Category(); + category2.setId(category1.getId()); + assertThat(category1).isEqualTo(category2); + category2.setId(2L); + assertThat(category1).isNotEqualTo(category2); + category1.setId(null); + assertThat(category1).isNotEqualTo(category2); + } +} diff --git a/src/test/java/org/apeps/firstapp/web/rest/CustomerResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/CustomerResourceIntTest.java new file mode 100644 index 0000000..6629753 --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/CustomerResourceIntTest.java @@ -0,0 +1,262 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Customer; +import org.apeps.firstapp.repository.CustomerRepository; +import org.apeps.firstapp.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the CustomerResource REST controller. + * + * @see CustomerResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class CustomerResourceIntTest { + + private static final String DEFAULT_FIRST_NAME = "AAAAAAAAAA"; + private static final String UPDATED_FIRST_NAME = "BBBBBBBBBB"; + + private static final String DEFAULT_LAST_NAME = "AAAAAAAAAA"; + private static final String UPDATED_LAST_NAME = "BBBBBBBBBB"; + + private static final String DEFAULT_EMAIL = "AAAAAAAAAA"; + private static final String UPDATED_EMAIL = "BBBBBBBBBB"; + + private static final String DEFAULT_TELEPHONE = "AAAAAAAAAA"; + private static final String UPDATED_TELEPHONE = "BBBBBBBBBB"; + + @Autowired + private CustomerRepository customerRepository; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restCustomerMockMvc; + + private Customer customer; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final CustomerResource customerResource = new CustomerResource(customerRepository); + this.restCustomerMockMvc = MockMvcBuilders.standaloneSetup(customerResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setMessageConverters(jacksonMessageConverter).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Customer createEntity(EntityManager em) { + Customer customer = new Customer() + .firstName(DEFAULT_FIRST_NAME) + .lastName(DEFAULT_LAST_NAME) + .email(DEFAULT_EMAIL) + .telephone(DEFAULT_TELEPHONE); + return customer; + } + + @Before + public void initTest() { + customer = createEntity(em); + } + + @Test + @Transactional + public void createCustomer() throws Exception { + int databaseSizeBeforeCreate = customerRepository.findAll().size(); + + // Create the Customer + restCustomerMockMvc.perform(post("/api/customers") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(customer))) + .andExpect(status().isCreated()); + + // Validate the Customer in the database + List customerList = customerRepository.findAll(); + assertThat(customerList).hasSize(databaseSizeBeforeCreate + 1); + Customer testCustomer = customerList.get(customerList.size() - 1); + assertThat(testCustomer.getFirstName()).isEqualTo(DEFAULT_FIRST_NAME); + assertThat(testCustomer.getLastName()).isEqualTo(DEFAULT_LAST_NAME); + assertThat(testCustomer.getEmail()).isEqualTo(DEFAULT_EMAIL); + assertThat(testCustomer.getTelephone()).isEqualTo(DEFAULT_TELEPHONE); + } + + @Test + @Transactional + public void createCustomerWithExistingId() throws Exception { + int databaseSizeBeforeCreate = customerRepository.findAll().size(); + + // Create the Customer with an existing ID + customer.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restCustomerMockMvc.perform(post("/api/customers") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(customer))) + .andExpect(status().isBadRequest()); + + // Validate the Customer in the database + List customerList = customerRepository.findAll(); + assertThat(customerList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void getAllCustomers() throws Exception { + // Initialize the database + customerRepository.saveAndFlush(customer); + + // Get all the customerList + restCustomerMockMvc.perform(get("/api/customers?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(customer.getId().intValue()))) + .andExpect(jsonPath("$.[*].firstName").value(hasItem(DEFAULT_FIRST_NAME.toString()))) + .andExpect(jsonPath("$.[*].lastName").value(hasItem(DEFAULT_LAST_NAME.toString()))) + .andExpect(jsonPath("$.[*].email").value(hasItem(DEFAULT_EMAIL.toString()))) + .andExpect(jsonPath("$.[*].telephone").value(hasItem(DEFAULT_TELEPHONE.toString()))); + } + + @Test + @Transactional + public void getCustomer() throws Exception { + // Initialize the database + customerRepository.saveAndFlush(customer); + + // Get the customer + restCustomerMockMvc.perform(get("/api/customers/{id}", customer.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(customer.getId().intValue())) + .andExpect(jsonPath("$.firstName").value(DEFAULT_FIRST_NAME.toString())) + .andExpect(jsonPath("$.lastName").value(DEFAULT_LAST_NAME.toString())) + .andExpect(jsonPath("$.email").value(DEFAULT_EMAIL.toString())) + .andExpect(jsonPath("$.telephone").value(DEFAULT_TELEPHONE.toString())); + } + + @Test + @Transactional + public void getNonExistingCustomer() throws Exception { + // Get the customer + restCustomerMockMvc.perform(get("/api/customers/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateCustomer() throws Exception { + // Initialize the database + customerRepository.saveAndFlush(customer); + int databaseSizeBeforeUpdate = customerRepository.findAll().size(); + + // Update the customer + Customer updatedCustomer = customerRepository.findOne(customer.getId()); + updatedCustomer + .firstName(UPDATED_FIRST_NAME) + .lastName(UPDATED_LAST_NAME) + .email(UPDATED_EMAIL) + .telephone(UPDATED_TELEPHONE); + + restCustomerMockMvc.perform(put("/api/customers") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedCustomer))) + .andExpect(status().isOk()); + + // Validate the Customer in the database + List customerList = customerRepository.findAll(); + assertThat(customerList).hasSize(databaseSizeBeforeUpdate); + Customer testCustomer = customerList.get(customerList.size() - 1); + assertThat(testCustomer.getFirstName()).isEqualTo(UPDATED_FIRST_NAME); + assertThat(testCustomer.getLastName()).isEqualTo(UPDATED_LAST_NAME); + assertThat(testCustomer.getEmail()).isEqualTo(UPDATED_EMAIL); + assertThat(testCustomer.getTelephone()).isEqualTo(UPDATED_TELEPHONE); + } + + @Test + @Transactional + public void updateNonExistingCustomer() throws Exception { + int databaseSizeBeforeUpdate = customerRepository.findAll().size(); + + // Create the Customer + + // If the entity doesn't have an ID, it will be created instead of just being updated + restCustomerMockMvc.perform(put("/api/customers") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(customer))) + .andExpect(status().isCreated()); + + // Validate the Customer in the database + List customerList = customerRepository.findAll(); + assertThat(customerList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deleteCustomer() throws Exception { + // Initialize the database + customerRepository.saveAndFlush(customer); + int databaseSizeBeforeDelete = customerRepository.findAll().size(); + + // Get the customer + restCustomerMockMvc.perform(delete("/api/customers/{id}", customer.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List customerList = customerRepository.findAll(); + assertThat(customerList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Customer.class); + Customer customer1 = new Customer(); + customer1.setId(1L); + Customer customer2 = new Customer(); + customer2.setId(customer1.getId()); + assertThat(customer1).isEqualTo(customer2); + customer2.setId(2L); + assertThat(customer1).isNotEqualTo(customer2); + customer1.setId(null); + assertThat(customer1).isNotEqualTo(customer2); + } +} diff --git a/src/test/java/org/apeps/firstapp/web/rest/ItemResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/ItemResourceIntTest.java new file mode 100644 index 0000000..94bbaad --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/ItemResourceIntTest.java @@ -0,0 +1,277 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Item; +import org.apeps.firstapp.repository.ItemRepository; +import org.apeps.firstapp.service.ItemService; +import org.apeps.firstapp.web.rest.errors.ExceptionTranslator; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Test class for the ItemResource REST controller. + * + * @see ItemResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class ItemResourceIntTest { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + private static final String DEFAULT_DESCRIPTION = "AAAAAAAAAA"; + private static final String UPDATED_DESCRIPTION = "BBBBBBBBBB"; + + private static final Integer DEFAULT_PRICE = 1; + private static final Integer UPDATED_PRICE = 2; + + @Autowired + private ItemRepository itemRepository; + + @Autowired + private ItemService itemService; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restItemMockMvc; + + private Item item; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final ItemResource itemResource = new ItemResource(itemService); + this.restItemMockMvc = MockMvcBuilders.standaloneSetup(itemResource) + .setCustomArgumentResolvers(pageableArgumentResolver) + .setControllerAdvice(exceptionTranslator) + .setMessageConverters(jacksonMessageConverter).build(); + } + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Item createEntity(EntityManager em) { + Item item = new Item() + .name(DEFAULT_NAME) + .description(DEFAULT_DESCRIPTION) + .price(DEFAULT_PRICE); + return item; + } + + @Before + public void initTest() { + item = createEntity(em); + } + + @Test + @Transactional + public void createItem() throws Exception { + int databaseSizeBeforeCreate = itemRepository.findAll().size(); + + // Create the Item + restItemMockMvc.perform(post("/api/items") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(item))) + .andExpect(status().isCreated()); + + // Validate the Item in the database + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeCreate + 1); + Item testItem = itemList.get(itemList.size() - 1); + assertThat(testItem.getName()).isEqualTo(DEFAULT_NAME); + assertThat(testItem.getDescription()).isEqualTo(DEFAULT_DESCRIPTION); + assertThat(testItem.getPrice()).isEqualTo(DEFAULT_PRICE); + } + + @Test + @Transactional + public void createItemWithExistingId() throws Exception { + int databaseSizeBeforeCreate = itemRepository.findAll().size(); + + // Create the Item with an existing ID + item.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restItemMockMvc.perform(post("/api/items") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(item))) + .andExpect(status().isBadRequest()); + + // Validate the Item in the database + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = itemRepository.findAll().size(); + // set the field null + item.setName(null); + + // Create the Item, which fails. + + restItemMockMvc.perform(post("/api/items") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(item))) + .andExpect(status().isBadRequest()); + + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void getAllItems() throws Exception { + // Initialize the database + itemRepository.saveAndFlush(item); + + // Get all the itemList + restItemMockMvc.perform(get("/api/items?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(item.getId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))) + .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString()))) + .andExpect(jsonPath("$.[*].price").value(hasItem(DEFAULT_PRICE))); + } + + @Test + @Transactional + public void getItem() throws Exception { + // Initialize the database + itemRepository.saveAndFlush(item); + + // Get the item + restItemMockMvc.perform(get("/api/items/{id}", item.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(item.getId().intValue())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())) + .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString())) + .andExpect(jsonPath("$.price").value(DEFAULT_PRICE)); + } + + @Test + @Transactional + public void getNonExistingItem() throws Exception { + // Get the item + restItemMockMvc.perform(get("/api/items/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateItem() throws Exception { + // Initialize the database + itemService.save(item); + + int databaseSizeBeforeUpdate = itemRepository.findAll().size(); + + // Update the item + Item updatedItem = itemRepository.findOne(item.getId()); + updatedItem + .name(UPDATED_NAME) + .description(UPDATED_DESCRIPTION) + .price(UPDATED_PRICE); + + restItemMockMvc.perform(put("/api/items") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedItem))) + .andExpect(status().isOk()); + + // Validate the Item in the database + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeUpdate); + Item testItem = itemList.get(itemList.size() - 1); + assertThat(testItem.getName()).isEqualTo(UPDATED_NAME); + assertThat(testItem.getDescription()).isEqualTo(UPDATED_DESCRIPTION); + assertThat(testItem.getPrice()).isEqualTo(UPDATED_PRICE); + } + + @Test + @Transactional + public void updateNonExistingItem() throws Exception { + int databaseSizeBeforeUpdate = itemRepository.findAll().size(); + + // Create the Item + + // If the entity doesn't have an ID, it will be created instead of just being updated + restItemMockMvc.perform(put("/api/items") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(item))) + .andExpect(status().isCreated()); + + // Validate the Item in the database + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deleteItem() throws Exception { + // Initialize the database + itemService.save(item); + + int databaseSizeBeforeDelete = itemRepository.findAll().size(); + + // Get the item + restItemMockMvc.perform(delete("/api/items/{id}", item.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List itemList = itemRepository.findAll(); + assertThat(itemList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Item.class); + Item item1 = new Item(); + item1.setId(1L); + Item item2 = new Item(); + item2.setId(item1.getId()); + assertThat(item1).isEqualTo(item2); + item2.setId(2L); + assertThat(item1).isNotEqualTo(item2); + item1.setId(null); + assertThat(item1).isNotEqualTo(item2); + } +} diff --git a/src/test/javascript/spec/app/entities/cart/cart-detail.controller.spec.js b/src/test/javascript/spec/app/entities/cart/cart-detail.controller.spec.js new file mode 100644 index 0000000..35ea359 --- /dev/null +++ b/src/test/javascript/spec/app/entities/cart/cart-detail.controller.spec.js @@ -0,0 +1,48 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Cart Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockCart, MockItem, MockCustomer; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockCart = jasmine.createSpy('MockCart'); + MockItem = jasmine.createSpy('MockItem'); + MockCustomer = jasmine.createSpy('MockCustomer'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Cart': MockCart, + 'Item': MockItem, + 'Customer': MockCustomer + }; + createController = function() { + $injector.get('$controller')("CartDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:cartUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +}); diff --git a/src/test/javascript/spec/app/entities/category/category-detail.controller.spec.js b/src/test/javascript/spec/app/entities/category/category-detail.controller.spec.js new file mode 100644 index 0000000..5d60996 --- /dev/null +++ b/src/test/javascript/spec/app/entities/category/category-detail.controller.spec.js @@ -0,0 +1,46 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Category Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockCategory, MockItem; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockCategory = jasmine.createSpy('MockCategory'); + MockItem = jasmine.createSpy('MockItem'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Category': MockCategory, + 'Item': MockItem + }; + createController = function() { + $injector.get('$controller')("CategoryDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:categoryUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +}); diff --git a/src/test/javascript/spec/app/entities/customer/customer-detail.controller.spec.js b/src/test/javascript/spec/app/entities/customer/customer-detail.controller.spec.js new file mode 100644 index 0000000..7427fab --- /dev/null +++ b/src/test/javascript/spec/app/entities/customer/customer-detail.controller.spec.js @@ -0,0 +1,46 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Customer Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockCustomer, MockCart; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockCustomer = jasmine.createSpy('MockCustomer'); + MockCart = jasmine.createSpy('MockCart'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Customer': MockCustomer, + 'Cart': MockCart + }; + createController = function() { + $injector.get('$controller')("CustomerDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:customerUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +}); diff --git a/src/test/javascript/spec/app/entities/item/item-detail.controller.spec.js b/src/test/javascript/spec/app/entities/item/item-detail.controller.spec.js new file mode 100644 index 0000000..b888532 --- /dev/null +++ b/src/test/javascript/spec/app/entities/item/item-detail.controller.spec.js @@ -0,0 +1,48 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Item Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockItem, MockCategory, MockCart; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockItem = jasmine.createSpy('MockItem'); + MockCategory = jasmine.createSpy('MockCategory'); + MockCart = jasmine.createSpy('MockCart'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Item': MockItem, + 'Category': MockCategory, + 'Cart': MockCart + }; + createController = function() { + $injector.get('$controller')("ItemDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:itemUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +});