diff --git a/.jhipster/Offering.json b/.jhipster/Offering.json new file mode 100644 index 0000000..f24b16b --- /dev/null +++ b/.jhipster/Offering.json @@ -0,0 +1,45 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipType": "one-to-many", + "relationshipName": "prices", + "otherEntityName": "price", + "otherEntityRelationshipName": "offering" + }, + { + "relationshipName": "offering", + "otherEntityName": "offering", + "relationshipType": "many-to-one", + "otherEntityField": "id" + }, + { + "relationshipType": "one-to-many", + "relationshipName": "childs", + "otherEntityName": "offering", + "otherEntityRelationshipName": "offering" + } + ], + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + }, + { + "fieldName": "description", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + } + ], + "changelogDate": "20171118114136", + "entityTableName": "offering", + "dto": "no", + "pagination": "no", + "service": "no", + "jpaMetamodelFiltering": false +} \ No newline at end of file diff --git a/.jhipster/Price.json b/.jhipster/Price.json new file mode 100644 index 0000000..43b47b2 --- /dev/null +++ b/.jhipster/Price.json @@ -0,0 +1,26 @@ +{ + "fluentMethods": true, + "relationships": [ + { + "relationshipName": "offering", + "otherEntityName": "offering", + "relationshipType": "many-to-one", + "otherEntityField": "id" + } + ], + "fields": [ + { + "fieldName": "value", + "fieldType": "Double", + "fieldValidateRules": [ + "required" + ] + } + ], + "changelogDate": "20171118114137", + "entityTableName": "price", + "dto": "no", + "pagination": "no", + "service": "no", + "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..2c26447 100644 --- a/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java +++ b/src/main/java/org/apeps/firstapp/config/CacheConfiguration.java @@ -43,6 +43,10 @@ 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.Offering.class.getName(), jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Offering.class.getName() + ".prices", jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Offering.class.getName() + ".childs", jcacheConfiguration); + cm.createCache(org.apeps.firstapp.domain.Price.class.getName(), jcacheConfiguration); // jhipster-needle-ehcache-add-entry }; } diff --git a/src/main/java/org/apeps/firstapp/domain/Offering.java b/src/main/java/org/apeps/firstapp/domain/Offering.java new file mode 100644 index 0000000..2f70122 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Offering.java @@ -0,0 +1,177 @@ +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 Offering. + */ +@Entity +@Table(name = "offering") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Offering 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; + + @NotNull + @Column(name = "description", nullable = false) + private String description; + + @OneToMany(mappedBy = "offering") + @JsonIgnore + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + private Set prices = new HashSet<>(); + + @ManyToOne + private Offering offering; + + @OneToMany(mappedBy = "offering") + @JsonIgnore + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + private Set childs = 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 getName() { + return name; + } + + public Offering name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public Offering description(String description) { + this.description = description; + return this; + } + + public void setDescription(String description) { + this.description = description; + } + + public Set getPrices() { + return prices; + } + + public Offering prices(Set prices) { + this.prices = prices; + return this; + } + + public Offering addPrices(Price price) { + this.prices.add(price); + price.setOffering(this); + return this; + } + + public Offering removePrices(Price price) { + this.prices.remove(price); + price.setOffering(null); + return this; + } + + public void setPrices(Set prices) { + this.prices = prices; + } + + public Offering getOffering() { + return offering; + } + + public Offering offering(Offering offering) { + this.offering = offering; + return this; + } + + public void setOffering(Offering offering) { + this.offering = offering; + } + + public Set getChilds() { + return childs; + } + + public Offering childs(Set offerings) { + this.childs = offerings; + return this; + } + + public Offering addChilds(Offering offering) { + this.childs.add(offering); + offering.setOffering(this); + return this; + } + + public Offering removeChilds(Offering offering) { + this.childs.remove(offering); + offering.setOffering(null); + return this; + } + + public void setChilds(Set offerings) { + this.childs = offerings; + } + // 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; + } + Offering offering = (Offering) o; + if (offering.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), offering.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Offering{" + + "id=" + getId() + + ", name='" + getName() + "'" + + ", description='" + getDescription() + "'" + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/domain/Price.java b/src/main/java/org/apeps/firstapp/domain/Price.java new file mode 100644 index 0000000..24d2d58 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/domain/Price.java @@ -0,0 +1,96 @@ +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 Price. + */ +@Entity +@Table(name = "price") +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) +public class Price implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @NotNull + @Column(name = "jhi_value", nullable = false) + private Double value; + + @ManyToOne + private Offering offering; + + // 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 Double getValue() { + return value; + } + + public Price value(Double value) { + this.value = value; + return this; + } + + public void setValue(Double value) { + this.value = value; + } + + public Offering getOffering() { + return offering; + } + + public Price offering(Offering offering) { + this.offering = offering; + return this; + } + + public void setOffering(Offering offering) { + this.offering = offering; + } + // 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; + } + Price price = (Price) o; + if (price.getId() == null || getId() == null) { + return false; + } + return Objects.equals(getId(), price.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString() { + return "Price{" + + "id=" + getId() + + ", value='" + getValue() + "'" + + "}"; + } +} diff --git a/src/main/java/org/apeps/firstapp/repository/OfferingRepository.java b/src/main/java/org/apeps/firstapp/repository/OfferingRepository.java new file mode 100644 index 0000000..140a739 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/OfferingRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Offering; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Offering entity. + */ +@SuppressWarnings("unused") +@Repository +public interface OfferingRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/repository/PriceRepository.java b/src/main/java/org/apeps/firstapp/repository/PriceRepository.java new file mode 100644 index 0000000..20136ba --- /dev/null +++ b/src/main/java/org/apeps/firstapp/repository/PriceRepository.java @@ -0,0 +1,16 @@ +package org.apeps.firstapp.repository; + +import org.apeps.firstapp.domain.Price; +import org.springframework.stereotype.Repository; + +import org.springframework.data.jpa.repository.*; + + +/** + * Spring Data JPA repository for the Price entity. + */ +@SuppressWarnings("unused") +@Repository +public interface PriceRepository extends JpaRepository { + +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/OfferingResource.java b/src/main/java/org/apeps/firstapp/web/rest/OfferingResource.java new file mode 100644 index 0000000..2feffe3 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/OfferingResource.java @@ -0,0 +1,120 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Offering; + +import org.apeps.firstapp.repository.OfferingRepository; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Offering. + */ +@RestController +@RequestMapping("/api") +public class OfferingResource { + + private final Logger log = LoggerFactory.getLogger(OfferingResource.class); + + private static final String ENTITY_NAME = "offering"; + + private final OfferingRepository offeringRepository; + + public OfferingResource(OfferingRepository offeringRepository) { + this.offeringRepository = offeringRepository; + } + + /** + * POST /offerings : Create a new offering. + * + * @param offering the offering to create + * @return the ResponseEntity with status 201 (Created) and with body the new offering, or with status 400 (Bad Request) if the offering has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/offerings") + @Timed + public ResponseEntity createOffering(@Valid @RequestBody Offering offering) throws URISyntaxException { + log.debug("REST request to save Offering : {}", offering); + if (offering.getId() != null) { + throw new BadRequestAlertException("A new offering cannot already have an ID", ENTITY_NAME, "idexists"); + } + Offering result = offeringRepository.save(offering); + return ResponseEntity.created(new URI("/api/offerings/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /offerings : Updates an existing offering. + * + * @param offering the offering to update + * @return the ResponseEntity with status 200 (OK) and with body the updated offering, + * or with status 400 (Bad Request) if the offering is not valid, + * or with status 500 (Internal Server Error) if the offering couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/offerings") + @Timed + public ResponseEntity updateOffering(@Valid @RequestBody Offering offering) throws URISyntaxException { + log.debug("REST request to update Offering : {}", offering); + if (offering.getId() == null) { + return createOffering(offering); + } + Offering result = offeringRepository.save(offering); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, offering.getId().toString())) + .body(result); + } + + /** + * GET /offerings : get all the offerings. + * + * @return the ResponseEntity with status 200 (OK) and the list of offerings in body + */ + @GetMapping("/offerings") + @Timed + public List getAllOfferings() { + log.debug("REST request to get all Offerings"); + return offeringRepository.findAll(); + } + + /** + * GET /offerings/:id : get the "id" offering. + * + * @param id the id of the offering to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the offering, or with status 404 (Not Found) + */ + @GetMapping("/offerings/{id}") + @Timed + public ResponseEntity getOffering(@PathVariable Long id) { + log.debug("REST request to get Offering : {}", id); + Offering offering = offeringRepository.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(offering)); + } + + /** + * DELETE /offerings/:id : delete the "id" offering. + * + * @param id the id of the offering to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/offerings/{id}") + @Timed + public ResponseEntity deleteOffering(@PathVariable Long id) { + log.debug("REST request to delete Offering : {}", id); + offeringRepository.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/java/org/apeps/firstapp/web/rest/PriceResource.java b/src/main/java/org/apeps/firstapp/web/rest/PriceResource.java new file mode 100644 index 0000000..609f110 --- /dev/null +++ b/src/main/java/org/apeps/firstapp/web/rest/PriceResource.java @@ -0,0 +1,120 @@ +package org.apeps.firstapp.web.rest; + +import com.codahale.metrics.annotation.Timed; +import org.apeps.firstapp.domain.Price; + +import org.apeps.firstapp.repository.PriceRepository; +import org.apeps.firstapp.web.rest.errors.BadRequestAlertException; +import org.apeps.firstapp.web.rest.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; + +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing Price. + */ +@RestController +@RequestMapping("/api") +public class PriceResource { + + private final Logger log = LoggerFactory.getLogger(PriceResource.class); + + private static final String ENTITY_NAME = "price"; + + private final PriceRepository priceRepository; + + public PriceResource(PriceRepository priceRepository) { + this.priceRepository = priceRepository; + } + + /** + * POST /prices : Create a new price. + * + * @param price the price to create + * @return the ResponseEntity with status 201 (Created) and with body the new price, or with status 400 (Bad Request) if the price has already an ID + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PostMapping("/prices") + @Timed + public ResponseEntity createPrice(@Valid @RequestBody Price price) throws URISyntaxException { + log.debug("REST request to save Price : {}", price); + if (price.getId() != null) { + throw new BadRequestAlertException("A new price cannot already have an ID", ENTITY_NAME, "idexists"); + } + Price result = priceRepository.save(price); + return ResponseEntity.created(new URI("/api/prices/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * PUT /prices : Updates an existing price. + * + * @param price the price to update + * @return the ResponseEntity with status 200 (OK) and with body the updated price, + * or with status 400 (Bad Request) if the price is not valid, + * or with status 500 (Internal Server Error) if the price couldn't be updated + * @throws URISyntaxException if the Location URI syntax is incorrect + */ + @PutMapping("/prices") + @Timed + public ResponseEntity updatePrice(@Valid @RequestBody Price price) throws URISyntaxException { + log.debug("REST request to update Price : {}", price); + if (price.getId() == null) { + return createPrice(price); + } + Price result = priceRepository.save(price); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, price.getId().toString())) + .body(result); + } + + /** + * GET /prices : get all the prices. + * + * @return the ResponseEntity with status 200 (OK) and the list of prices in body + */ + @GetMapping("/prices") + @Timed + public List getAllPrices() { + log.debug("REST request to get all Prices"); + return priceRepository.findAll(); + } + + /** + * GET /prices/:id : get the "id" price. + * + * @param id the id of the price to retrieve + * @return the ResponseEntity with status 200 (OK) and with body the price, or with status 404 (Not Found) + */ + @GetMapping("/prices/{id}") + @Timed + public ResponseEntity getPrice(@PathVariable Long id) { + log.debug("REST request to get Price : {}", id); + Price price = priceRepository.findOne(id); + return ResponseUtil.wrapOrNotFound(Optional.ofNullable(price)); + } + + /** + * DELETE /prices/:id : delete the "id" price. + * + * @param id the id of the price to delete + * @return the ResponseEntity with status 200 (OK) + */ + @DeleteMapping("/prices/{id}") + @Timed + public ResponseEntity deletePrice(@PathVariable Long id) { + log.debug("REST request to delete Price : {}", id); + priceRepository.delete(id); + return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_Offering.xml b/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_Offering.xml new file mode 100644 index 0000000..117a002 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_Offering.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_constraints_Offering.xml b/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_constraints_Offering.xml new file mode 100644 index 0000000..850a748 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118114136_added_entity_constraints_Offering.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_Price.xml b/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_Price.xml new file mode 100644 index 0000000..96a9aeb --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_Price.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_constraints_Price.xml b/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_constraints_Price.xml new file mode 100644 index 0000000..2aa5203 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20171118114137_added_entity_constraints_Price.xml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index f2b0b1f..1bf7f66 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -5,6 +5,10 @@ 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/offering/offering-delete-dialog.controller.js b/src/main/webapp/app/entities/offering/offering-delete-dialog.controller.js new file mode 100644 index 0000000..7dd0762 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('OfferingDeleteController',OfferingDeleteController); + + OfferingDeleteController.$inject = ['$uibModalInstance', 'entity', 'Offering']; + + function OfferingDeleteController($uibModalInstance, entity, Offering) { + var vm = this; + + vm.offering = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Offering.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/offering/offering-delete-dialog.html b/src/main/webapp/app/entities/offering/offering-delete-dialog.html new file mode 100644 index 0000000..7e8f012 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/offering/offering-detail.controller.js b/src/main/webapp/app/entities/offering/offering-detail.controller.js new file mode 100644 index 0000000..c911933 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('OfferingDetailController', OfferingDetailController); + + OfferingDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Offering', 'Price']; + + function OfferingDetailController($scope, $rootScope, $stateParams, previousState, entity, Offering, Price) { + var vm = this; + + vm.offering = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:offeringUpdate', function(event, result) { + vm.offering = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/offering/offering-detail.html b/src/main/webapp/app/entities/offering/offering-detail.html new file mode 100644 index 0000000..00b2520 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-detail.html @@ -0,0 +1,31 @@ + +
+

