- Timestamp:
- 01/06/23 02:51:45 (23 months ago)
- Branches:
- main
- Children:
- d4b888e
- Parents:
- 1bd8d1e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/autopartz/controller/UserController.java
r1bd8d1e rf484b14 1 1 package com.example.autopartz.controller; 2 2 3 import com.example.autopartz.repository.OrdersForUserRepository; 4 import com.example.autopartz.repository.RepairsForUserRepository; 5 import com.example.autopartz.repository.ReviewsForUserRepository; 3 import com.example.autopartz.model.CarSample; 4 import com.example.autopartz.model.Client; 5 import com.example.autopartz.model.ServiceBook; 6 import com.example.autopartz.repository.*; 7 import com.example.autopartz.service.CarService; 6 8 import com.example.autopartz.service.UserService; 7 9 import org.springframework.stereotype.Controller; 8 10 import org.springframework.ui.Model; 9 11 import org.springframework.web.bind.annotation.GetMapping; 10 import org.springframework.web.bind.annotation.P athVariable;12 import org.springframework.web.bind.annotation.PostMapping; 11 13 import org.springframework.web.bind.annotation.RequestMapping; 14 import org.springframework.web.bind.annotation.RequestParam; 12 15 13 16 import javax.servlet.http.HttpServletRequest; 17 import javax.servlet.http.HttpServletResponse; 18 import java.io.IOException; 14 19 15 20 @Controller … … 20 25 private final ReviewsForUserRepository reviewsForUserRepository; 21 26 private final UserService userService; 22 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService) { 27 private final CarService carService; 28 private final CarSampleRepository carSampleRepository; 29 private final ServiceBookRepository serviceBookRepository; 30 public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService, CarService carService, CarSampleRepository carSampleRepository, ServiceBookRepository serviceBookRepository) { 23 31 this.ordersForUserRepository = ordersForUserRepository; 24 32 this.repairsForUserRepository = repairsForUserRepository; 25 33 this.reviewsForUserRepository = reviewsForUserRepository; 26 34 this.userService = userService; 35 this.carService = carService; 36 this.carSampleRepository = carSampleRepository; 37 this.serviceBookRepository = serviceBookRepository; 27 38 } 28 39 @GetMapping("orders") … … 47 58 return "master-template"; 48 59 } 60 @GetMapping("/addCarSampleForUser") 61 public String addCarSampleForUser(Model model){ 62 model.addAttribute("bodyContent","addCarSampleForUser"); 63 model.addAttribute("cars",carService.findAll()); 64 return "master-template"; 65 } 66 @PostMapping("/addCarSampleForUser") 67 public void addCarSampleForUser(@RequestParam Integer vin, @RequestParam Integer year, @RequestParam Integer power, 68 @RequestParam Integer displacement, @RequestParam String fuel, 69 @RequestParam Integer km, @RequestParam Integer cartype, 70 HttpServletRequest request, HttpServletResponse response){ 71 CarSample cs = new CarSample(vin,year,power,displacement,fuel,km, (Client) userService.findByUsername(request.getRemoteUser()),carService.findById(cartype)); 72 carSampleRepository.save(cs); 73 serviceBookRepository.save(new ServiceBook(cs)); 74 try { 75 response.sendRedirect("/"); 76 } catch (IOException e) { 77 throw new RuntimeException(e); 78 } 79 } 49 80 }
Note:
See TracChangeset
for help on using the changeset viewer.