Changeset 7aa3382


Ignore:
Timestamp:
03/10/23 22:17:37 (21 months ago)
Author:
SazdovaEkaterina <sazdovaekaterina@…>
Branches:
main
Children:
4ab3aae
Parents:
56a6233
Message:

add approve functionality

Location:
Prototype Application/Paw5/src/main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/AdopterService.java

    r56a6233 r7aa3382  
    77public interface AdopterService {
    88    List<Adopter> findAllThatNeedApproval();
     9
     10    Adopter findById(Integer id);
     11
     12    void save(Adopter adopter);
    913}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/AdopterServiceImplementation.java

    r56a6233 r7aa3382  
    2424                .collect(Collectors.toList());
    2525    }
     26
     27    @Override
     28    public Adopter findById(Integer id) {
     29        return this.adopterRepository.findById(id).get();
     30    }
     31
     32    @Override
     33    public void save(Adopter adopter) {
     34        this.adopterRepository.save(adopter);
     35    }
    2636}
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/EmployeeController.java

    r56a6233 r7aa3382  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.Adopter;
     4import finki.paw5.model.entities.Employee;
    35import finki.paw5.service.AdopterService;
     6import finki.paw5.service.EmployeeService;
     7import jakarta.servlet.http.HttpServletRequest;
    48import org.springframework.stereotype.Controller;
    59import org.springframework.ui.Model;
    610import org.springframework.web.bind.annotation.GetMapping;
     11import org.springframework.web.bind.annotation.PathVariable;
     12import org.springframework.web.bind.annotation.PostMapping;
    713import org.springframework.web.bind.annotation.RequestMapping;
    814
     
    1016@RequestMapping("/")
    1117public class EmployeeController {
     18
    1219    private final AdopterService adopterService;
     20    private final EmployeeService employeeService;
    1321
    14     public EmployeeController(AdopterService adopterService) {
     22    public EmployeeController(AdopterService adopterService, EmployeeService employeeService) {
    1523        this.adopterService = adopterService;
     24        this.employeeService = employeeService;
    1625    }
    1726
    18 
    1927    @GetMapping("/approve-adopters")
    20     public String getHomePage(Model model){
     28    public String getApprovalPage(Model model){
    2129        model.addAttribute("needApproval", this.adopterService.findAllThatNeedApproval());
    2230        return "/approve-adopters";
    2331    }
     32
     33    @PostMapping("/submit-approval-{id}")
     34    public String approveAdopter(@PathVariable Integer id, HttpServletRequest request){
     35
     36        Employee employeeVerificator = (Employee) request.getSession().getAttribute("user");
     37
     38        Adopter adopter = this.adopterService.findById(id);
     39
     40        adopter.setVerified(true);
     41        adopter.setEmployeeVerificator(employeeVerificator);
     42
     43        this.adopterService.save(adopter);
     44
     45        return "redirect:/approve-adopters";
     46    }
    2447}
  • Prototype Application/Paw5/src/main/resources/templates/approve-adopters.html

    r56a6233 r7aa3382  
    5050<div>
    5151  <h2>Adopters who are waiting for your approval</h2>
    52     <ul>
    53       <li
    54           th:each="adopter : ${needApproval}"
    55           th:text="${adopter.getName()}">
    56           <!--napravi tabela-->
    57       </li>
    58     </ul>
     52    <table>
     53        <tr>
     54            <td>Name</td>
     55            <td>Email Address</td>
     56            <td>Telephone Number</td>
     57            <td></td>
     58        </tr>
     59        <tr th:each="adopter : ${needApproval}">
     60            <td th:text="${adopter.getName()}"></td>
     61            <td th:text="${adopter.getEmail()}"></td>
     62            <td th:text="${adopter.getTelephone()}"></td>
     63            <td>
     64                <form method="POST"
     65                      th:action="@{'/submit-approval-{id}' (id=${adopter.getId()})}">
     66                    <button id="submit"
     67                            type="submit"
     68                            class="btn">Approve</button>
     69                </form>
     70            </td>
     71        </tr>
     72    </table>
    5973</div>
    6074</body>
Note: See TracChangeset for help on using the changeset viewer.