Changeset 5f53114


Ignore:
Timestamp:
03/05/23 17:35:54 (21 months ago)
Author:
SazdovaEkaterina <sazdovaekaterina@…>
Branches:
main
Children:
8b7dd7f
Parents:
9358bff
Message:

use model instead of session

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

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r9358bff r5f53114  
    7777
    7878    @GetMapping("/adoption-posts")
    79     public String getAdoptionPosts(Model model, HttpServletRequest request){
     79    public String getAdoptionPosts(Model model){
    8080
    8181        List<Post> posts = this.postService.findAll();
    8282        List<Pet> pets = this.petService.listpets();
    83         //model.addAttribute("posts", posts);
    84         //model.addAttribute("pets",pets);
    85         request.getSession().setAttribute("posts",posts);//temp
    86         request.getSession().setAttribute("pets",pets);//temp
     83        model.addAttribute("posts", posts);
     84        model.addAttribute("pets",pets);
    8785
    8886        return "list-posts-adoption";
     
    9088
    9189    @GetMapping("/pet-details-{id}")
    92     public String getPostDetails(@PathVariable Integer id, Model model, HttpServletRequest request){
     90    public String getPostDetails(@PathVariable Integer id,
     91                                 Model model){
    9392
    9493        Post post = this.postService.findById(id).get();
    9594        Pet pet = this.petService.findById(post.getPetId());
    9695
    97         //model.addAttribute("pet", pet);
    98         //model.addAttribute("post", post);
    99         request.getSession().setAttribute("post", post);//temp
    100         request.getSession().setAttribute("pet", pet);//temp
    101 
    102         if(pet.getAdoptionId() != null){
    103             request.getSession().setAttribute("disableAdoption", true);
    104         } else{
    105             request.getSession().setAttribute("disableAdoption", false);
    106         }
     96        model.addAttribute("pet", pet);
     97        model.addAttribute("post", post);
    10798
    10899        return "pet-details";
  • Prototype Application/Paw5/src/main/resources/templates/list-posts-adoption.html

    r9358bff r5f53114  
    11<!DOCTYPE html>
    22<html xmlns="http://www.w3.org/1999/xhtml"
    3       xmlns:th="http://www.thymeleaf.org"
     3      xmlns:th="http://thymeleaf.org"
    44      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
    55      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
     
    4545        <th>Species</th>
    4646    </tr>
    47     <tr th:each = "post : ${session.posts}">
     47    <tr th:each = "post : ${posts}">
    4848        <td th:text = "${post.getId()}"></td>
    49         <td th:each = "pet : ${session.pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getName()}"></td>
    50         <td th:each = "pet : ${session.pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getSpecies()}"></td>
     49        <td th:each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getName()}"></td>
     50        <td th:each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getSpecies()}"></td>
    5151        <td>
    5252            <form th:action="@{'/pet-details-{id}' (id=${post.getId()})}"
  • Prototype Application/Paw5/src/main/resources/templates/pet-details.html

    r9358bff r5f53114  
    11<!DOCTYPE html>
    22<html xmlns="http://www.w3.org/1999/xhtml"
    3       xmlns:th="http://www.thymeleaf.org"
     3      xmlns:th="http://thymeleaf.org"
    44      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
    55      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
     
    4141    <tr>
    4242        <th>Post ID</th>
    43         <td th:text = "${session.post.getId()}"></td>
     43        <td th:text = "${post.getId()}"></td>
    4444    <tr>
    4545        <th>Pet Name</th>
    46         <td th:text = "${session.pet.getName()}"></td>
     46        <td th:text = "${pet.getName()}"></td>
    4747    </tr>
    4848    <tr>
    4949        <th>Species</th>
    50         <td th:text = "${session.pet.getSpecies()}"></td>
     50        <td th:text = "${pet.getSpecies()}"></td>
    5151    </tr>
    5252    <tr>
    5353        <th>Breed</th>
    54         <td th:text = "${session.pet.getBreed()}"></td>
     54        <td th:text = "${pet.getBreed()}"></td>
    5555    </tr>
    5656    <tr>
    5757        <th>Gender</th>
    58         <td th:text = "${session.pet.getGender()}"></td>
     58        <td th:text = "${pet.getGender()}"></td>
    5959    </tr>
    6060    <tr>
    6161        <th>Age Group</th>
    62         <td th:text = "${session.pet.getAgeGroup}"></td>
     62        <td th:text = "${pet.getAgeGroup}"></td>
    6363    </tr>
    6464    <tr>
    6565        <th>Size</th>
    66         <td th:text = "${session.pet.getSize()}"></td>
     66        <td th:text = "${pet.getSize()}"></td>
    6767    </tr>
    6868</table>
    6969<form method="POST"
    70       th:action="@{'/submit-adopton-{id}' (id=${session.pet.getId()})}"
    71       th:if="${session.pet.getAdoptionId()==null}">
    72     <button id="submit" type="submit">Adopt</button>
     70      th:action="@{'/submit-adopton-{id}' (id=${pet.getId()})}"
     71      th:if="${pet.getAdoptionId()==null}">
     72    <button id="submit"
     73            type="submit"
     74            class="btn">Adopt</button>
    7375</form>
    7476
Note: See TracChangeset for help on using the changeset viewer.