Skip to content

Commit 7a84309

Browse files
committed
Merge branch 'feature/basicApp' into main
2 parents fcf8710 + b1c6b58 commit 7a84309

37 files changed

+1337
-255
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}

backend/webandtech/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<dependency>
8484
<groupId>org.webjars</groupId>
8585
<artifactId>bootstrap</artifactId>
86-
<version>3.3.7</version>
86+
<version>5.1.3</version>
8787
</dependency>
8888
<dependency>
8989
<groupId>org.webjars</groupId>
@@ -109,9 +109,9 @@
109109
<version>2.8.0</version>
110110
</dependency>
111111
<dependency>
112-
<groupId>com.github.librepdf</groupId>
113-
<artifactId>openpdf</artifactId>
114-
<version>1.3.27</version>
112+
<groupId>com.github.librepdf</groupId>
113+
<artifactId>openpdf</artifactId>
114+
<version>1.3.8</version>
115115
</dependency>
116116
</dependencies>
117117
</project>

backend/webandtech/src/main/java/webapp8/webandtech/controller/AdminController.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@
33
import java.io.IOException;
44
import java.util.ArrayList;
55
import java.util.List;
6-
import java.util.regex.Pattern;
76

87
import javax.servlet.http.HttpServletRequest;
9-
import javax.servlet.http.HttpServletResponse;
10-
import javax.servlet.http.HttpSession;
118

129
import org.springframework.beans.factory.annotation.Autowired;
1310
import org.springframework.security.web.csrf.CsrfToken;
1411
import org.springframework.stereotype.Controller;
1512
import org.springframework.ui.Model;
1613
import org.springframework.web.bind.annotation.CrossOrigin;
1714
import org.springframework.web.bind.annotation.GetMapping;
18-
import org.springframework.web.bind.annotation.PathVariable;
19-
import org.springframework.web.bind.annotation.RequestParam;
2015

2116
import webapp8.webandtech.model.Order;
2217
import webapp8.webandtech.model.OrderModel;
2318
import webapp8.webandtech.model.Product;
24-
import webapp8.webandtech.model.Statistics;
25-
import webapp8.webandtech.model.User;
2619
import webapp8.webandtech.service.AdminService;
2720
import webapp8.webandtech.service.OrderService;
2821
import webapp8.webandtech.service.ProductService;
@@ -84,6 +77,7 @@ private String getUserList(Model model,HttpServletRequest request) throws IOExce
8477
}else{
8578
model.addAttribute("login", false);
8679
}
80+
8781
model.addAttribute("userList", userService.getAllUsersPage());
8882
model.addAttribute("admin", request.isUserInRole("ADMIN"));
8983
model.addAttribute("userr", request.isUserInRole("USER"));

backend/webandtech/src/main/java/webapp8/webandtech/controller/AjaxController.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
package webapp8.webandtech.controller;
22

3-
import java.io.IOException;
4-
import java.sql.SQLException;
5-
import java.util.List;
63

7-
import javax.servlet.http.HttpServletResponse;
4+
5+
86

97
import org.springframework.beans.factory.annotation.Autowired;
10-
import org.springframework.core.io.InputStreamResource;
11-
import org.springframework.core.io.Resource;
8+
129
import org.springframework.data.domain.Page;
1310
import org.springframework.data.domain.Pageable;
14-
import org.springframework.http.HttpHeaders;
15-
import org.springframework.http.ResponseEntity;
16-
import org.springframework.stereotype.Controller;
11+
1712
import org.springframework.web.bind.annotation.CrossOrigin;
1813
import org.springframework.web.bind.annotation.GetMapping;
19-
import org.springframework.web.bind.annotation.PathVariable;
20-
import org.springframework.web.bind.annotation.PostMapping;
2114
import org.springframework.web.bind.annotation.RequestParam;
2215
import org.springframework.web.bind.annotation.RestController;
23-
import org.springframework.web.multipart.MultipartFile;
2416

