source: src/main/java/com/example/autopartz/controller/UserController.java@ feffc2f

main
Last change on this file since feffc2f was feffc2f, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 18 months ago

Added some views and functionalities

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[2e46f06]1package com.example.autopartz.controller;
2
[23a2bc5]3import com.example.autopartz.model.*;
[feffc2f]4import com.example.autopartz.model.views.*;
[23a2bc5]5import com.example.autopartz.repository.*;
[2e46f06]6import com.example.autopartz.service.UserService;
[feffc2f]7import org.springframework.stereotype.Controller;
8import org.springframework.ui.Model;
[23a2bc5]9import org.springframework.web.bind.annotation.*;
[2e46f06]10
11import java.util.List;
12
[feffc2f]13@Controller
[2e46f06]14@RequestMapping("/")
15public 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}
Note: See TracBrowser for help on using the repository browser.