Changeset 676144b for src/main


Ignore:
Timestamp:
01/05/23 04:11:40 (23 months ago)
Author:
andrejtodorovski <82031894+andrejtodorovski@…>
Branches:
main
Children:
1bd8d1e
Parents:
7d43957
Message:

Added admin view of pending roles and approve functionality

Location:
src/main
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/autopartz/config/WebSecurityConfig.java

    r7d43957 r676144b  
    2828        http.csrf().disable()
    2929                .authorizeRequests()
    30                 .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*").permitAll()
     30                .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/viewUsers","/approve/*").permitAll()
    3131                .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder").hasRole("CLIENT")
    3232                .anyRequest()
  • src/main/java/com/example/autopartz/controller/HomeController.java

    r7d43957 r676144b  
    102102    public void handleLogin(@RequestParam String username, @RequestParam String password){
    103103        User u = loginService.login(username,password);
    104         System.out.println(u.getName_user());
     104        System.out.println(u.getName());
    105105    }
    106106    @PostMapping("/register")
  • src/main/java/com/example/autopartz/controller/PartController.java

    r7d43957 r676144b  
    5050    }
    5151    @PostMapping("/repairshopdelivery")
    52     public void setRepairShopDelivery(@RequestParam String name, HttpServletResponse response){
     52    public void setRepairShopDelivery(@RequestParam String name, HttpServletResponse response, HttpSession session){
    5353        // insert into project.repair (vin, id_repair_shop, id_service_book) values (1111,3,1)
     54        session.removeAttribute("order");
    5455        try {
    5556            response.sendRedirect("/");
     
    5960    }
    6061    @PostMapping("/homedelivery")
    61     public void setHomeDelivery(@RequestParam String address, HttpServletResponse response){
     62    public void setHomeDelivery(@RequestParam String address, HttpServletResponse response, HttpSession session){
    6263        // insert into delivery (delivery_status, delivery_address,id_user,id_order) values ('in progress','Aerodrom',4,1)
     64        session.removeAttribute("order");
    6365        try {
    6466            response.sendRedirect("/");
  • src/main/java/com/example/autopartz/controller/UserController.java

    r7d43957 r676144b  
    2828    @GetMapping("orders")
    2929    public String getOrdersForUser(Model model, HttpServletRequest request){
    30         Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
     30        Integer id = userService.findByUsername(request.getRemoteUser()).getId();
    3131        model.addAttribute("userOrders",ordersForUserRepository.findAllByUserid(id));
    3232        model.addAttribute("bodyContent","ordersForUser");
     
    3535    @GetMapping("repairs")
    3636    public String getRepairsForUser(Model model, HttpServletRequest request){
    37         Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
     37        Integer id = userService.findByUsername(request.getRemoteUser()).getId();
    3838        model.addAttribute("userRepairs",repairsForUserRepository.findAllByUserid(id));
    3939        model.addAttribute("bodyContent","repairsForUser");
     
    4242    @GetMapping("reviews")
    4343    public String getReviewsForUser(Model model,HttpServletRequest request){
    44         Integer id = userService.findByUsername(request.getRemoteUser()).getID_user();
     44        Integer id = userService.findByUsername(request.getRemoteUser()).getId();
    4545        model.addAttribute("userReviews",reviewsForUserRepository.findAllByUserid(id));
    4646        model.addAttribute("bodyContent","reviewsForUser");
  • src/main/java/com/example/autopartz/model/Administrator.java

    r7d43957 r676144b  
    2727        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    2828        Administrator that = (Administrator) o;
    29         return ID_user != null && Objects.equals(ID_user, that.ID_user);
     29        return id != null && Objects.equals(id, that.id);
    3030    }
    3131
  • src/main/java/com/example/autopartz/model/Client.java

    r7d43957 r676144b  
    2828        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    2929        Client client = (Client) o;
    30         return ID_user != null && Objects.equals(ID_user, client.ID_user);
     30        return id != null && Objects.equals(id, client.id);
    3131    }
    3232
  • src/main/java/com/example/autopartz/model/Deliveryman.java

    r7d43957 r676144b  
    3535        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    3636        Deliveryman that = (Deliveryman) o;
    37         return ID_user != null && Objects.equals(ID_user, that.ID_user);
     37        return id != null && Objects.equals(id, that.id);
    3838    }
    3939
  • src/main/java/com/example/autopartz/model/User.java

    r7d43957 r676144b  
    2525    @Id
    2626    @GeneratedValue(strategy = GenerationType.IDENTITY)
    27     Integer ID_user;
     27    @Column(name = "ID_user")
     28    Integer id;
    2829    String username;
    2930    String email;
    30     String name_user;
     31    @Column(name = "name_user")
     32    String name;
    3133    @Column(name = "password_user")
    3234    String password;
     
    3941    public User(String username, String name, String email, String password, String number) {
    4042        this.username = username;
    41         this.name_user = name;
     43        this.name = name;
    4244        this.email = email;
    4345        this.password = password;
     
    5153        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    5254        User user = (User) o;
    53         return ID_user != null && Objects.equals(ID_user, user.ID_user);
     55        return id != null && Objects.equals(id, user.id);
    5456    }
    5557
  • src/main/java/com/example/autopartz/model/Warehouseman.java

    r7d43957 r676144b  
    3939        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
    4040        Warehouseman that = (Warehouseman) o;
    41         return ID_user != null && Objects.equals(ID_user, that.ID_user);
     41        return id != null && Objects.equals(id, that.id);
    4242    }
    4343
     
    4848    @Override
    4949    public Collection<? extends GrantedAuthority> getAuthorities() {
    50         if(employed_from==defaultEmployedFrom)
     50        if(Objects.equals(employed_from, defaultEmployedFrom))
    5151            return Collections.singletonList(Role.ROLE_PENDING_WAREHOUSEMAN);
    5252        else
  • src/main/java/com/example/autopartz/model/views/ReviewsForUser.java

    r7d43957 r676144b  
    2828    Integer userid;
    2929    Integer rating;
     30    Integer orderid;
    3031    String rcomment;
    3132    String rsname;
  • src/main/java/com/example/autopartz/repository/UserRepository.java

    r7d43957 r676144b  
    33import com.example.autopartz.model.User;
    44import org.springframework.data.jpa.repository.JpaRepository;
     5import org.springframework.security.core.GrantedAuthority;
    56import org.springframework.stereotype.Repository;
    67
     8import java.util.Collection;
    79import java.util.List;
    810
  • src/main/java/com/example/autopartz/service/UserService.java

    r7d43957 r676144b  
    88    List<User> findAllUsers();
    99    User findByUsername(String username);
    10 
     10    User findById(Integer id);
    1111}
  • src/main/java/com/example/autopartz/service/impl/UserServiceImpl.java

    r7d43957 r676144b  
    11package com.example.autopartz.service.impl;
    22
     3import com.example.autopartz.model.Role;
    34import com.example.autopartz.model.User;
    45import com.example.autopartz.repository.UserRepository;
     
    67import org.springframework.stereotype.Service;
    78
     9import java.util.Collections;
    810import java.util.List;
    911
     
    2527        return userRepository.findAllByUsername(username).stream().findFirst().orElseThrow(RuntimeException::new);
    2628    }
     29
     30    @Override
     31    public User findById(Integer id) {
     32        return userRepository.findById(id).get();
     33    }
    2734}
  • src/main/resources/templates/reviewsForUser.html

    r7d43957 r676144b  
    88    <th>Име на сервис</th>
    99    <th>Локација на сервис</th>
     10    <th>За нарачка број</th>
    1011  </tr>
    1112  </thead>
     
    1617    <td th:text="${review.getRsname()}"></td>
    1718    <td th:text="${review.getRslocation()}"></td>
     19    <td th:text="${review.getOrderid}"></td>
    1820  </tr>
    1921  </tbody>
Note: See TracChangeset for help on using the changeset viewer.