2517
import webapp8.webandtech.model.Order;
2618
import webapp8.webandtech.model.Product;
27-
import webapp8.webandtech.model.Statistics;
2819
import webapp8.webandtech.model.User;
29-
import webapp8.webandtech.service.AdminService;
3020
import webapp8.webandtech.service.ProductService;
3121
import webapp8.webandtech.service.UserService;
3222
import webapp8.webandtech.service.OrderService;
@@ -37,8 +27,6 @@ public class AjaxController {
3727
@Autowired
3828
private ProductService productService;
3929
@Autowired
40-
private AdminService adminService;
41-
@Autowired
4230
private OrderService orderService;
4331
@Autowired
4432
private UserService userService;

backend/webandtech/src/main/java/webapp8/webandtech/controller/NavigationController.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.IOException;
44
import java.util.ArrayList;
55
import java.util.List;
6-
import java.util.regex.Pattern;
6+
77

88
import javax.servlet.http.HttpServletRequest;
99
import javax.servlet.http.HttpServletResponse;
@@ -115,7 +115,7 @@ private String getCheckOut(Model model,HttpServletRequest request) throws IOExce
115115
}
116116
System.out.println(carShop.getCarShop());
117117
model.addAttribute("priceCar", totalPrice);
118-
model.addAttribute("shopCar", carShop.getCarShop());
118+
model.addAttribute("shopCar", productos);
119119
model.addAttribute("admin", request.isUserInRole("ADMIN"));
120120
model.addAttribute("userr", request.isUserInRole("USER"));
121121

@@ -193,13 +193,10 @@ private String getPhones(Model model, HttpServletRequest request, @RequestParam(
193193
model.addAttribute("admin", request.isUserInRole("ADMIN"));
194194
model.addAttribute("userr", request.isUserInRole("USER"));
195195
model.addAttribute("typeProduct", typeProduct);
196-
if(typeProduct != null){
197-
model.addAttribute("products", productService.getProductType(typeProduct));
198-
199-
System.out.println(typeProduct);
200-
} else{
201-
model.addAttribute("products", productService.getPhones());
202-
}
196+
197+
model.addAttribute("products", productService.getPhones());
198+
model.addAttribute("type", "undefined");
199+
model.addAttribute("category", "telefono");
203200

204201
return "productsByFeatures";
205202
}
@@ -309,4 +306,51 @@ private String getUserSecurity(Model model,HttpServletRequest request) throws IO
309306
return "seguridad";
310307
}
311308

309+
@GetMapping("/products/modifyProduct/{idproduct}")
310+
private String getModifyProduct(Model model,HttpServletRequest request, @PathVariable int idproduct, HttpSession sesion, HttpServletResponse response) throws IOException {
311+
CsrfToken token = (CsrfToken) request.getAttribute("_csrf");
312+
model.addAttribute("token", token.getToken());
313+
if(request.getUserPrincipal() != null){
314+
model.addAttribute("user", request.getUserPrincipal().getName());
315+
model.addAttribute("login", (request.getUserPrincipal() != null));
316+
}else{
317+
model.addAttribute("login", false);
318+
}
319+
320+
Product product = productService.getProduct(idproduct);
321+
322+
if (product.getProductcategory().equals("Componente")){
323+
model.addAttribute("componente", "componente");
324+
} else if (product.getProductcategory().equals("Periferico")){
325+
model.addAttribute("periferico", "Periferico");
326+
} else {
327+
model.addAttribute("telefono", "telefono");
328+
}
329+
330+
if (product.getProductType().equals("Placa base")){
331+
model.addAttribute("placa", "placa");
332+
} else if (product.getProductType().equals("Disco duro")){
333+
model.addAttribute("disco", "disco");
334+
} else if (product.getProductType().equals("Procesador")){
335+
model.addAttribute("prcesador", "prcesador");
336+
} else if (product.getProductType().equals("Tarjeta grafica")){
337+
model.addAttribute("tarjeta", "tarjeta");
338+
} else if (product.getProductType().equals("Teclado")){
339+
model.addAttribute("teclado", "teclado");
340+
} else if (product.getProductType().equals("Raton")){
341+
model.addAttribute("raton", "raton");
342+
} else if (product.getProductType().equals("Monitor")){
343+
model.addAttribute("monitor", "monitor");
344+
} else if (product.getProductType().equals("Auriculares")){
345+
model.addAttribute("auriculares", "auriculares");
346+
} else {
347+
model.addAttribute("telefono", "telefono");
348+
}
349+
model.addAttribute("product", product);
350+
model.addAttribute("admin", request.isUserInRole("ADMIN"));
351+
model.addAttribute("userr", request.isUserInRole("USER"));
352+
353+
return "modifyProduct";
354+
}
355+
312356
}

