Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3640f41

Browse files
modify database structure : add basket modify other tables
1 parent 1906ffd commit 3640f41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+127
-48
lines changed

‎src/main/java/com/nfs/project/dto/RegisterRequest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@AllArgsConstructor
1313
@NoArgsConstructor
1414
public class RegisterRequest {
15-
1615
private String firstname;
1716
private String lastname;
1817
@Email(message = "email field is required")

‎src/main/java/com/nfs/project/exception/NoHandlerException.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
*/
66
package com.nfs.project.exception;
77

8+
import java.sql.Date;
9+
import java.time.LocalDate;
10+
811
import org.springframework.http.HttpStatus;
912
import org.springframework.http.ResponseEntity;
1013
import org.springframework.web.bind.annotation.ControllerAdvice;
1114
import org.springframework.web.bind.annotation.ExceptionHandler;
1215
import org.springframework.web.servlet.NoHandlerFoundException;
1316

17+
import com.nfs.project.payload.ResponseData;
18+
1419
@ControllerAdvice
1520
public class NoHandlerException {
1621

@@ -20,8 +25,7 @@ public String handleNoHandlerFoundException(NoHandlerFoundException ex) {
2025
return "forward:/index.html";
2126
}
2227
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class)
23-
public ResponseEntity<String> index(org.springframework.web.bind.MethodArgumentNotValidException ex) {
24-
System.out.println("MethodArgumentNotValidException");
25-
return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
28+
public ResponseEntity<ResponseData> index(org.springframework.web.bind.MethodArgumentNotValidException ex) {
29+
return ResponseEntity.badRequest().body(ResponseData.builder().date(LocalDate.now()).message(ex.getMessage()).build());
2630
}
2731
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @author abdelouahabella
3+
* Date: Mar 17, 2023
4+
* Time: 11:14:01 PM
5+
*/
6+
package com.nfs.project.model;
7+
8+
import jakarta.persistence.Column;
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.FetchType;
11+
import jakarta.persistence.GeneratedValue;
12+
import jakarta.persistence.GenerationType;
13+
import jakarta.persistence.Id;
14+
import jakarta.persistence.JoinColumn;
15+
import jakarta.persistence.ManyToOne;
16+
import jakarta.persistence.SequenceGenerator;
17+
import jakarta.persistence.Table;
18+
import lombok.AllArgsConstructor;
19+
import lombok.Builder;
20+
import lombok.Data;
21+
import lombok.NoArgsConstructor;
22+
23+
@Data
24+
@Builder
25+
@NoArgsConstructor
26+
@AllArgsConstructor
27+
@Entity
28+
@Table(name = "order_basket")
29+
public class OrderBasket {
30+
31+
@Id
32+
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_basket_seq")
33+
@SequenceGenerator(name = "order_basket_seq", sequenceName = "ORDER_BASKET_SEQ", allocationSize = 1)
34+
private int basketid;
35+
36+
@Column(name = "productid")
37+
@ManyToOne(fetch = FetchType.LAZY)
38+
@JoinColumn(name = "productid")
39+
private Product product;
40+
41+
@Column(name = "orderid")
42+
@ManyToOne(fetch = FetchType.LAZY)
43+
@JoinColumn(name = "orderid")
44+
private customer customer;
45+
46+
47+
@Column(name = "quantity")
48+
private int quantity;
49+
50+
@Column(name = "priceperunit")
51+
private double priceperunit;
52+
53+
54+
}

‎src/main/java/com/nfs/project/model/OrdersOperation.java‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,27 @@
1818
@Entity(name = "orders_operation")
1919
@Table
2020
@NoArgsConstructor
21+
2122
public class OrdersOperation implements Serializable {
2223
@Id
23-
@SequenceGenerator(
24-
name="OrdersOPSquence",
25-
sequenceName = "OrdersOPSquence",
26-
allocationSize = 1
27-
)
28-
@GeneratedValue(
29-
strategy = GenerationType.SEQUENCE,
30-
generator = "OrdersOPSquence"
31-
)
24+
@SequenceGenerator(name="OrdersOPSquence",sequenceName = "OrdersOPSquence",allocationSize = 1)
25+
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "OrdersOPSquence")
3226
private int id;
33-
34-
@ManyToOne
35-
@JoinColumn(name="customer_id")
36-
// @Valid
37-
private customer customerid;
3827
private String Label;
3928
private String Status;
4029
private float TotalOrderPrice;
41-
private float priceperunit;
4230
private LocalDate OrderDate,ConfirmationDate,ShippingDate,ReceivingDate;
4331
private Boolean confirmed,Shipped,Received;
32+
@ManyToOne
33+
@JoinColumn(name="customer_id")
34+
private customer customerid;
35+
4436
public OrdersOperation(customer customerid, String label,
4537
float totalOrderPrice, float priceperunit, boolean confirmed) {
4638

4739
this.customerid = customerid;
4840
this.Label = label;
4941
this.TotalOrderPrice = totalOrderPrice;
50-
this.priceperunit = priceperunit;
5142
this.OrderDate = LocalDate.now();
5243
this.confirmed = confirmed;
5344
this.Shipped = false;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author abdelouahabella
3+
* Date: Mar 17, 2023
4+
* Time: 9:49:14 PM
5+
*/
6+
package com.nfs.project.payload;
7+
8+
import java.time.LocalDate;
9+
10+
import com.fasterxml.jackson.annotation.JsonInclude;
11+
12+
import lombok.AllArgsConstructor;
13+
import lombok.Builder;
14+
import lombok.Data;
15+
import lombok.NoArgsConstructor;
16+
17+
@Data
18+
@AllArgsConstructor
19+
@NoArgsConstructor
20+
@Builder
21+
@JsonInclude(JsonInclude.Include.NON_NULL)
22+
public class ResponseData {
23+
24+
private String message;
25+
26+
private int status;
27+
28+
private String path;
29+
30+
private LocalDate date;
31+
}

‎src/main/java/com/nfs/project/service/OrdersOpService.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public boolean validateOrders(List<OrdersOperation> orders) {
9393
}
9494

9595
private boolean isOrderCompleted(OrdersOperation op) {
96-
if (op.getLabel().isEmpty() || op.getPriceperunit() <= 0 ||
96+
if (op.getLabel().isEmpty() ||
9797
!customerRepository.existsById(op.getId()) || op.getTotalOrderPrice() <= 0) {
9898
return false;
9999
}
@@ -104,11 +104,10 @@ private boolean isOrderCompleted(OrdersOperation op) {
104104
@Override
105105
public void SaveOrderOperation(OrdersOperation order) {
106106
System.out.println(order.getLabel() + "\n"
107-
+ order.getPriceperunit()
108107
+ "\n" + (customerRepository.findById(order.getId()).isPresent())
109108
+ "\n" +"\n"+order.getTotalOrderPrice());
110109

111-
if(order.getLabel()!="" && order.getPriceperunit()>0
110+
if(order.getLabel()!=""
112111
&& customerRepository.findById(order.getId()).isPresent()
113112
&& order.getTotalOrderPrice()>0
114113
){

‎src/main/resources/index.sql‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ INCREMENT BY 1
5454
NOCACHE;
5555

5656
select * from product order by id desc;
57+
DROP TABLE stock_operation;
5758
CREATE TABLE stock_operation (
5859
id INTEGER NOT NULL,
5960
product_id INTEGER NOT NULL,
6061
quantity INTEGER NOT NULL,
6162
quantity_consumed INTEGER NOT NULL,
62-
entered_date DATE NOT NULL,
6363
label VARCHAR(255) NOT NULL,
64-
exited_date DATE,
6564
PRIMARY KEY (id)
6665
);
6766
ALTER TABLE stock_operation ADD CONSTRAINT fk_product_id
@@ -77,42 +76,44 @@ NOCACHE;
7776

7877

7978

80-
drop table orders_operation;
79+
drop table orders_operation CASCADE CONSTRAINTS;
8180
CREATE TABLE orders_operation (
8281
id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
83-
ProductId NUMBER NOT NULL,
8482
customerid NUMBER NOT NULL,
8583
Label VARCHAR2(255) NOT NULL,
86-
TotalOrderPrice FLOAT NOT NULL,
87-
priceperunit FLOAT NOT NULL,
88-
OrderDate DATE NOT NULL,
89-
confirmed NUMBER(1) DEFAULT 0 NOT NULL,
90-
Shipped NUMBER(1) DEFAULT 0 NOT NULL,
91-
Received NUMBER(1) DEFAULT 0 NOT NULL,
92-
quantity NUMBER NOT NULL,
93-
CONSTRAINT fk_product
94-
FOREIGN KEY (ProductId)
95-
REFERENCES product (id),
84+
TOTAL_ORDER_PRICE FLOAT NOT NULL,
85+
ORDER_DATE DATE NOT NULL,
86+
Confirmation_Date DATE,
87+
Shipping_Date DATE,
88+
Receiving_Date DATE,
9689
CONSTRAINT fk_customer
9790
FOREIGN KEY (customerid)
9891
REFERENCES customer (id),
9992
CONSTRAINT check_total_price
100-
CHECK (TotalOrderPrice > 0),
101-
CONSTRAINT check_price_per_unit
102-
CHECK (priceperunit > 0),
103-
CONSTRAINT check_quantity
104-
CHECK (quantity > 0)
93+
CHECK (TOTAL_ORDER_PRICE > 0)
10594
);
10695

107-
-- rename TotalOrderPrice to TOTAL_ORDER_PRICE
108-
alter table orders_operation rename column TotalOrderPrice to TOTAL_ORDER_PRICE;
109-
-- rename orderDate to ORDER_DATE
110-
alter table orders_operation rename column orderDate to ORDER_DATE;
111-
-- rename productId to PRODUCT_ID
112-
alter table orders_operation rename column productId to PRODUCT_ID;
96+
drop table order_basket;
97+
CREATE TABLE order_Basket (
98+
basketid NUMBER primary key,
99+
orderid NUMBER,
100+
productid INTEGER,
101+
-- price per unit to keep the price fix in case of price change
102+
priceperunit NUMBER,
103+
quantity number,
104+
CONSTRAINT fk_basket FOREIGN KEY (orderid) REFERENCES orders_operation(id),
105+
CONSTRAINT fk2_basket FOREIGN KEY (productid) REFERENCES product(id)
106+
);
107+
CREATE SEQUENCE ORDER_BASKET_SEQ START WITH 1 INCREMENT BY 1 NOCACHE;
113108

114109
CREATE SEQUENCE OrdersOPSquence
115110
START WITH 1
116111
INCREMENT BY 1
117112
NOCACHE;
118113

114+
-- clreate all the previous tables
115+
DELETE FROM orders_operation;
116+
DELETE FROM order_basket;
117+
DELETE FROM stock_operation;
118+
-- DELETE FROM product;
119+
DELETE FROM customer;
-828 Bytes
Binary file not shown.
-3.75 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /