[2e46f06] | 1 | package com.example.autopartz.controller;
|
---|
| 2 |
|
---|
[23a2bc5] | 3 | import com.example.autopartz.model.*;
|
---|
[feffc2f] | 4 | import com.example.autopartz.model.views.*;
|
---|
[23a2bc5] | 5 | import com.example.autopartz.repository.*;
|
---|
[2e46f06] | 6 | import com.example.autopartz.service.UserService;
|
---|
[feffc2f] | 7 | import org.springframework.stereotype.Controller;
|
---|
| 8 | import org.springframework.ui.Model;
|
---|
[23a2bc5] | 9 | import org.springframework.web.bind.annotation.*;
|
---|
[2e46f06] | 10 |
|
---|
| 11 | import java.util.List;
|
---|
| 12 |
|
---|
[feffc2f] | 13 | @Controller
|
---|
[2e46f06] | 14 | @RequestMapping("/")
|
---|
| 15 | public class UserController {
|
---|
| 16 | private final UserService userService;
|
---|
[23a2bc5] | 17 | private final RepairShopReviewSummaryRepository repairShopReviewSummaryRepository;
|
---|
| 18 | private final PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository;
|
---|
[2e46f06] | 19 |
|
---|
[23a2bc5] | 20 | private final OrdersForUserRepository ordersForUserRepository;
|
---|
| 21 | private final RepairsForUserRepository repairsForUserRepository;
|
---|
| 22 | private final ReviewsForUserRepository reviewsForUserRepository;
|
---|
| 23 | public UserController(UserService userService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository) {
|
---|
[2e46f06] | 24 | this.userService = userService;
|
---|
[23a2bc5] | 25 | this.repairShopReviewSummaryRepository = repairShopReviewSummaryRepository;
|
---|
| 26 | this.partsForCarTypeAndCategoryRepository = partsForCarTypeAndCategoryRepository;
|
---|
| 27 | this.ordersForUserRepository = ordersForUserRepository;
|
---|
| 28 | this.repairsForUserRepository = repairsForUserRepository;
|
---|
| 29 | this.reviewsForUserRepository = reviewsForUserRepository;
|
---|
[2e46f06] | 30 | }
|
---|
| 31 | @GetMapping("reportTest")
|
---|
| 32 | public List<RepairShopReviewsSummary> getRepairShopReport(){
|
---|
[23a2bc5] | 33 | return repairShopReviewSummaryRepository.findAll();
|
---|
[2e46f06] | 34 | }
|
---|
| 35 | @GetMapping("usersTest")
|
---|
| 36 | public List<User> getAllUsers(){
|
---|
| 37 | return userService.findAllUsers();
|
---|
| 38 | }
|
---|
[23a2bc5] | 39 | @GetMapping("parts")
|
---|
| 40 | public List<PartsForCarTypeAndCategory> getPartsForCarTypeAndCategory(@RequestParam String cartype, @RequestParam String category){
|
---|
| 41 | return partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category);
|
---|
| 42 | }
|
---|
| 43 | @GetMapping("orders/{id}")
|
---|
[feffc2f] | 44 | public String getOrdersForUser(@PathVariable Long id, Model model){
|
---|
| 45 | model.addAttribute("userOrders",ordersForUserRepository.findAllByUserid(id));
|
---|
| 46 | return "ordersForUser";
|
---|
[23a2bc5] | 47 | }
|
---|
| 48 | @GetMapping("repairs/{id}")
|
---|
[feffc2f] | 49 | public String getRepairsForUser(@PathVariable Long id,Model model){
|
---|
| 50 | model.addAttribute("userRepairs",repairsForUserRepository.findAllByUserid(id));
|
---|
| 51 | return "repairsForUser";
|
---|
[23a2bc5] | 52 | }
|
---|
| 53 | @GetMapping("reviews/{id}")
|
---|
[feffc2f] | 54 | public String getReviewsForUser(@PathVariable Long id, Model model){
|
---|
| 55 | model.addAttribute("userReviews",reviewsForUserRepository.findAllByUserid(id));
|
---|
| 56 | return "reviewsForUser";
|
---|
[23a2bc5] | 57 | }
|
---|
[2e46f06] | 58 | }
|
---|