Commit 08e0761f authored by Ololw's avatar Ololw
Browse files

BDD Ajout table Taux

parent 22c23146
......@@ -7,6 +7,12 @@
"otherEntityName": "vehicule",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "agence"
},
{
"relationshipName": "taux",
"otherEntityName": "taux",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "agence"
}
],
"fields": [
......
{
"fluentMethods": true,
"clientRootFolder": "",
"relationships": [
{
"relationshipName": "agence",
"otherEntityName": "agence",
"relationshipType": "many-to-one",
"relationshipValidateRules": [
"required"
],
"otherEntityField": "id"
}
],
"fields": [
{
"fieldName": "date",
"fieldType": "Instant",
"fieldValidateRules": [
"required"
]
},
{
"fieldName": "taux",
"fieldType": "Long",
"fieldValidateRules": [
"required"
]
}
],
"changelogDate": "20181105135142",
"dto": "no",
"searchEngine": "elasticsearch",
"service": "no",
"entityTableName": "taux",
"jpaMetamodelFiltering": false,
"pagination": "no"
}
......@@ -40,6 +40,10 @@ public class Agence implements Serializable {
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Vehicule> vehicules = new HashSet<>();
@OneToMany(mappedBy = "agence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Taux> tauxes = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
......@@ -99,6 +103,31 @@ public class Agence implements Serializable {
public void setVehicules(Set<Vehicule> vehicules) {
this.vehicules = vehicules;
}
public Set<Taux> getTauxes() {
return tauxes;
}
public Agence tauxes(Set<Taux> tauxes) {
this.tauxes = tauxes;
return this;
}
public Agence addTaux(Taux taux) {
this.tauxes.add(taux);
taux.setAgence(this);
return this;
}
public Agence removeTaux(Taux taux) {
this.tauxes.remove(taux);
taux.setAgence(null);
return this;
}
public void setTauxes(Set<Taux> tauxes) {
this.tauxes = tauxes;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
......
package com.mycompany.myapp.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.validation.constraints.*;
import org.springframework.data.elasticsearch.annotations.Document;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
/**
* A Taux.
*/
@Entity
@Table(name = "taux")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "taux")
public class Taux implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Column(name = "jhi_date", nullable = false)
private Instant date;
@NotNull
@Column(name = "taux", nullable = false)
private Long taux;
@ManyToOne(optional = false)
@NotNull
@JsonIgnoreProperties("tauxes")
private Agence agence;
// 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 Instant getDate() {
return date;
}
public Taux date(Instant date) {
this.date = date;
return this;
}
public void setDate(Instant date) {
this.date = date;
}
public Long getTaux() {
return taux;
}
public Taux taux(Long taux) {
this.taux = taux;
return this;
}
public void setTaux(Long taux) {
this.taux = taux;
}
public Agence getAgence() {
return agence;
}
public Taux agence(Agence agence) {
this.agence = agence;
return this;
}
public void setAgence(Agence agence) {
this.agence = agence;
}
// 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;
}
Taux taux = (Taux) o;
if (taux.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), taux.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "Taux{" +
"id=" + getId() +
", date='" + getDate() + "'" +
", taux=" + getTaux() +
"}";
}
}
package com.mycompany.myapp.repository;
import com.mycompany.myapp.domain.Taux;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
/**
* Spring Data repository for the Taux entity.
*/
@SuppressWarnings("unused")
@Repository
public interface TauxRepository extends JpaRepository<Taux, Long> {
}
package com.mycompany.myapp.repository.search;
import com.mycompany.myapp.domain.Taux;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
/**
* Spring Data Elasticsearch repository for the Taux entity.
*/
public interface TauxSearchRepository extends ElasticsearchRepository<Taux, Long> {
}
package com.mycompany.myapp.web.rest;
import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.Taux;
import com.mycompany.myapp.repository.TauxRepository;
import com.mycompany.myapp.repository.search.TauxSearchRepository;
import com.mycompany.myapp.web.rest.errors.BadRequestAlertException;
import com.mycompany.myapp.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;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.elasticsearch.index.query.QueryBuilders.*;
/**
* REST controller for managing Taux.
*/
@RestController
@RequestMapping("/api")
public class TauxResource {
private final Logger log = LoggerFactory.getLogger(TauxResource.class);
private static final String ENTITY_NAME = "taux";
private final TauxRepository tauxRepository;
private final TauxSearchRepository tauxSearchRepository;
public TauxResource(TauxRepository tauxRepository, TauxSearchRepository tauxSearchRepository) {
this.tauxRepository = tauxRepository;
this.tauxSearchRepository = tauxSearchRepository;
}
/**
* POST /tauxes : Create a new taux.
*
* @param taux the taux to create
* @return the ResponseEntity with status 201 (Created) and with body the new taux, or with status 400 (Bad Request) if the taux has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/tauxes")
@Timed
public ResponseEntity<Taux> createTaux(@Valid @RequestBody Taux taux) throws URISyntaxException {
log.debug("REST request to save Taux : {}", taux);
if (taux.getId() != null) {
throw new BadRequestAlertException("A new taux cannot already have an ID", ENTITY_NAME, "idexists");
}
Taux result = tauxRepository.save(taux);
tauxSearchRepository.save(result);
return ResponseEntity.created(new URI("/api/tauxes/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result);
}
/**
* PUT /tauxes : Updates an existing taux.
*
* @param taux the taux to update
* @return the ResponseEntity with status 200 (OK) and with body the updated taux,
* or with status 400 (Bad Request) if the taux is not valid,
* or with status 500 (Internal Server Error) if the taux couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/tauxes")
@Timed
public ResponseEntity<Taux> updateTaux(@Valid @RequestBody Taux taux) throws URISyntaxException {
log.debug("REST request to update Taux : {}", taux);
if (taux.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
Taux result = tauxRepository.save(taux);
tauxSearchRepository.save(result);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, taux.getId().toString()))
.body(result);
}
/**
* GET /tauxes : get all the tauxes.
*
* @return the ResponseEntity with status 200 (OK) and the list of tauxes in body
*/
@GetMapping("/tauxes")
@Timed
public List<Taux> getAllTauxes() {
log.debug("REST request to get all Tauxes");
return tauxRepository.findAll();
}
/**
* GET /tauxes/:id : get the "id" taux.
*
* @param id the id of the taux to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the taux, or with status 404 (Not Found)
*/
@GetMapping("/tauxes/{id}")
@Timed
public ResponseEntity<Taux> getTaux(@PathVariable Long id) {
log.debug("REST request to get Taux : {}", id);
Optional<Taux> taux = tauxRepository.findById(id);
return ResponseUtil.wrapOrNotFound(taux);
}
/**
* DELETE /tauxes/:id : delete the "id" taux.
*
* @param id the id of the taux to delete
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("/tauxes/{id}")
@Timed
public ResponseEntity<Void> deleteTaux(@PathVariable Long id) {
log.debug("REST request to delete Taux : {}", id);
tauxRepository.deleteById(id);
tauxSearchRepository.deleteById(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
}
/**
* SEARCH /_search/tauxes?query=:query : search for the taux corresponding
* to the query.
*
* @param query the query of the taux search
* @return the result of the search
*/
@GetMapping("/_search/tauxes")
@Timed
public List<Taux> searchTauxes(@RequestParam String query) {
log.debug("REST request to search Tauxes for query {}", query);
return StreamSupport
.stream(tauxSearchRepository.search(queryStringQuery(query)).spliterator(), false)
.collect(Collectors.toList());
}
}
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="now" value="now()" dbms="h2"/>
<property name="now" value="now()" dbms="mysql"/>
<property name="autoIncrement" value="true"/>
<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql"/>
<!--
Added the entity Taux.
-->
<changeSet id="20181105135142-1" author="jhipster">
<createTable tableName="taux">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="jhi_date" type="datetime">
<constraints nullable="false" />
</column>
<column name="taux" type="bigint">
<constraints nullable="false" />
</column>
<column name="agence_id" type="bigint">
<constraints nullable="false" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
<dropDefaultValue tableName="taux" columnName="jhi_date" columnDataType="datetime"/>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove-->
</databaseChangeLog>
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<!--
Added the constraints for entity Taux.
-->
<changeSet id="20181105135142-2" author="jhipster">
<addForeignKeyConstraint baseColumnNames="agence_id"
baseTableName="taux"
constraintName="fk_taux_agence_id"
referencedColumnNames="id"
referencedTableName="agence"/>
</changeSet>
</databaseChangeLog>
......@@ -11,8 +11,10 @@
<include file="config/liquibase/changelog/20181104173557_added_entity_Scooter.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20181104173913_added_entity_Voiture.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20181104174504_added_entity_Agence.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20181105135142_added_entity_Taux.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
<include file="config/liquibase/changelog/20181104150433_added_entity_constraints_Reservation.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20181104161253_added_entity_constraints_Vehicule.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20181105135142_added_entity_constraints_Taux.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
</databaseChangeLog>
......@@ -6,6 +6,7 @@ import { MyTransportVeloModule } from './velo/velo.module';
import { MyTransportScooterModule } from './scooter/scooter.module';
import { MyTransportVoitureModule } from './voiture/voiture.module';
import { MyTransportAgenceModule } from './agence/agence.module';
import { MyTransportTauxModule } from './taux/taux.module';
/* jhipster-needle-add-entity-module-import - JHipster will add entity modules imports here */
@NgModule({
......@@ -17,6 +18,7 @@ import { MyTransportAgenceModule } from './agence/agence.module';
MyTransportScooterModule,
MyTransportVoitureModule,
MyTransportAgenceModule,
MyTransportTauxModule,
/* jhipster-needle-add-entity-module - JHipster will add entity modules here */
],
declarations: [],
......
export * from './taux.service';
export * from './taux-update.component';
export * from './taux-delete-dialog.component';
export * from './taux-detail.component';
export * from './taux.component';
export * from './taux.route';
<form name="deleteForm" (ngSubmit)="confirmDelete(taux.id)">
<div class="modal-header">
<h4 class="modal-title" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"
(click)="clear()">&times;</button>
</div>
<div class="modal-body">
<jhi-alert-error></jhi-alert-error>
<p id="jhi-delete-taux-heading" jhiTranslate="myTransportApp.taux.delete.question" translateValues="{id: '{{taux.id}}'}">Are you sure you want to delete this Taux?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="clear()">
<fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button id="jhi-confirm-delete-taux" type="submit" class="btn btn-danger">
<fa-icon [icon]="'times'"></fa-icon>&nbsp;<span jhiTranslate="entity.action.delete">Delete</span>
</button>
</div>
</form>
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { JhiEventManager } from 'ng-jhipster';
import { ITaux } from 'app/shared/model/taux.model';
import { TauxService } from './taux.service';
@Component({
selector: 'jhi-taux-delete-dialog',
templateUrl: './taux-delete-dialog.component.html'
})
export class TauxDeleteDialogComponent {
taux: ITaux;
constructor(private tauxService: TauxService, public activeModal: NgbActiveModal, private eventManager: JhiEventManager) {}
clear() {
this.activeModal.dismiss('cancel');
}
confirmDelete(id: number) {
this.tauxService.delete(id).subscribe(response => {
this.eventManager.broadcast({
name: 'tauxListModification',
content: 'Deleted an taux'
});
this.activeModal.dismiss(true);
});
}
}
@Component({
selector: 'jhi-taux-delete-popup',
template: ''
})
export class TauxDeletePopupComponent implements OnInit, OnDestroy {
private ngbModalRef: NgbModalRef;
constructor(private activatedRoute: ActivatedRoute, private router: Router, private modalService: NgbModal) {}
ngOnInit() {
this.activatedRoute.data.subscribe(({ taux }) => {
setTimeout(() => {
this.ngbModalRef = this.modalService.open(TauxDeleteDialogComponent as Component, { size: 'lg', backdrop: 'static' });
this.ngbModalRef.componentInstance.taux = taux;
this.ngbModalRef.result.then(
result => {
this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
this.ngbModalRef = null;
},
reason => {
this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
this.ngbModalRef = null;
}
);
}, 0);
});
}