Changeset 60de3eb for src


Ignore:
Timestamp:
01/03/23 23:03:00 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
6832924
Parents:
feffc2f
Message:

Added master template and added filtering parts by car and category

Location:
src/main
Files:
9 added
14 edited

Legend:

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

    rfeffc2f r60de3eb  
    22
    33import com.example.autopartz.model.User;
     4import com.example.autopartz.repository.PartsForCarTypeAndCategoryRepository;
     5import com.example.autopartz.service.CarService;
     6import com.example.autopartz.service.CategoryService;
    47import com.example.autopartz.service.LoginService;
    58import com.example.autopartz.service.PartService;
     
    1619    private final LoginService loginService;
    1720    private final PartService partService;
     21    private final PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository;
     22    private final CarService carService;
     23    private final CategoryService categoryService;
    1824
    19     public HomeController(LoginService loginService, PartService partService) {
     25    public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService) {
    2026        this.loginService = loginService;
    2127        this.partService = partService;
     28        this.partsForCarTypeAndCategoryRepository = partsForCarTypeAndCategoryRepository;
     29        this.carService = carService;
     30        this.categoryService = categoryService;
    2231    }
    2332
     
    2534    public String getHomePage(Model model){
    2635        model.addAttribute("parts",partService.findAll());
    27         return "homepage";
     36        model.addAttribute("cars",carService.findAll());
     37        model.addAttribute("categories",categoryService.findAll());
     38        model.addAttribute("bodyContent","homepage");
     39        return "master-template";
     40    }
     41    @GetMapping("/filtered")
     42    public String getPartsForCarTypeAndCategory(@RequestParam String cartype, @RequestParam String category, Model model){
     43        model.addAttribute("filtered", partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category));
     44        model.addAttribute("bodyContent","filteredParts");
     45        return "master-template";
    2846    }
    2947    @GetMapping("/login")
    30     public String getLoginPage(){
    31         return "login";
     48    public String getLoginPage(Model model){
     49        model.addAttribute("bodyContent","login");
     50        return "master-template";
    3251    }
    3352    @GetMapping("/register")
    34     public String getRegisterPage(){
    35         return "register";
     53    public String getRegisterPage(Model model){
     54        model.addAttribute("bodyContent","register");
     55        return "master-template";
    3656    }
    3757    @PostMapping("/login")
    3858    public void handleLogin(@RequestParam String username, @RequestParam String password){
    3959        User u = loginService.login(username,password);
     60        System.out.println(u.getName_user());
    4061    }
    4162    @PostMapping("/register")
  • src/main/java/com/example/autopartz/controller/PartController.java

    rfeffc2f r60de3eb  
    2929        model.addAttribute("part",temp);
    3030        model.addAttribute("amount",amount);
    31         return "partinfo";
     31        model.addAttribute("bodyContent","partinfo");
     32        return "master-template";
    3233    }
    3334    @GetMapping("/delivery/{id}")
     
    3536        model.addAttribute("repairShops",repairShopService.findAll());
    3637        model.addAttribute("partId",id);
    37         return "deliveryForPart";
     38        model.addAttribute("bodyContent","deliveryForPart");
     39        return "master-template";
    3840    }
    3941    @PostMapping("/repairshopdelivery")
  • src/main/java/com/example/autopartz/controller/UserController.java

    rfeffc2f r60de3eb  
    1616    private final UserService userService;
    1717    private final RepairShopReviewSummaryRepository repairShopReviewSummaryRepository;
    18     private final PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository;
    1918
    2019    private final OrdersForUserRepository ordersForUserRepository;
    2120    private final RepairsForUserRepository repairsForUserRepository;
    2221    private final ReviewsForUserRepository reviewsForUserRepository;
    23     public UserController(UserService userService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository) {
     22    public UserController(UserService userService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository, OrdersForUserRepository ordersForUserRepository, RepairsForUserRepository repairsForUserRepository, ReviewsForUserRepository reviewsForUserRepository) {
    2423        this.userService = userService;
    2524        this.repairShopReviewSummaryRepository = repairShopReviewSummaryRepository;
    26         this.partsForCarTypeAndCategoryRepository = partsForCarTypeAndCategoryRepository;
    2725        this.ordersForUserRepository = ordersForUserRepository;
    2826        this.repairsForUserRepository = repairsForUserRepository;
     
    3735        return userService.findAllUsers();
    3836    }
    39     @GetMapping("parts")
    40     public List<PartsForCarTypeAndCategory> getPartsForCarTypeAndCategory(@RequestParam String cartype, @RequestParam String category){
    41         return partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category);
    42     }
    4337    @GetMapping("orders/{id}")
    4438    public String getOrdersForUser(@PathVariable Long id, Model model){
    4539        model.addAttribute("userOrders",ordersForUserRepository.findAllByUserid(id));
    46         return "ordersForUser";
     40        model.addAttribute("bodyContent","ordersForUser");
     41        return "master-template";
    4742    }
    4843    @GetMapping("repairs/{id}")
    4944    public String getRepairsForUser(@PathVariable Long id,Model model){
    5045        model.addAttribute("userRepairs",repairsForUserRepository.findAllByUserid(id));
    51         return "repairsForUser";
     46        model.addAttribute("bodyContent","repairsForUser");
     47        return "master-template";
    5248    }
    5349    @GetMapping("reviews/{id}")
    5450    public String getReviewsForUser(@PathVariable Long id, Model model){
    5551        model.addAttribute("userReviews",reviewsForUserRepository.findAllByUserid(id));
    56         return "reviewsForUser";
     52        model.addAttribute("bodyContent","reviewsForUser");
     53        return "master-template";
    5754    }
    5855}
  • src/main/java/com/example/autopartz/model/Car.java

    rfeffc2f r60de3eb  
    1818    Integer in_production_since;
    1919    Integer in_production_till;
    20     String car_type;
     20    @Column(name = "car_type")
     21    String cartype;
    2122    @ManyToOne
    2223    @JoinColumn(name = "id_car_manufacturer")
  • src/main/java/com/example/autopartz/model/Category.java

    rfeffc2f r60de3eb  
    11package com.example.autopartz.model;
    22
    3 import jakarta.persistence.Entity;
    4 import jakarta.persistence.Id;
    5 import jakarta.persistence.JoinColumn;
    6 import jakarta.persistence.ManyToOne;
     3import jakarta.persistence.*;
    74import lombok.*;
    85import org.hibernate.Hibernate;
     
    1815    @Id
    1916    Long ID_category;
    20     String category_name;
     17    @Column(name = "category_name")
     18    String cname;
    2119    @ManyToOne
    2220    @JoinColumn(name = "id_parent_category")
  • src/main/java/com/example/autopartz/model/views/PartsForCarTypeAndCategory.java

    rfeffc2f r60de3eb  
    2525    String cartype;
    2626    String category;
     27    String pmname;
    2728}
  • src/main/resources/templates/deliveryForPart.html

    rfeffc2f r60de3eb  
    1 <!DOCTYPE html>
    2 <html lang="en">
    3 <head>
    4     <meta charset="UTF-8">
    5     <title>Податоци за достава</title>
    6 </head>
    7 <body>
     1<div>
    82<header>
    93  <h1>Податоци за достава</h1>
     
    3327</main>
    3428
    35 </body>
    36 </html>
     29</div>
  • src/main/resources/templates/homepage.html

    rfeffc2f r60de3eb  
    1 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
    2       lang="en">
    3 <head>
    4     <meta charset="utf-8"/>
    5     <title>Почетна</title>
    6 </head>
    7 <body>
     1<div>
    82<header>
    93    <a th:href="${'/orders/4'}">Мои нарачки</a>
     
    137<main>
    148    <h1>Сите производи</h1>
     9    <form th:action="@{/filtered}">
     10        <label for="cartype"></label><select id="cartype" required name="cartype">
     11            <option  th:each="car : ${cars}"
     12                     th:text="${car.getCartype()}"
     13                     th:value="${car.getCartype()}">
     14            </option>
     15        </select>
     16        <label for="category"></label><select id="category" required name="category">
     17            <option  th:each="cat : ${categories}"
     18                     th:text="${cat.getCname()}"
     19                     th:value="${cat.getCname()}">
     20            </option>
     21        </select>
     22        <button type="submit">Филтрирај</button>
     23    </form>
    1524    <table>
    1625        <thead>
    1726        <tr>
    1827            <th>Name</th>
    19             <th>Description</th>
    2028            <th>Manufacturer</th>
    2129            <th>Details</th>
     
    2533        <tr th:each="part : ${parts}">
    2634            <td th:text="${part.getName()}"></td>
    27             <td th:text="${part.getDescription()}"></td>
    2835            <td th:text="${part.getManufacturer().getName()}"></td>
    2936            <td>
     
    3643    </table>
    3744</main>
    38 </body>
    39 </html>
     45</div>
  • src/main/resources/templates/login.html

    rfeffc2f r60de3eb  
    1 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en">
    2 <head>
    3     <title>Најава</title>
    4 <!--    <link href="/main.css" rel="stylesheet"/>-->
    5     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"/>
    6     <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    7     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    8     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    9 </head>
    10 <body>
     1<div>
    112<form th:method="POST" th:action="@{/login}">
    123    <div class="container">
     
    2617</form>
    2718<a href="/register" class="btn btn-block btn-light">Регистрирај се</a>
    28 </body>
    29 </html>
     19</div>
  • src/main/resources/templates/ordersForUser.html

    rfeffc2f r60de3eb  
    1 <!DOCTYPE html>
    2 <html lang="en">
    3 <head>
    4     <meta charset="UTF-8">
    5     <title>Мои нарачки</title>
    6 </head>
    7 <body>
     1<div>
    82<h1>Мои нарачки</h1>
    93<table>
     
    2721  </tbody>
    2822</table>
    29 </body>
    30 </html>
     23</div>
  • src/main/resources/templates/partinfo.html

    rfeffc2f r60de3eb  
    1 <!DOCTYPE html>
    2 <html lang="en">
    3 <head>
    4     <meta charset="UTF-8">
    5     <title>Детали</title>
    6 </head>
    7 <body>
     1<div>
    82<p th:text="${part.getName()}"></p>
    93<p th:text="${part.getDescription()}"></p>
     
    1610    <button type="submit">Купи</button>
    1711</form>
    18 </body>
    19 </html>
     12</div>
  • src/main/resources/templates/register.html

    rfeffc2f r60de3eb  
    1 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en">
    2 <head>
    3     <title>Login form</title>
    4     <!--    <link href="/main.css" rel="stylesheet"/>-->
    5     <title>Login</title>
    6     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"/>
    7     <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    8     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    9     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    10 </head>
    11 <body>
     1<div>
    122<form th:method="POST" th:action="@{/register}">
    133    <div class="container">
     
    4333</form>
    4434<a href="/login" class="btn btn-block btn-light">Веќе имате сметка? Најавете се</a>
    45 </body>
    46 </html>
     35</div>
  • src/main/resources/templates/repairsForUser.html

    rfeffc2f r60de3eb  
    1 <!DOCTYPE html>
    2 <html lang="en">
    3 <head>
    4     <meta charset="UTF-8">
    5     <title>Мои поправки</title>
    6 </head>
    7 <body>
     1<div>
    82<h1>Мои поправки</h1>
    93<table>
     
    126    <th>Датум на нарачка</th>
    137    <th>Нарачан дел</th>
    14     <th>Број на шасија</th>0olji
     8    <th>Број на шасија</th>
    159    <th>Име на сервис</th>
    1610  </tr>
     
    2519  </tbody>
    2620</table>
    27 </body>
    28 </html>
     21</div>
  • src/main/resources/templates/reviewsForUser.html

    rfeffc2f r60de3eb  
    1 <!DOCTYPE html>
    2 <html lang="en">
    3 <head>
    4     <meta charset="UTF-8">
    5     <title>Мои критики</title>
    6 </head>
    7 <body>
     1<div>
    82<h1>Мои критики</h1>
    93<table>
     
    2519  </tbody>
    2620</table>
    27 </body>
    28 </html>
     21</div>
Note: See TracChangeset for help on using the changeset viewer.