Skip to content

Commit 8fa5a9f

Browse files
author
JEstebanC
committed
Finish the last change in datebase with the additional relation
1 parent 7be400d commit 8fa5a9f

21 files changed

+105
-336
lines changed

src/main/java/JEstebanC/FastFoodApp/controller/BillController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.web.bind.annotation.RequestParam;
2020
import org.springframework.web.bind.annotation.RestController;
2121

22+
import JEstebanC.FastFoodApp.enumeration.StatusBill;
2223
import JEstebanC.FastFoodApp.model.Bill;
2324
import JEstebanC.FastFoodApp.model.Response;
2425
import JEstebanC.FastFoodApp.service.BillServiceImp;
@@ -47,10 +48,10 @@ public ResponseEntity<Response> saveBill(@RequestBody @Valid Bill bill) {
4748
// READ
4849
@GetMapping(value = "/list")
4950
public ResponseEntity<Response> getBill(@RequestParam(name = "startDate") String startDate,
50-
@RequestParam(name = "endDate") String endDate) {
51+
@RequestParam(name = "endDate") String endDate, @RequestParam(name = "statusBill") StatusBill statusBill) {
5152

5253
return ResponseEntity.ok(
53-
Response.builder().timeStamp(Instant.now()).data(Map.of("bill", serviceImp.list(startDate, endDate)))
54+
Response.builder().timeStamp(Instant.now()).data(Map.of("bill", serviceImp.list(startDate, endDate,statusBill)))
5455
.message("List bills").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
5556
}
5657

src/main/java/JEstebanC/FastFoodApp/controller/CategoryAdditionalController.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/main/java/JEstebanC/FastFoodApp/controller/OrdersController.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package JEstebanC.FastFoodApp.controller;
22

3-
43
import java.time.Instant;
54
import java.util.Map;
65

@@ -20,7 +19,7 @@
2019
import org.springframework.web.bind.annotation.RequestMapping;
2120
import org.springframework.web.bind.annotation.RestController;
2221

23-
22+
import JEstebanC.FastFoodApp.model.Additional;
2423
import JEstebanC.FastFoodApp.model.Orders;
2524
import JEstebanC.FastFoodApp.model.Response;
2625
import JEstebanC.FastFoodApp.service.OrdersServiceImp;
@@ -47,6 +46,18 @@ public ResponseEntity<Response> saveOrder(@RequestBody @Valid Orders order) {
4746
.message("Create order").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
4847
}
4948

49+
// CREATE ADDITIONAL
50+
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EMPLOYEE')")
51+
@PostMapping(value = "/additional/{idOrder}")
52+
public ResponseEntity<Response> saveAdditional(@PathVariable("idOrder") Long idOrder,
53+
@RequestBody @Valid Additional additional) {
54+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
55+
.data(Map.of("order", serviceImp.addAdditionalToOrder(idOrder, additional)))
56+
.message("Added additional to product with id: " + idOrder).status(HttpStatus.OK)
57+
.statusCode(HttpStatus.OK.value()).build());
58+
59+
}
60+
5061
// READ
5162
@PreAuthorize("hasRole('ROLE_ADMIN') OR hasRole('ROLE_EMPLOYEE')")
5263
@GetMapping(value = "/list")
@@ -62,7 +73,7 @@ public ResponseEntity<Response> updateOrder(@PathVariable("id") Long id, @Reques
6273
HttpServletRequest request) {
6374
if (serviceImp.exist(id)) {
6475
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
65-
.data(Map.of("order", serviceImp.update(id,order))).message("Update order with id:" + id)
76+
.data(Map.of("order", serviceImp.update(id, order))).message("Update order with id:" + id)
6677
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
6778
}
6879
return ResponseEntity

src/main/java/JEstebanC/FastFoodApp/controller/ProductController.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.springframework.web.bind.annotation.RequestMapping;
1919
import org.springframework.web.bind.annotation.RestController;
2020

21-
import JEstebanC.FastFoodApp.model.Additional;
2221
import JEstebanC.FastFoodApp.model.Product;
2322
import JEstebanC.FastFoodApp.model.Response;
2423
import JEstebanC.FastFoodApp.service.ProductServiceImp;
@@ -51,22 +50,12 @@ public ResponseEntity<Response> saveProduct(@RequestBody @Valid Product product)
5150
}
5251
}
5352

54-
// CREATE ADDITIONAL
55-
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EMPLOYEE')")
56-
@PostMapping(value = "/additional/{idProduct}")
57-
public ResponseEntity<Response> saveAdditional(@PathVariable("idProduct") Long idProduct,
58-
@RequestBody @Valid Additional additional) {
59-
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
60-
.data(Map.of("product", serviceImp.addAdditionalToProduct(idProduct, additional)))
61-
.message("Added additional to product with id: " + idProduct).status(HttpStatus.OK)
62-
.statusCode(HttpStatus.OK.value()).build());
63-
64-
}
6553
// READ
6654
@GetMapping(value = "/list/{page}")
6755
public ResponseEntity<Response> getProduct(@PathVariable(name = "page") Long page) {
68-
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("products", serviceImp.list(page)))
69-
.message("List products").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
56+
return ResponseEntity
57+
.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("products", serviceImp.list(page)))
58+
.message("List products").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
7059
}
7160