Offering {{vm.offering.id}}

+
+ +
+
Name
+
+ {{vm.offering.name}} +
+
Description
+
+ {{vm.offering.description}} +
+
Offering
+
+ {{vm.offering.offering.id}} +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/offering/offering-dialog.controller.js b/src/main/webapp/app/entities/offering/offering-dialog.controller.js new file mode 100644 index 0000000..672ba3e --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-dialog.controller.js @@ -0,0 +1,48 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('OfferingDialogController', OfferingDialogController); + + OfferingDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Offering', 'Price']; + + function OfferingDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Offering, Price) { + var vm = this; + + vm.offering = entity; + vm.clear = clear; + vm.save = save; + vm.prices = Price.query(); + vm.offerings = Offering.query(); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.offering.id !== null) { + Offering.update(vm.offering, onSaveSuccess, onSaveError); + } else { + Offering.save(vm.offering, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:offeringUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/offering/offering-dialog.html b/src/main/webapp/app/entities/offering/offering-dialog.html new file mode 100644 index 0000000..f5b48e2 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering-dialog.html @@ -0,0 +1,56 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/offering/offering.controller.js b/src/main/webapp/app/entities/offering/offering.controller.js new file mode 100644 index 0000000..6de5c52 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering.controller.js @@ -0,0 +1,25 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('OfferingController', OfferingController); + + OfferingController.$inject = ['Offering']; + + function OfferingController(Offering) { + + var vm = this; + + vm.offerings = []; + + loadAll(); + + function loadAll() { + Offering.query(function(result) { + vm.offerings = result; + vm.searchQuery = null; + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/offering/offering.service.js b/src/main/webapp/app/entities/offering/offering.service.js new file mode 100644 index 0000000..b908031 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Offering', Offering); + + Offering.$inject = ['$resource']; + + function Offering ($resource) { + var resourceUrl = 'api/offerings/: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/offering/offering.state.js b/src/main/webapp/app/entities/offering/offering.state.js new file mode 100644 index 0000000..ed4ab2f --- /dev/null +++ b/src/main/webapp/app/entities/offering/offering.state.js @@ -0,0 +1,162 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('offering', { + parent: 'entity', + url: '/offering', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Offerings' + }, + views: { + 'content@': { + templateUrl: 'app/entities/offering/offerings.html', + controller: 'OfferingController', + controllerAs: 'vm' + } + }, + resolve: { + } + }) + .state('offering-detail', { + parent: 'offering', + url: '/offering/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Offering' + }, + views: { + 'content@': { + templateUrl: 'app/entities/offering/offering-detail.html', + controller: 'OfferingDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Offering', function($stateParams, Offering) { + return Offering.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'offering', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('offering-detail.edit', { + parent: 'offering-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/offering/offering-dialog.html', + controller: 'OfferingDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Offering', function(Offering) { + return Offering.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('offering.new', { + parent: 'offering', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/offering/offering-dialog.html', + controller: 'OfferingDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + name: null, + description: null, + id: null + }; + } + } + }).result.then(function() { + $state.go('offering', null, { reload: 'offering' }); + }, function() { + $state.go('offering'); + }); + }] + }) + .state('offering.edit', { + parent: 'offering', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/offering/offering-dialog.html', + controller: 'OfferingDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Offering', function(Offering) { + return Offering.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('offering', null, { reload: 'offering' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('offering.delete', { + parent: 'offering', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/offering/offering-delete-dialog.html', + controller: 'OfferingDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Offering', function(Offering) { + return Offering.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('offering', null, { reload: 'offering' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/offering/offerings.html b/src/main/webapp/app/entities/offering/offerings.html new file mode 100644 index 0000000..23b67f5 --- /dev/null +++ b/src/main/webapp/app/entities/offering/offerings.html @@ -0,0 +1,62 @@ +
+

Offerings

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + +
IDNameDescriptionOffering
{{offering.id}}{{offering.name}}{{offering.description}} + {{offering.offering.id}} + +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/entities/price/price-delete-dialog.controller.js b/src/main/webapp/app/entities/price/price-delete-dialog.controller.js new file mode 100644 index 0000000..f31aad2 --- /dev/null +++ b/src/main/webapp/app/entities/price/price-delete-dialog.controller.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('PriceDeleteController',PriceDeleteController); + + PriceDeleteController.$inject = ['$uibModalInstance', 'entity', 'Price']; + + function PriceDeleteController($uibModalInstance, entity, Price) { + var vm = this; + + vm.price = entity; + vm.clear = clear; + vm.confirmDelete = confirmDelete; + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function confirmDelete (id) { + Price.delete({id: id}, + function () { + $uibModalInstance.close(true); + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/price/price-delete-dialog.html b/src/main/webapp/app/entities/price/price-delete-dialog.html new file mode 100644 index 0000000..5b01dc4 --- /dev/null +++ b/src/main/webapp/app/entities/price/price-delete-dialog.html @@ -0,0 +1,19 @@ +
+ + + +
diff --git a/src/main/webapp/app/entities/price/price-detail.controller.js b/src/main/webapp/app/entities/price/price-detail.controller.js new file mode 100644 index 0000000..6ed4a7d --- /dev/null +++ b/src/main/webapp/app/entities/price/price-detail.controller.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('PriceDetailController', PriceDetailController); + + PriceDetailController.$inject = ['$scope', '$rootScope', '$stateParams', 'previousState', 'entity', 'Price', 'Offering']; + + function PriceDetailController($scope, $rootScope, $stateParams, previousState, entity, Price, Offering) { + var vm = this; + + vm.price = entity; + vm.previousState = previousState.name; + + var unsubscribe = $rootScope.$on('firstApp:priceUpdate', function(event, result) { + vm.price = result; + }); + $scope.$on('$destroy', unsubscribe); + } +})(); diff --git a/src/main/webapp/app/entities/price/price-detail.html b/src/main/webapp/app/entities/price/price-detail.html new file mode 100644 index 0000000..a77a1a0 --- /dev/null +++ b/src/main/webapp/app/entities/price/price-detail.html @@ -0,0 +1,27 @@ + +
+

Price {{vm.price.id}}

+
+ +
+
Value
+
+ {{vm.price.value}} +
+
Offering
+
+ {{vm.price.offering.id}} +
+
+ + + + +
diff --git a/src/main/webapp/app/entities/price/price-dialog.controller.js b/src/main/webapp/app/entities/price/price-dialog.controller.js new file mode 100644 index 0000000..7dc7b32 --- /dev/null +++ b/src/main/webapp/app/entities/price/price-dialog.controller.js @@ -0,0 +1,47 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('PriceDialogController', PriceDialogController); + + PriceDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'Price', 'Offering']; + + function PriceDialogController ($timeout, $scope, $stateParams, $uibModalInstance, entity, Price, Offering) { + var vm = this; + + vm.price = entity; + vm.clear = clear; + vm.save = save; + vm.offerings = Offering.query(); + + $timeout(function (){ + angular.element('.form-group:eq(1)>input').focus(); + }); + + function clear () { + $uibModalInstance.dismiss('cancel'); + } + + function save () { + vm.isSaving = true; + if (vm.price.id !== null) { + Price.update(vm.price, onSaveSuccess, onSaveError); + } else { + Price.save(vm.price, onSaveSuccess, onSaveError); + } + } + + function onSaveSuccess (result) { + $scope.$emit('firstApp:priceUpdate', result); + $uibModalInstance.close(result); + vm.isSaving = false; + } + + function onSaveError () { + vm.isSaving = false; + } + + + } +})(); diff --git a/src/main/webapp/app/entities/price/price-dialog.html b/src/main/webapp/app/entities/price/price-dialog.html new file mode 100644 index 0000000..ca4579d --- /dev/null +++ b/src/main/webapp/app/entities/price/price-dialog.html @@ -0,0 +1,48 @@ + +
+ + + + +
diff --git a/src/main/webapp/app/entities/price/price.controller.js b/src/main/webapp/app/entities/price/price.controller.js new file mode 100644 index 0000000..7e74294 --- /dev/null +++ b/src/main/webapp/app/entities/price/price.controller.js @@ -0,0 +1,25 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .controller('PriceController', PriceController); + + PriceController.$inject = ['Price']; + + function PriceController(Price) { + + var vm = this; + + vm.prices = []; + + loadAll(); + + function loadAll() { + Price.query(function(result) { + vm.prices = result; + vm.searchQuery = null; + }); + } + } +})(); diff --git a/src/main/webapp/app/entities/price/price.service.js b/src/main/webapp/app/entities/price/price.service.js new file mode 100644 index 0000000..3b151f5 --- /dev/null +++ b/src/main/webapp/app/entities/price/price.service.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular + .module('firstApp') + .factory('Price', Price); + + Price.$inject = ['$resource']; + + function Price ($resource) { + var resourceUrl = 'api/prices/: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/price/price.state.js b/src/main/webapp/app/entities/price/price.state.js new file mode 100644 index 0000000..9a29add --- /dev/null +++ b/src/main/webapp/app/entities/price/price.state.js @@ -0,0 +1,161 @@ +(function() { + 'use strict'; + + angular + .module('firstApp') + .config(stateConfig); + + stateConfig.$inject = ['$stateProvider']; + + function stateConfig($stateProvider) { + $stateProvider + .state('price', { + parent: 'entity', + url: '/price', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Prices' + }, + views: { + 'content@': { + templateUrl: 'app/entities/price/prices.html', + controller: 'PriceController', + controllerAs: 'vm' + } + }, + resolve: { + } + }) + .state('price-detail', { + parent: 'price', + url: '/price/{id}', + data: { + authorities: ['ROLE_USER'], + pageTitle: 'Price' + }, + views: { + 'content@': { + templateUrl: 'app/entities/price/price-detail.html', + controller: 'PriceDetailController', + controllerAs: 'vm' + } + }, + resolve: { + entity: ['$stateParams', 'Price', function($stateParams, Price) { + return Price.get({id : $stateParams.id}).$promise; + }], + previousState: ["$state", function ($state) { + var currentStateData = { + name: $state.current.name || 'price', + params: $state.params, + url: $state.href($state.current.name, $state.params) + }; + return currentStateData; + }] + } + }) + .state('price-detail.edit', { + parent: 'price-detail', + url: '/detail/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/price/price-dialog.html', + controller: 'PriceDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Price', function(Price) { + return Price.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('^', {}, { reload: false }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('price.new', { + parent: 'price', + url: '/new', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/price/price-dialog.html', + controller: 'PriceDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: function () { + return { + value: null, + id: null + }; + } + } + }).result.then(function() { + $state.go('price', null, { reload: 'price' }); + }, function() { + $state.go('price'); + }); + }] + }) + .state('price.edit', { + parent: 'price', + url: '/{id}/edit', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/price/price-dialog.html', + controller: 'PriceDialogController', + controllerAs: 'vm', + backdrop: 'static', + size: 'lg', + resolve: { + entity: ['Price', function(Price) { + return Price.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('price', null, { reload: 'price' }); + }, function() { + $state.go('^'); + }); + }] + }) + .state('price.delete', { + parent: 'price', + url: '/{id}/delete', + data: { + authorities: ['ROLE_USER'] + }, + onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) { + $uibModal.open({ + templateUrl: 'app/entities/price/price-delete-dialog.html', + controller: 'PriceDeleteController', + controllerAs: 'vm', + size: 'md', + resolve: { + entity: ['Price', function(Price) { + return Price.get({id : $stateParams.id}).$promise; + }] + } + }).result.then(function() { + $state.go('price', null, { reload: 'price' }); + }, function() { + $state.go('^'); + }); + }] + }); + } + +})(); diff --git a/src/main/webapp/app/entities/price/prices.html b/src/main/webapp/app/entities/price/prices.html new file mode 100644 index 0000000..961afc0 --- /dev/null +++ b/src/main/webapp/app/entities/price/prices.html @@ -0,0 +1,60 @@ +
+

Prices

+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + +
IDValueOffering
{{price.id}}{{price.value}} + {{price.offering.id}} + +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/layouts/navbar/navbar.html b/src/main/webapp/app/layouts/navbar/navbar.html index 07e9106..f5332bb 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.html +++ b/src/main/webapp/app/layouts/navbar/navbar.html @@ -32,6 +32,18 @@ diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index b744bde..a52cdee 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -288,6 +288,18 @@

Connect to Start Bootstrap:

+ + + + + + + + + + + + diff --git a/src/test/java/org/apeps/firstapp/web/rest/OfferingResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/OfferingResourceIntTest.java new file mode 100644 index 0000000..055e28f --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/OfferingResourceIntTest.java @@ -0,0 +1,280 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Offering; +import org.apeps.firstapp.repository.OfferingRepository; +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 OfferingResource REST controller. + * + * @see OfferingResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class OfferingResourceIntTest { + + 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"; + + @Autowired + private OfferingRepository offeringRepository; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restOfferingMockMvc; + + private Offering offering; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final OfferingResource offeringResource = new OfferingResource(offeringRepository); + this.restOfferingMockMvc = MockMvcBuilders.standaloneSetup(offeringResource) + .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 Offering createEntity(EntityManager em) { + Offering offering = new Offering() + .name(DEFAULT_NAME) + .description(DEFAULT_DESCRIPTION); + return offering; + } + + @Before + public void initTest() { + offering = createEntity(em); + } + + @Test + @Transactional + public void createOffering() throws Exception { + int databaseSizeBeforeCreate = offeringRepository.findAll().size(); + + // Create the Offering + restOfferingMockMvc.perform(post("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(offering))) + .andExpect(status().isCreated()); + + // Validate the Offering in the database + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeCreate + 1); + Offering testOffering = offeringList.get(offeringList.size() - 1); + assertThat(testOffering.getName()).isEqualTo(DEFAULT_NAME); + assertThat(testOffering.getDescription()).isEqualTo(DEFAULT_DESCRIPTION); + } + + @Test + @Transactional + public void createOfferingWithExistingId() throws Exception { + int databaseSizeBeforeCreate = offeringRepository.findAll().size(); + + // Create the Offering with an existing ID + offering.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restOfferingMockMvc.perform(post("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(offering))) + .andExpect(status().isBadRequest()); + + // Validate the Offering in the database + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = offeringRepository.findAll().size(); + // set the field null + offering.setName(null); + + // Create the Offering, which fails. + + restOfferingMockMvc.perform(post("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(offering))) + .andExpect(status().isBadRequest()); + + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void checkDescriptionIsRequired() throws Exception { + int databaseSizeBeforeTest = offeringRepository.findAll().size(); + // set the field null + offering.setDescription(null); + + // Create the Offering, which fails. + + restOfferingMockMvc.perform(post("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(offering))) + .andExpect(status().isBadRequest()); + + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void getAllOfferings() throws Exception { + // Initialize the database + offeringRepository.saveAndFlush(offering); + + // Get all the offeringList + restOfferingMockMvc.perform(get("/api/offerings?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(offering.getId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME.toString()))) + .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString()))); + } + + @Test + @Transactional + public void getOffering() throws Exception { + // Initialize the database + offeringRepository.saveAndFlush(offering); + + // Get the offering + restOfferingMockMvc.perform(get("/api/offerings/{id}", offering.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(offering.getId().intValue())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())) + .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString())); + } + + @Test + @Transactional + public void getNonExistingOffering() throws Exception { + // Get the offering + restOfferingMockMvc.perform(get("/api/offerings/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateOffering() throws Exception { + // Initialize the database + offeringRepository.saveAndFlush(offering); + int databaseSizeBeforeUpdate = offeringRepository.findAll().size(); + + // Update the offering + Offering updatedOffering = offeringRepository.findOne(offering.getId()); + updatedOffering + .name(UPDATED_NAME) + .description(UPDATED_DESCRIPTION); + + restOfferingMockMvc.perform(put("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedOffering))) + .andExpect(status().isOk()); + + // Validate the Offering in the database + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeUpdate); + Offering testOffering = offeringList.get(offeringList.size() - 1); + assertThat(testOffering.getName()).isEqualTo(UPDATED_NAME); + assertThat(testOffering.getDescription()).isEqualTo(UPDATED_DESCRIPTION); + } + + @Test + @Transactional + public void updateNonExistingOffering() throws Exception { + int databaseSizeBeforeUpdate = offeringRepository.findAll().size(); + + // Create the Offering + + // If the entity doesn't have an ID, it will be created instead of just being updated + restOfferingMockMvc.perform(put("/api/offerings") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(offering))) + .andExpect(status().isCreated()); + + // Validate the Offering in the database + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deleteOffering() throws Exception { + // Initialize the database + offeringRepository.saveAndFlush(offering); + int databaseSizeBeforeDelete = offeringRepository.findAll().size(); + + // Get the offering + restOfferingMockMvc.perform(delete("/api/offerings/{id}", offering.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List offeringList = offeringRepository.findAll(); + assertThat(offeringList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Offering.class); + Offering offering1 = new Offering(); + offering1.setId(1L); + Offering offering2 = new Offering(); + offering2.setId(offering1.getId()); + assertThat(offering1).isEqualTo(offering2); + offering2.setId(2L); + assertThat(offering1).isNotEqualTo(offering2); + offering1.setId(null); + assertThat(offering1).isNotEqualTo(offering2); + } +} diff --git a/src/test/java/org/apeps/firstapp/web/rest/PriceResourceIntTest.java b/src/test/java/org/apeps/firstapp/web/rest/PriceResourceIntTest.java new file mode 100644 index 0000000..28cc99f --- /dev/null +++ b/src/test/java/org/apeps/firstapp/web/rest/PriceResourceIntTest.java @@ -0,0 +1,253 @@ +package org.apeps.firstapp.web.rest; + +import org.apeps.firstapp.FirstApp; + +import org.apeps.firstapp.domain.Price; +import org.apeps.firstapp.repository.PriceRepository; +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 PriceResource REST controller. + * + * @see PriceResource + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FirstApp.class) +public class PriceResourceIntTest { + + private static final Double DEFAULT_VALUE = 1D; + private static final Double UPDATED_VALUE = 2D; + + @Autowired + private PriceRepository priceRepository; + + @Autowired + private MappingJackson2HttpMessageConverter jacksonMessageConverter; + + @Autowired + private PageableHandlerMethodArgumentResolver pageableArgumentResolver; + + @Autowired + private ExceptionTranslator exceptionTranslator; + + @Autowired + private EntityManager em; + + private MockMvc restPriceMockMvc; + + private Price price; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + final PriceResource priceResource = new PriceResource(priceRepository); + this.restPriceMockMvc = MockMvcBuilders.standaloneSetup(priceResource) + .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 Price createEntity(EntityManager em) { + Price price = new Price() + .value(DEFAULT_VALUE); + return price; + } + + @Before + public void initTest() { + price = createEntity(em); + } + + @Test + @Transactional + public void createPrice() throws Exception { + int databaseSizeBeforeCreate = priceRepository.findAll().size(); + + // Create the Price + restPriceMockMvc.perform(post("/api/prices") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(price))) + .andExpect(status().isCreated()); + + // Validate the Price in the database + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeCreate + 1); + Price testPrice = priceList.get(priceList.size() - 1); + assertThat(testPrice.getValue()).isEqualTo(DEFAULT_VALUE); + } + + @Test + @Transactional + public void createPriceWithExistingId() throws Exception { + int databaseSizeBeforeCreate = priceRepository.findAll().size(); + + // Create the Price with an existing ID + price.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restPriceMockMvc.perform(post("/api/prices") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(price))) + .andExpect(status().isBadRequest()); + + // Validate the Price in the database + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeCreate); + } + + @Test + @Transactional + public void checkValueIsRequired() throws Exception { + int databaseSizeBeforeTest = priceRepository.findAll().size(); + // set the field null + price.setValue(null); + + // Create the Price, which fails. + + restPriceMockMvc.perform(post("/api/prices") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(price))) + .andExpect(status().isBadRequest()); + + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void getAllPrices() throws Exception { + // Initialize the database + priceRepository.saveAndFlush(price); + + // Get all the priceList + restPriceMockMvc.perform(get("/api/prices?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(price.getId().intValue()))) + .andExpect(jsonPath("$.[*].value").value(hasItem(DEFAULT_VALUE.doubleValue()))); + } + + @Test + @Transactional + public void getPrice() throws Exception { + // Initialize the database + priceRepository.saveAndFlush(price); + + // Get the price + restPriceMockMvc.perform(get("/api/prices/{id}", price.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(jsonPath("$.id").value(price.getId().intValue())) + .andExpect(jsonPath("$.value").value(DEFAULT_VALUE.doubleValue())); + } + + @Test + @Transactional + public void getNonExistingPrice() throws Exception { + // Get the price + restPriceMockMvc.perform(get("/api/prices/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updatePrice() throws Exception { + // Initialize the database + priceRepository.saveAndFlush(price); + int databaseSizeBeforeUpdate = priceRepository.findAll().size(); + + // Update the price + Price updatedPrice = priceRepository.findOne(price.getId()); + updatedPrice + .value(UPDATED_VALUE); + + restPriceMockMvc.perform(put("/api/prices") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(updatedPrice))) + .andExpect(status().isOk()); + + // Validate the Price in the database + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeUpdate); + Price testPrice = priceList.get(priceList.size() - 1); + assertThat(testPrice.getValue()).isEqualTo(UPDATED_VALUE); + } + + @Test + @Transactional + public void updateNonExistingPrice() throws Exception { + int databaseSizeBeforeUpdate = priceRepository.findAll().size(); + + // Create the Price + + // If the entity doesn't have an ID, it will be created instead of just being updated + restPriceMockMvc.perform(put("/api/prices") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(price))) + .andExpect(status().isCreated()); + + // Validate the Price in the database + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeUpdate + 1); + } + + @Test + @Transactional + public void deletePrice() throws Exception { + // Initialize the database + priceRepository.saveAndFlush(price); + int databaseSizeBeforeDelete = priceRepository.findAll().size(); + + // Get the price + restPriceMockMvc.perform(delete("/api/prices/{id}", price.getId()) + .accept(TestUtil.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()); + + // Validate the database is empty + List priceList = priceRepository.findAll(); + assertThat(priceList).hasSize(databaseSizeBeforeDelete - 1); + } + + @Test + @Transactional + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Price.class); + Price price1 = new Price(); + price1.setId(1L); + Price price2 = new Price(); + price2.setId(price1.getId()); + assertThat(price1).isEqualTo(price2); + price2.setId(2L); + assertThat(price1).isNotEqualTo(price2); + price1.setId(null); + assertThat(price1).isNotEqualTo(price2); + } +} diff --git a/src/test/javascript/spec/app/entities/offering/offering-detail.controller.spec.js b/src/test/javascript/spec/app/entities/offering/offering-detail.controller.spec.js new file mode 100644 index 0000000..625a5a1 --- /dev/null +++ b/src/test/javascript/spec/app/entities/offering/offering-detail.controller.spec.js @@ -0,0 +1,46 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Offering Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockOffering, MockPrice; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockOffering = jasmine.createSpy('MockOffering'); + MockPrice = jasmine.createSpy('MockPrice'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Offering': MockOffering, + 'Price': MockPrice + }; + createController = function() { + $injector.get('$controller')("OfferingDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:offeringUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +}); diff --git a/src/test/javascript/spec/app/entities/price/price-detail.controller.spec.js b/src/test/javascript/spec/app/entities/price/price-detail.controller.spec.js new file mode 100644 index 0000000..d4f1dc6 --- /dev/null +++ b/src/test/javascript/spec/app/entities/price/price-detail.controller.spec.js @@ -0,0 +1,46 @@ +'use strict'; + +describe('Controller Tests', function() { + + describe('Price Management Detail Controller', function() { + var $scope, $rootScope; + var MockEntity, MockPreviousState, MockPrice, MockOffering; + var createController; + + beforeEach(inject(function($injector) { + $rootScope = $injector.get('$rootScope'); + $scope = $rootScope.$new(); + MockEntity = jasmine.createSpy('MockEntity'); + MockPreviousState = jasmine.createSpy('MockPreviousState'); + MockPrice = jasmine.createSpy('MockPrice'); + MockOffering = jasmine.createSpy('MockOffering'); + + + var locals = { + '$scope': $scope, + '$rootScope': $rootScope, + 'entity': MockEntity, + 'previousState': MockPreviousState, + 'Price': MockPrice, + 'Offering': MockOffering + }; + createController = function() { + $injector.get('$controller')("PriceDetailController", locals); + }; + })); + + + describe('Root Scope Listening', function() { + it('Unregisters root scope listener upon scope destruction', function() { + var eventType = 'firstApp:priceUpdate'; + + createController(); + expect($rootScope.$$listenerCount[eventType]).toEqual(1); + + $scope.$destroy(); + expect($rootScope.$$listenerCount[eventType]).toBeUndefined(); + }); + }); + }); + +});