Ignore:
Timestamp:
07/26/23 19:26:35 (16 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Parents:
e02787e
Message:

Added transactional methods to secure the database integrity and refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/controller/UserController.java

    re02787e r2a552fe  
    2525    private final UserService userService;
    2626    private final CarService carService;
    27     private final CarSampleRepository carSampleRepository;
    28     private final ServiceBookRepository serviceBookRepository;
    2927    private final RepairService repairService;
    3028    private final ReviewRepository reviewRepository;
    31     private final RepairRepository repairRepository;
    3229    private final OrderRepository orderRepository;
    3330
    34     public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, CarSampleRepository carSampleRepository, ServiceBookRepository serviceBookRepository, RepairService repairService, ReviewRepository reviewRepository,
    35                           RepairRepository repairRepository,
     31    public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, RepairService repairService, ReviewRepository reviewRepository,
    3632                          OrderRepository orderRepository) {
    3733        this.ordersForUserRepository = ordersForUserRepository;
     
    4036        this.userService = userService;
    4137        this.carService = carService;
    42         this.carSampleRepository = carSampleRepository;
    43         this.serviceBookRepository = serviceBookRepository;
    4438        this.repairService = repairService;
    4539        this.reviewRepository = reviewRepository;
    46         this.repairRepository = repairRepository;
    4740        this.orderRepository = orderRepository;
    4841    }
     
    9285                                    @RequestParam Integer km, @RequestParam Integer cartype,
    9386                                    HttpServletRequest request, HttpServletResponse response){
    94         CarSample cs = new CarSample(vin,year,power,displacement,fuel,km, (Client) userService.findByUsername(request.getRemoteUser()),carService.findById(cartype));
    95         carSampleRepository.save(cs);
    96         serviceBookRepository.save(new ServiceBook(cs));
     87        userService.addCarSampleForUser(vin,year,power,displacement,fuel,km,cartype,request.getRemoteUser());
    9788        try {
    9889            response.sendRedirect("/");
     
    109100    @PostMapping("/repairs/addReview/{id}")
    110101    public void addReview(@PathVariable Integer id, @RequestParam Integer rating, @RequestParam(required = false) String comment,
    111                           Model model, HttpServletResponse response, HttpServletRequest request){
     102                          HttpServletResponse response, HttpServletRequest request){
    112103        Client client = (Client) userService.findByUsername(request.getRemoteUser());
    113104        Repair repair = repairService.findById(id);
Note: See TracChangeset for help on using the changeset viewer.