Skip to content

Commit

Permalink
Modification de la BD pour les Ordered #32
Browse files Browse the repository at this point in the history
  • Loading branch information
madoci committed Sep 18, 2020
1 parent 1f9049f commit 5188a5e
Show file tree
Hide file tree
Showing 37 changed files with 265 additions and 304 deletions.
31 changes: 11 additions & 20 deletions .jhipster/Customer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
{
"name": "Customer",
"fields": [
{
"fieldName": "name",
"fieldType": "String",
"fieldValidateRules": ["required"]
},
{
"fieldName": "lastName",
"fieldType": "String",
"fieldValidateRules": ["required"]
},
{
"fieldName": "address",
"fieldType": "String",
"fieldValidateRules": ["required"]
"fieldValidateRules": [
"required"
]
}
],
"relationships": [
{
"relationshipType": "one-to-one",
"otherEntityName": "user",
"otherEntityRelationshipName": "customer",
"relationshipName": "user",
"otherEntityField": "id",
"ownerSide": true
},
{
"relationshipType": "one-to-many",
"otherEntityName": "ordered",
"otherEntityRelationshipName": "idCustomer",
"relationshipName": "idOrder"
},
{
"relationshipName": "user",
"otherEntityName": "user",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"useJPADerivedIdentifier": true,
"otherEntityRelationshipName": "customer"
}
],
"changelogDate": "20200916123938",
Expand Down
14 changes: 14 additions & 0 deletions .jhipster/Ordered.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
"required"
]
},
{
"fieldName": "firstName",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
},
{
"fieldName": "lastName",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
},
{
"fieldName": "delevryAddress",
"fieldType": "String",
Expand Down
10 changes: 7 additions & 3 deletions DataBase_Ebraire.jh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

entity Customer {
id Long,
name String required,
lastName String required,
address String required
}

entity Ordered {
id Long,
commandStart LocalDate required,
firstName String required,
lastName String required,
delevryAddress String required,
billingAddress String required,
status Status required
Expand Down Expand Up @@ -50,7 +50,11 @@ enum Status{
}


relationship OneToMany{
relationship OneToOne {
Customer{user} to User
}

relationship OneToMany {
Customer{idOrder} to Ordered{idCustomer}, // chaque client a sa liste de commande
Ordered{orderLines} to OrderLine{order}
}
Expand Down
69 changes: 17 additions & 52 deletions src/main/java/com/shaf/ebraire/domain/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,22 @@ public class Customer 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 = true)
private String name;

@NotNull
@Column(name = "last_name", nullable = true)
private String lastName;

@NotNull
@Column(name = "address", nullable = false)
private String address;

@OneToMany(mappedBy = "idCustomer")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<Ordered> idOrders = new HashSet<>();

@OneToOne
@MapsId
@JoinColumn(name = "id")
private User user;

@OneToMany(mappedBy = "idCustomer")
private Set<Ordered> idOrders = new HashSet<>();

// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
Expand All @@ -53,43 +46,30 @@ public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public Customer name(String name) {
this.name = name;
return this;
}

public void setName(String name) {
this.name = name;
}

public String getLastName() {
return lastName;
public String getAddress() {
return address;
}

public Customer lastName(String lastName) {
this.lastName = lastName;
public Customer address(String address) {
this.address = address;
return this;
}

public void setLastName(String lastName) {
this.lastName = lastName;
public void setAddress(String address) {
this.address = address;
}

public String getAddress() {
return address;
public User getUser() {
return user;
}

public Customer address(String address) {
this.address = address;
public Customer user(User user) {
this.user = user;
return this;
}

public void setAddress(String address) {
this.address = address;
public void setUser(User user) {
this.user = user;
}

public Set<Ordered> getIdOrders() {
Expand All @@ -116,19 +96,6 @@ public Customer removeIdOrder(Ordered ordered) {
public void setIdOrders(Set<Ordered> ordereds) {
this.idOrders = ordereds;
}

public User getUser() {
return user;
}

public Customer user(User user) {
this.user = user;
return this;
}

public void setUser(User user) {
this.user = user;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

@Override
Expand All @@ -152,8 +119,6 @@ public int hashCode() {
public String toString() {
return "Customer{" +
"id=" + getId() +
", name='" + getName() + "'" +
", lastName='" + getLastName() + "'" +
", address='" + getAddress() + "'" +
"}";
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/shaf/ebraire/domain/Ordered.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public class Ordered implements Serializable {
@Column(name = "command_start", nullable = false)
private LocalDate commandStart;

@NotNull
@Column(name = "first_name", nullable = false)
private String firstName;

@NotNull
@Column(name = "last_name", nullable = false)
private String lastName;

@NotNull
@Column(name = "delevry_address", nullable = false)
private String delevryAddress;
Expand Down Expand Up @@ -76,6 +84,32 @@ public void setCommandStart(LocalDate commandStart) {
this.commandStart = commandStart;
}

public String getFirstName() {
return firstName;
}

public Ordered firstName(String firstName) {
this.firstName = firstName;
return this;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public Ordered lastName(String lastName) {
this.lastName = lastName;
return this;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getDelevryAddress() {
return delevryAddress;
}
Expand Down Expand Up @@ -176,6 +210,8 @@ public String toString() {
return "Ordered{" +
"id=" + getId() +
", commandStart='" + getCommandStart() + "'" +
", firstName='" + getFirstName() + "'" +
", lastName='" + getLastName() + "'" +
", delevryAddress='" + getDelevryAddress() + "'" +
", billingAddress='" + getBillingAddress() + "'" +
", status='" + getStatus() + "'" +
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/shaf/ebraire/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ public User registerUser(UserDTO userDTO, String password, String address) {
Customer customer = new Customer();
customer.setUser(newUser);
customer.setAddress(address);
customer.setName("");
customer.setLastName("");
customerRepository.save(customer);
log.debug("Created Information for Customer: {}", customer);

Expand Down
9 changes: 0 additions & 9 deletions src/main/java/com/shaf/ebraire/web/rest/CustomerResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -59,11 +58,6 @@ public ResponseEntity<Customer> createCustomer(@Valid @RequestBody Customer cust
if (customer.getId() != null) {
throw new BadRequestAlertException("A new customer cannot already have an ID", ENTITY_NAME, "idexists");
}
if (Objects.isNull(customer.getUser())) {
throw new BadRequestAlertException("Invalid association value provided", ENTITY_NAME, "null");
}
Long userId = customer.getUser().getId();
userRepository.findById(userId).ifPresent(customer::user);
Customer result = customerRepository.save(customer);
return ResponseEntity.created(new URI("/api/customers/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString()))
Expand Down Expand Up @@ -97,7 +91,6 @@ public ResponseEntity<Customer> updateCustomer(@Valid @RequestBody Customer cust
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of customers in body.
*/
@GetMapping("/customers")
@Transactional(readOnly = true)
public List<Customer> getAllCustomers() {
log.debug("REST request to get all Customers");
return customerRepository.findAll();
Expand All @@ -110,7 +103,6 @@ public List<Customer> getAllCustomers() {
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the customer, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/customers/{id}")
@Transactional(readOnly = true)
public ResponseEntity<Customer> getCustomer(@PathVariable Long id) {
log.debug("REST request to get Customer : {}", id);
Optional<Customer> customer = customerRepository.findById(id);
Expand Down Expand Up @@ -147,5 +139,4 @@ public ResponseEntity<Customer> getCustomer(@PathVariable String login) {
Optional<Customer> customer = customerRepository.findById(user.get().getId());
return ResponseUtil.wrapOrNotFound(customer);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
<column name="id" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="true" />
</column>
<column name="last_name" type="varchar(255)">
<constraints nullable="true" />
</column>
<column name="address" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="user_id" type="bigint">
<constraints unique="true" nullable="true" uniqueConstraintName="ux_customer_user_id" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here -->
</createTable>
</changeSet>
Expand All @@ -47,8 +44,6 @@
separator=";"
tableName="customer">
<column name="id" type="numeric"/>
<column name="name" type="string"/>
<column name="last_name" type="string"/>
<column name="address" type="string"/>
<!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
</loadData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-->
<changeSet id="20200916123938-2" author="jhipster">

<addForeignKeyConstraint baseColumnNames="id"
<addForeignKeyConstraint baseColumnNames="user_id"
baseTableName="customer"
constraintName="fk_customer_user_id"
referencedColumnNames="id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<column name="command_start" type="date">
<constraints nullable="false" />
</column>
<column name="first_name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="last_name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="delevry_address" type="varchar(255)">
<constraints nullable="false" />
</column>
Expand Down Expand Up @@ -54,6 +60,8 @@
tableName="ordered">
<column name="id" type="numeric"/>
<column name="command_start" type="date"/>
<column name="first_name" type="string"/>
<column name="last_name" type="string"/>
<column name="delevry_address" type="string"/>
<column name="billing_address" type="string"/>
<column name="status" type="string"/>
Expand Down
Loading

0 comments on commit 5188a5e

Please sign in to comment.