backend/webandtech/src/main/java/webapp8/webandtech/controller/ProductController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.springframework.web.bind.annotation.PathVariable;
2020
import org.springframework.web.bind.annotation.PostMapping;
2121
import org.springframework.web.bind.annotation.RequestParam;
22-
import org.springframework.web.bind.annotation.RestController;
2322
import org.springframework.web.multipart.MultipartFile;
2423

2524
import webapp8.webandtech.model.Product;
@@ -39,6 +38,14 @@ private void productUpload(Product product, HttpServletResponse response, @Reque
3938
response.sendRedirect("/index");
4039
}
4140

41+
@PostMapping("/admin/productModify")
42+
private void productModify(Product product, HttpServletResponse response, @RequestParam(required = false) MultipartFile image11, @RequestParam(required = false) MultipartFile image22, @RequestParam(required = false) MultipartFile image33) throws IOException {
43+
System.out.println(product);
44+
productService.modifyDataProduct(product, image11, image22, image33);
45+
response.sendRedirect("/index");
46+
}
47+
48+
4249
@GetMapping("/componentPage")
4350
private Page<Product> getComponentsPage(Pageable page){
4451
return productService.getComponentsPage(page);
@@ -96,4 +103,13 @@ private ResponseEntity<Object> getProductImg3( @PathVariable int idproduct) thro
96103
.contentLength(product.getImage3().length())
97104
.body(file);
98105
}
106+
107+
108+
@PostMapping("/admin/deleteProduct")
109+
public void deleteProduct (HttpServletResponse response, @RequestParam int idproduct) throws IOException {
110+
productService.deleteProductById(idproduct);
111+
response.sendRedirect("/index");
112+
}
113+
114+
99115
}

backend/webandtech/src/main/java/webapp8/webandtech/controller/StoreController.java

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package webapp8.webandtech.controller;
22

3+
4+
35
import java.io.IOException;
6+
import java.text.DateFormat;
7+
import java.text.SimpleDateFormat;
8+
import java.time.LocalDateTime;
9+
import java.time.format.DateTimeFormatter;
10+
import java.util.Date;
411
import java.util.List;
512

613
import javax.servlet.http.HttpServletRequest;
714
import javax.servlet.http.HttpServletResponse;
815

9-
1016
import org.springframework.beans.factory.annotation.Autowired;
17+
1118
import org.springframework.stereotype.Controller;
1219
import org.springframework.web.bind.annotation.CrossOrigin;
20+
import org.springframework.web.bind.annotation.GetMapping;
1321
import org.springframework.web.bind.annotation.PostMapping;
1422
import org.springframework.web.bind.annotation.RequestParam;
1523

