Ignore:
Timestamp:
01/04/23 02:56:41 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
7d43957
Parents:
ae042f4
Message:

Fixed reviews, repairs, orders by logged user

File:
1 edited

Legend:

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

    rae042f4 rab952ab  
    44import com.example.autopartz.repository.RepairsForUserRepository;
    55import com.example.autopartz.repository.ReviewsForUserRepository;
     6import com.example.autopartz.service.UserService;
    67import org.springframework.stereotype.Controller;
    78import org.springframework.ui.Model;
     
    910import org.springframework.web.bind.annotation.PathVariable;
    1011import org.springframework.web.bind.annotation.RequestMapping;
     12
     13import javax.servlet.http.HttpServletRequest;
    1114
    1215@Controller
     
    1619    private final RepairsForUserRepository repairsForUserRepository;
    1720    private final ReviewsForUserRepository reviewsForUserRepository;
    18     public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository) {
     21    private final UserService userService;
     22    public UserController(OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository, UserService userService) {
    1923        this.ordersForUserRepository = ordersForUserRepository;
    2024        this.repairsForUserRepository = repairsForUserRepository;
    2125        this.reviewsForUserRepository = reviewsForUserRepository;
     26        this.userService = userService;
    2227    }
    23     @GetMapping("orders/{id}")
    24     public String getOrdersForUser(@PathVariable Integer id, Model model){
     28    @GetMapping("orders")
     29    public String getOrdersForUser(Model model, HttpServletRequest request){
     30        Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
    2531        model.addAttribute("userOrders",ordersForUserRepository.findAllByUserid(id));
    2632        model.addAttribute("bodyContent","ordersForUser");
    2733        return "master-template";
    2834    }
    29     @GetMapping("repairs/{id}")
    30     public String getRepairsForUser(@PathVariable Integer id,Model model){
     35    @GetMapping("repairs")
     36    public String getRepairsForUser(Model model, HttpServletRequest request){
     37        Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
    3138        model.addAttribute("userRepairs",repairsForUserRepository.findAllByUserid(id));
    3239        model.addAttribute("bodyContent","repairsForUser");
    3340        return "master-template";
    3441    }
    35     @GetMapping("reviews/{id}")
    36     public String getReviewsForUser(@PathVariable Integer id, Model model){
     42    @GetMapping("reviews")
     43    public String getReviewsForUser(Model model,HttpServletRequest request){
     44        Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
    3745        model.addAttribute("userReviews",reviewsForUserRepository.findAllByUserid(id));
    3846        model.addAttribute("bodyContent","reviewsForUser");
Note: See TracChangeset for help on using the changeset viewer.