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..6955f65 --- /dev/null +++ b/.jhipster/Customer.json @@ -0,0 +1,35 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "one-to-many", + "relationshipName": "item", + "otherEntityName": "item", + "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..24d9539 --- /dev/null +++ b/.jhipster/Item.json @@ -0,0 +1,40 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "many-to-one", + "relationshipName": "category", + "otherEntityName": "category", + "otherEntityField": "id" + }, + { + "relationshipName": "customer", + "otherEntityName": "customer", + "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": "infinite-scroll", + "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 49efd82..de3cae3 100644 --- a/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java +++ b/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java @@ -43,6 +43,11 @@ public JCacheManagerCustomizer cacheManagerCustomizer() { cm.createCache(org.apeps.firstapp.domain.User.class.getName() + ".authorities", jcacheConfiguration); cm.createCache(org.apeps.firstapp.domain.PersistentToken.class.getName(), jcacheConfiguration); cm.createCache(org.apeps.firstapp.domain.User.class.getName() + ".persistentTokens", 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); // jhipster-needle-ehcache-add-entry }; } 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..0b2f000 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Customer.java @@ -0,0 +1,162 @@ +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 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; + + @OneToMany(mappedBy = "customer") + @JsonIgnore + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + private Set items = new HashSet<>(); + + // 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 Set getItems() { + return items; + } + + public Customer items(Set items) { + this.items = items; + return this; + } + + public Customer addItem(Item item) { + this.items.add(item); + item.setCustomer(this); + return this; + } + + public Customer removeItem(Item item) { + this.items.remove(item); + item.setCustomer(null); + return this; + } + + public void setItems(Set items) { + this.items = items; + } + // 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..1f4a59f --- /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 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 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 Customer getCustomer() { + return customer; + } + + public Item 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; + } + 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/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/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..480fd4e --- /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..4b066bb --- /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..bb7a88f --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118104228_added_entity_Customer.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index f2b0b1f..44f5320 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -5,6 +5,11 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"> + + + + + 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..be9a4dc --- /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', 'Item']; + + function CustomerDetailController($scope, $rootScope, $stateParams, previousState, entity, Customer, Item) { + 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..d933a78 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-detail.html @@ -0,0 +1,35 @@ + +
+

Customer {{vm.customer.id}}

+
+ +
+
First Name
+
+ {{vm.customer.firstName}} +
+
Last Name
+
+ {{vm.customer.lastName}} +
+
Email
+
+ {{vm.customer.email}} +
+
Telephone
+
+ {{vm.customer.telephone}} +
+
+ + + + +
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..65bff49 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-dialog.controller.js @@ -0,0 +1,47 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('CustomerDialogController', CustomerDialogController); + + CustomerDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Customer', 'Item']; + + function CustomerDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Customer, Item) { + var vm = this; + + vm.customer = entity; + vm.clear = clear; + vm.save = save; + vm.items = Item.query(); + + $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..695c170 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customer-dialog.html @@ -0,0 +1,50 @@ + +
+ + + + +
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..ddbe2f9 --- /dev/null +++ b/src/main/webapp/app/entities/customer/customers.html @@ -0,0 +1,66 @@ +
+

Customers

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
ID First Name Last Name Email Telephone
{{customer.id}}{{customer.firstName}}{{customer.lastName}}{{customer.email}}{{customer.telephone}} +
+ + + +
+
+
+
+ + +
+
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..d8d6dd9 --- /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', 'Customer']; + + function ItemDetailController($scope, $rootScope, $stateParams, previousState, entity, Item, Category, Customer) { + 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..784506d --- /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}} +
+
Customer
+
+ {{vm.item.customer.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..c7c046d --- /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', 'Customer']; + + function ItemDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Item, Category, Customer) { + var vm = this; + + vm.item = entity; + vm.clear = clear; + vm.save = save; + vm.categories = Category.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.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..b62d855 --- /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..845349e --- /dev/null +++ b/src/main/webapp/app/entities/item/item.controller.js @@ -0,0 +1,65 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('ItemController', ItemController); + + ItemController.$inject = ['Item', 'ParseLinks', 'AlertService', 'paginationConstants']; + + function ItemController(Item, ParseLinks, AlertService, paginationConstants) { + + var vm = this; + + vm.items = []; + vm.loadPage = loadPage; + vm.itemsPerPage = paginationConstants.itemsPerPage; + vm.page = 0; + vm.links = { + last: 0 + }; + vm.predicate = 'id'; + vm.reset = reset; + vm.reverse = true; + + loadAll(); + + function loadAll () { + Item.query({ + page: vm.page, + 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'); + for (var i = 0; i < data.length; i++) { + vm.items.push(data[i]); + } + } + + function onError(error) { + AlertService.error(error.data.message); + } + } + + function reset () { + vm.page = 0; + vm.items = []; + loadAll(); + } + + function loadPage(page) { + vm.page = page; + loadAll(); + } + } +})(); 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..faccec1 --- /dev/null +++ b/src/main/webapp/app/entities/item/item.state.js @@ -0,0 +1,163 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('item', { + parent: 'entity', + url: '/item', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Items' + }, + views: { + 'content@': { + templateUrl: 'app/entities/item/items.html', + controller: 'ItemController', + controllerAs: 'vm' + } + }, + resolve: { + } + }) + .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..8bfa7cd --- /dev/null +++ b/src/main/webapp/app/entities/item/items.html @@ -0,0 +1,68 @@ +
+

Items

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
ID Name Description Price Category Customer
{{item.id}}{{item.name}}{{item.description}}{{item.price}} + {{item.category.id}} + + {{item.customer.id}} + +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/layouts/navbar/navbar.html b/src/main/webapp/app/layouts/navbar/navbar.html index 07e9106..db36219 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.html +++ b/src/main/webapp/app/layouts/navbar/navbar.html @@ -32,6 +32,24 @@ diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index ddb6dc6..538c1a9 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -100,7 +100,25 @@

You must enable javascript to view this page.

+ + + + + + + + + + + + + + + + + + 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/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..caf1db6 --- /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, MockItem; + 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'); + MockItem = jasmine.createSpy('MockItem'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Customer': MockCustomer, + 'Item': MockItem + }; + 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..c6f010d --- /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, MockCustomer; + 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'); + MockCustomer = jasmine.createSpy('MockCustomer'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Item': MockItem, + 'Category': MockCategory, + 'Customer': MockCustomer + }; + 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(); + }); + }); + }); + +});