7261
// UPDATE
@@ -75,7 +64,7 @@ public ResponseEntity<Response> getProduct(@PathVariable(name = "page") Long pag
7564
public ResponseEntity<Response> updateProduct(@PathVariable("id") Long id, @RequestBody @Valid Product product) {
7665
if (serviceImp.exist(id)) {
7766
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
78-
.data(Map.of("product", serviceImp.update(id,product))).message("Update product with id:" + id)
67+
.data(Map.of("product", serviceImp.update(id, product))).message("Update product with id:" + id)
7968
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
8069
} else {
8170
return ResponseEntity.ok(

src/main/java/JEstebanC/FastFoodApp/dto/BillOrdersDTO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import JEstebanC.FastFoodApp.enumeration.StatusBill;
99
import JEstebanC.FastFoodApp.model.PayMode;
10+
import JEstebanC.FastFoodApp.model.Additional;
1011
import JEstebanC.FastFoodApp.model.Product;
1112
import lombok.Data;
1213

@@ -24,6 +25,9 @@ public class BillOrdersDTO {
2425

2526
// Product
2627
private Collection<Product> product;
28+
29+
// Additional
30+
private Collection<Additional> Additional;
2731

2832
// Bill
2933
private Long idBill;

src/main/java/JEstebanC/FastFoodApp/model/Additional.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ public class Additional {
3030
@NotNull(message = "name cannot be empty or null")
3131
@Column(length = 30)
3232
private String name;
33+
34+
@NotNull(message = "name cannot be empty or null")
35+
private int price;
3336

3437
@ManyToOne
35-
@NotNull(message = "idCategoryAdditional cannot be empty or null")
36-
@JoinColumn(name = "idCategoryAdditional")
37-
private CategoryAdditional CategoryAdditional;
38+
@NotNull(message = "idCategory cannot be empty or null")
39+
@JoinColumn(name = "idCategory")
40+
private Category Category;
3841

3942
private Status status;
4043

src/main/java/JEstebanC/FastFoodApp/model/CategoryAdditional.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package JEstebanC.FastFoodApp.model;
22

3+
import java.util.ArrayList;
4+
import java.util.Collection;
5+
36
import javax.persistence.Entity;
47
import javax.persistence.GeneratedValue;
58
import javax.persistence.GenerationType;
69
import javax.persistence.Id;
710
import javax.persistence.JoinColumn;
11+
import javax.persistence.JoinTable;
12+
import javax.persistence.ManyToMany;
813
import javax.persistence.ManyToOne;
914
import javax.validation.constraints.NotNull;
1015

@@ -23,25 +28,31 @@
2328
@AllArgsConstructor
2429
public class Orders {
2530

26-
@Id
27-
@GeneratedValue(strategy = GenerationType.AUTO)
28-
private Long idOrder;
29-
30-
@ManyToOne
31-
@NotNull(message = "IdBill cannot be empty or null")
32-
@JoinColumn(name = "IdBill")
33-
private Bill Bill;
34-
35-
@ManyToOne
36-
@NotNull(message = "IdProduct cannot be empty or null")
37-
@JoinColumn(name = "IdProduct")
38-
private Product Product;
39-
40-
@NotNull(message = "amount cannot be empty or null")
41-
private int amount;
42-
private int noTable;
43-
@NotNull(message = "total cannot be empty or null")
44-
private int total;
45-
private Status status;
31+
@Id
32+
@GeneratedValue(strategy = GenerationType.AUTO)
33+
private Long idOrder;
34+
35+
@ManyToOne
36+
@NotNull(message = "idBill cannot be empty or null")
37+
@JoinColumn(name = "idBill")
38+
private Bill Bill;
39+
40+
@ManyToOne
41+
@NotNull(message = "idProduct cannot be empty or null")
42+
@JoinColumn(name = "idProduct")
43+
private Product Product;
44+
45+
@ManyToMany
46+
@JoinColumn(name = "idAdditional")
47+
@JoinTable(joinColumns = @JoinColumn(name = "idOrder"),
48+
inverseJoinColumns = @JoinColumn(name = "idAdditional"))
49+
private Collection<Additional> additional = new ArrayList<>();
50+
51+
@NotNull(message = "amount cannot be empty or null")
52+
private int amount;
53+
private int noTable;
54+
@NotNull(message = "total cannot be empty or null")
55+
private int total;
56+
private Status status;
4657

4758
}

src/main/java/JEstebanC/FastFoodApp/model/Product.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package JEstebanC.FastFoodApp.model;
22

3-
import java.util.ArrayList;
4-
import java.util.Collection;
5-
63
import javax.persistence.Column;
74
import javax.persistence.Entity;
85
import javax.persistence.GeneratedValue;
96
import javax.persistence.GenerationType;
107
import javax.persistence.Id;
118
import javax.persistence.JoinColumn;
12-
import javax.persistence.ManyToMany;
139
import javax.persistence.ManyToOne;
1410
import javax.validation.constraints.NotNull;
1511

@@ -48,7 +44,5 @@ public class Product {
4844
@JoinColumn(name = "idCategory")
4945
private Category Category;
5046

51-
@ManyToMany
52-
private Collection<Additional> additional = new ArrayList<>();
5347
private Status status;
5448
}

src/main/java/JEstebanC/FastFoodApp/repository/IBillRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.data.jpa.repository.Query;
1212
import org.springframework.stereotype.Repository;
1313

14+
import JEstebanC.FastFoodApp.enumeration.StatusBill;
1415
import JEstebanC.FastFoodApp.model.Bill;
1516

1617
/**
@@ -25,7 +26,7 @@ public interface IBillRepository extends JpaRepository<Bill, Long> {
2526
@Query(value = "SELECT * FROM bill where id_user = ?", nativeQuery = true)
2627
Bill findOneByIdUser(Long idUser);
2728

28-
Collection<Bill> findByDateBetween(Date startDate,Date endDate);
29+
Collection<Bill> findByDateBetweenAndStatusBill(Date startDate,Date endDate,StatusBill statusBill);
2930

3031
Bill findByIdBill(Long idBill);
3132

0 commit comments

Comments
 (0)