1624
import webapp8.webandtech.model.CarShop;
25+
import webapp8.webandtech.model.Order;
1726
import webapp8.webandtech.model.Product;
1827
import webapp8.webandtech.model.Rating;
1928
import webapp8.webandtech.model.User;
20-
import webapp8.webandtech.repository.UserRepository;
29+
import webapp8.webandtech.service.OrderService;
30+
import webapp8.webandtech.service.PDFGeneratorService;
2131
import webapp8.webandtech.service.ProductService;
2232
import webapp8.webandtech.service.RatingService;
2333
import webapp8.webandtech.service.UserService;
@@ -30,12 +40,20 @@ public class StoreController {
3040
@Autowired
3141
private ProductService productService;
3242
@Autowired
43+
private OrderService orderService;
44+
@Autowired
3345
private UserService userService;
3446
@Autowired
3547
private CarShop carShop;
3648
@Autowired
3749
private RatingService ratingService;
3850

51+
private final PDFGeneratorService pdfGeneratorService;
52+
53+
public StoreController(PDFGeneratorService pdfGeneratorService) {
54+
this.pdfGeneratorService = pdfGeneratorService;
55+
}
56+
3957
@PostMapping("/carShop")
4058
private void setCarShop(HttpServletRequest request, HttpServletResponse response, @RequestParam int idproduct) throws IOException {
4159
Product product = productService.getProduct(idproduct);
@@ -62,11 +80,61 @@ public void createNewRating(Rating rating, HttpServletResponse response, HttpSer
6280
ratingService.save(rating);
6381
response.sendRedirect("/products/"+idproduct);
6482
}
65-
@PostMapping("/users/newOrders")
66-
public void createNewOrders(List<Product> products, HttpServletResponse response, HttpServletRequest request, @RequestParam String user) throws IOException {
67-
User userData = userService.getUser(user);
68-
products.size();
83+
@GetMapping("/users/newOrders")
84+
public void createNewOrders(HttpServletResponse response, HttpServletRequest request) throws IOException {
85+
User user = userService.getUser(request.getUserPrincipal().getName());
86+
String idsProducts = "";
87+
List<Product> carts = carShop.getCarShop();
88+
float price = 0;
89+
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
90+
dtf.format(LocalDateTime.now());
91+
String date = dtf.format(LocalDateTime.now());
92+
for (Product cart : carts) {
93+
String id = Integer.toString(cart.getIdproduct());
94+
idsProducts = idsProducts+id+"/";
95+
price = price + cart.getPrice();
96+
}
97+
Order order = new Order();
98+
order.setPrice(price);
99+
order.setIduser(user);
100+
order.setIdproducts(idsProducts);
101+
order.setOrderdate(date);
102+
orderService.saveOrder(order);
103+
carShop.getCarShop().clear();
104+
//new pdf
105+
response.sendRedirect("/index");
106+
107+
}
108+
@GetMapping("/users/bill")
109+
public void createNewBill(HttpServletResponse response, HttpServletRequest request) throws IOException {
110+
User user = userService.getUser(request.getUserPrincipal().getName());
111+
String idsProducts = "";
112+
List<Product> carts = carShop.getCarShop();
113+
float price = 0;
114+
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
115+
dtf.format(LocalDateTime.now());
116+
String date = dtf.format(LocalDateTime.now());
117+
for (Product cart : carts) {
118+
String id = Integer.toString(cart.getIdproduct());
119+
idsProducts = idsProducts+id+"/";
120+
price = price + cart.getPrice();
121+
}
122+
Order order = new Order();
123+
order.setPrice(price);
124+
order.setIduser(user);
125+
order.setIdproducts(idsProducts);
126+
order.setOrderdate(date);
127+
//new pdf
128+
response.setContentType("application/pdf");
129+
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
130+
String currentDateTime = dateFormatter.format(new Date());
69131

70-
response.sendRedirect("/index");
132+
String headerKey = "Content-Disposition";
133+
String headerValue = "attachment; filename=pdf_" + currentDateTime + ".pdf";
134+
response.setHeader(headerKey, headerValue);
135+
136+
this.pdfGeneratorService.export(response, order, carts, user);
137+
138+
71139
}
72140
}

backend/webandtech/src/main/java/webapp8/webandtech/model/CarShop.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ public class CarShop {
1414
public List<Product> getCarShop() {
1515
return carShop;
1616
}
17+
18+
public void setCarShop(List<Product> carShop) {
19+
this.carShop = carShop;
20+
}
1721

1822
}

backend/webandtech/src/main/java/webapp8/webandtech/model/User.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
@Table(name = "users")
1717
public class User {
1818

19+
public interface Basic{}
20+
public interface Detailed extends User.Basic{}
21+
1922
@Id
2023
@GeneratedValue(strategy = GenerationType.IDENTITY)
2124
private int iduser;

backend/webandtech/src/main/java/webapp8/webandtech/repository/BrandRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import webapp8.webandtech.model.Brand;
99

1010

11-
1211
public interface BrandRepository extends JpaRepository<Brand, Integer>{
1312

13+
//public Brand findByIdproduct(Product idproduct);
1414
public Optional<Brand> findBybrandname(String brandname);
1515
public Optional<Brand> findByidbrand(String brandname);
1616
public List<Brand> findAll();
1717
boolean existsIdbrandsByBrandname(String brandname);
18+
//public Long deleteByIdproduct (Product idproduct);
19+
}
1820

19-
}

0 commit comments

Comments
 (0)