Changeset d4b888e
- Timestamp:
- 01/06/23 15:26:00 (23 months ago)
- Branches:
- main
- Children:
- 9dcbf44
- Parents:
- f484b14
- Location:
- src/main
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/config/WebSecurityConfig.java
rf484b14 rd4b888e 29 29 .authorizeRequests() 30 30 .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/access_denied").permitAll() 31 .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder","/addCarSampleForUser" ).hasRole("CLIENT")31 .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder","/addCarSampleForUser","/repairs/addReview/*").hasRole("CLIENT") 32 32 .antMatchers("/viewUsers","/approve/*").hasRole("ADMIN") 33 33 .anyRequest() -
src/main/java/com/example/autopartz/controller/PartController.java
rf484b14 rd4b888e 103 103 public void chooseRepairShop(@RequestParam Integer rs,HttpSession session, HttpServletResponse response){ 104 104 Order o = (Order) session.getAttribute("order"); 105 CarSample cs = (CarSample)session.getAttribute("car");105 CarSample cs = carSampleRepository.findById((Integer)session.getAttribute("carVin")).get(); 106 106 ServiceBook sb = serviceBookRepository.findByCarSample(cs); 107 107 RepairShop repairShop = repairShopService.getById(rs); 108 108 repairRepository.save(new Repair(o,repairShop,sb)); 109 // o.setOrder_status("finished"); 110 // orderService.save(o); 109 111 session.removeAttribute("order"); 110 112 try { … … 123 125 Deliveryman dm = deliverymanList.get(deliverer); 124 126 deliveryRepository.save(new Delivery("in progress",address,dm,o)); 127 // o.setOrder_status("finished"); 128 // orderService.save(o); 125 129 session.removeAttribute("order"); 126 130 try { -
src/main/java/com/example/autopartz/controller/UserController.java
rf484b14 rd4b888e 1 1 package com.example.autopartz.controller; 2 2 3 import com.example.autopartz.model.CarSample; 4 import com.example.autopartz.model.Client; 5 import com.example.autopartz.model.ServiceBook; 3 import com.example.autopartz.model.*; 4 import com.example.autopartz.model.views.RepairsForUser; 6 5 import com.example.autopartz.repository.*; 7 6 import com.example.autopartz.service.CarService; 7 import com.example.autopartz.service.RepairService; 8 8 import com.example.autopartz.service.UserService; 9 9 import org.springframework.stereotype.Controller; 10 10 import org.springframework.ui.Model; 11 import org.springframework.web.bind.annotation.GetMapping; 12 import org.springframework.web.bind.annotation.PostMapping; 13 import org.springframework.web.bind.annotation.RequestMapping; 14 import org.springframework.web.bind.annotation.RequestParam; 11 import org.springframework.web.bind.annotation.*; 15 12 16 13 import javax.servlet.http.HttpServletRequest; 17 14 import javax.servlet.http.HttpServletResponse; 18 15 import java.io.IOException; 16 import java.util.ArrayList; 17 import java.util.List; 19 18 20 19 @Controller … … 28 27 private final CarSampleRepository carSampleRepository; 29 28 private final ServiceBookRepository serviceBookRepository; 30 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, CarSampleRepository carSampleRepository, ServiceBookRepository serviceBookRepository) { 29 private final RepairService repairService; 30 private final ReviewRepository reviewRepository; 31 private final RepairRepository repairRepository; 32 private final OrderRepository orderRepository; 33 34 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, CarSampleRepository carSampleRepository, ServiceBookRepository serviceBookRepository, RepairService repairService, ReviewRepository reviewRepository, 35 RepairRepository repairRepository, 36 OrderRepository orderRepository) { 31 37 this.ordersForUserRepository = ordersForUserRepository; 32 38 this.repairsForUserRepository = repairsForUserRepository; … … 36 42 this.carSampleRepository = carSampleRepository; 37 43 this.serviceBookRepository = serviceBookRepository; 44 this.repairService = repairService; 45 this.reviewRepository = reviewRepository; 46 this.repairRepository = repairRepository; 47 this.orderRepository = orderRepository; 38 48 } 39 49 @GetMapping("orders") … … 48 58 Integer id = userService.findByUsername(request.getRemoteUser()).getId(); 49 59 model.addAttribute("userRepairs",repairsForUserRepository.findAllByUserid(id)); 60 List<Boolean> hasReview = new ArrayList<>(100); 61 for (int i = 0; i < orderRepository.findAll().size(); i++) { 62 hasReview.add(false); 63 } 64 for(RepairsForUser rfu: repairsForUserRepository.findAll()){ 65 if(reviewRepository.findByRepair(repairService.findById(rfu.getRepairid()))==null){ 66 hasReview.set(rfu.getRepairid(),false); 67 } 68 else { 69 hasReview.set(rfu.getRepairid(),true); 70 } 71 } 72 model.addAttribute("hasReview", hasReview); 50 73 model.addAttribute("bodyContent","repairsForUser"); 51 74 return "master-template"; … … 78 101 } 79 102 } 103 @GetMapping("/repairs/addReview/{id}") 104 public String addReviewFor(@PathVariable Integer id, Model model){ 105 model.addAttribute("bodyContent","addReviewPage"); 106 model.addAttribute("repair", repairService.findById(id)); 107 return "master-template"; 108 } 109 @PostMapping("/repairs/addReview/{id}") 110 public void addReview(@PathVariable Integer id, @RequestParam Integer rating, @RequestParam(required = false) String comment, 111 Model model, HttpServletResponse response, HttpServletRequest request){ 112 Client client = (Client) userService.findByUsername(request.getRemoteUser()); 113 Repair repair = repairService.findById(id); 114 reviewRepository.save(new Review(rating, 115 comment==null ? "" : comment, repair,client)); 116 try { 117 response.sendRedirect("/repairs"); 118 } catch (IOException e) { 119 throw new RuntimeException(e); 120 } 121 } 80 122 } -
src/main/java/com/example/autopartz/model/Repair.java
rf484b14 rd4b888e 18 18 @Id 19 19 @GeneratedValue(strategy = GenerationType.IDENTITY) 20 Integer ID_repair; 20 @Column(name = "ID_repair") 21 Integer id; 21 22 @OneToOne 22 23 @JoinColumn(name = "id_order") … … 34 35 this.serviceBook = serviceBook; 35 36 } 36 37 37 @Override 38 38 public boolean equals(Object o) { … … 40 40 if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; 41 41 Repair repair = (Repair) o; 42 return ID_repair != null && Objects.equals(ID_repair, repair.ID_repair);42 return id != null && Objects.equals(id, repair.id); 43 43 } 44 44 -
src/main/java/com/example/autopartz/model/Review.java
rf484b14 rd4b888e 7 7 import org.hibernate.Hibernate; 8 8 9 import javax.persistence.Entity; 10 import javax.persistence.Id; 11 import javax.persistence.JoinColumn; 12 import javax.persistence.ManyToOne; 9 import javax.persistence.*; 13 10 import java.util.Objects; 14 11 … … 20 17 public class Review { 21 18 @Id 19 @GeneratedValue(strategy = GenerationType.IDENTITY) 22 20 Integer ID_review; 23 21 Integer review_rating; … … 29 27 @JoinColumn(name = "id_user") 30 28 Client client; 29 30 public Review(Integer review_rating, String review_comment, Repair repair, Client client) { 31 this.review_rating = review_rating; 32 this.review_comment = review_comment; 33 this.repair = repair; 34 this.client = client; 35 } 31 36 32 37 @Override -
src/main/java/com/example/autopartz/model/views/RepairsForUser.java
rf484b14 rd4b888e 23 23 @Immutable 24 24 @Table(name = "`repairs_for_user`") 25 @IdClass(OrdersForUserId.class)26 25 public class RepairsForUser implements Serializable { 27 26 @Serial 28 27 private static final long serialVersionUID = 1L; 29 28 @Id 29 Integer repairid; 30 30 Integer userid; 31 @Id32 31 LocalDateTime orderdate; 33 @Id34 String partname;35 32 Integer orderid; 36 33 String rsname; -
src/main/java/com/example/autopartz/repository/RepairRepository.java
rf484b14 rd4b888e 4 4 import org.springframework.data.jpa.repository.JpaRepository; 5 5 6 import java.util.List; 7 6 8 public interface RepairRepository extends JpaRepository<Repair,Integer> { 9 List<Repair> findAllById(Integer id); 7 10 } -
src/main/java/com/example/autopartz/repository/RepairsForUserRepository.java
rf484b14 rd4b888e 9 9 10 10 @Repository 11 public interface RepairsForUserRepository extends JpaRepository<RepairsForUser, OrdersForUserId> {11 public interface RepairsForUserRepository extends JpaRepository<RepairsForUser, Integer> { 12 12 List<RepairsForUser> findAllByUserid(Integer userid); 13 13 } -
src/main/java/com/example/autopartz/service/OrderService.java
rf484b14 rd4b888e 10 10 Order create(Client user); 11 11 Order findById(Integer id); 12 void save(Order o); 12 13 } 13 14 -
src/main/java/com/example/autopartz/service/impl/OrderServiceImpl.java
rf484b14 rd4b888e 30 30 return orderRepository.findById(id).get(); 31 31 } 32 33 @Override 34 public void save(Order o) { 35 orderRepository.save(o); 36 } 32 37 } -
src/main/resources/templates/repairsForUser.html
rf484b14 rd4b888e 4 4 <thead> 5 5 <tr> 6 <th>Број на поправка</th> 6 7 <th>Датум на нарачка</th> 7 <th>Нарачан дел</th>8 8 <th>Број на нарачка</th> 9 9 <th>Име на сервис</th> 10 <th>Додај критика</th> 10 11 </tr> 11 12 </thead> 12 13 <tbody> 13 14 <tr th:each="repair : ${userRepairs}"> 15 <td th:text="${repair.getRepairid()}"></td> 14 16 <td th:text="${repair.getOrderdate}"></td> 15 <td th:text="${repair.getPartname()}"></td>16 17 <td th:text="${repair.getOrderid()}"></td> 17 18 <td th:text="${repair.getRsname()}"></td> 19 <td> 20 <div th:if="${!hasReview.get(repair.getRepairid())}"> 21 <form th:action="@{'/repairs/addReview/{id}' (id=${repair.getRepairid()}) }"> 22 <button type="submit">Додај критика</button> 23 </form> 24 </div> 25 <div th:if="${hasReview.get(repair.getRepairid())}"> 26 Веќе има критика 27 </div> 28 </td> 18 29 </tr> 19 30 </tbody>
Note:
See TracChangeset
for help on using the changeset viewer.