Changes in / [eac569a:3c7bf5b]
- Location:
- Prototype Application/Paw5/src/main
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Prototype Application/Paw5/src/main/java/finki/paw5/service/PetService.java
reac569a r3c7bf5b 2 2 3 3 import finki.paw5.model.entities.Pet; 4 import finki.paw5.web.controllers.PostController; 4 5 5 6 import java.util.List; 7 import java.util.Optional; 6 8 7 9 public interface PetService { … … 9 11 void save (Pet pet); 10 12 11 List<Pet> listpets();13 List<Pet> findAll(); 12 14 13 Pet findById(Integer id);15 Optional<Pet> findById(Integer petId); 14 16 } -
Prototype Application/Paw5/src/main/java/finki/paw5/service/PostService.java
reac569a r3c7bf5b 2 2 3 3 import finki.paw5.model.entities.Post; 4 4 5 import java.util.List; 5 6 import java.util.Optional; -
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java
reac569a r3c7bf5b 7 7 8 8 import java.util.List; 9 import java.util.Optional; 9 10 10 11 @Service … … 22 23 } 23 24 24 public List<Pet> listpets() {return this.petRepository.findAll();} 25 @Override 26 public List<Pet> findAll() { 27 return this.petRepository.findAll(); 28 } 25 29 26 30 @Override 27 public Pet findById(Integer id) {28 return this.petRepository.findById( id).get();31 public Optional<Pet> findById(Integer petId) { 32 return this.petRepository.findById(petId); 29 33 } 30 34 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/HomeController.java
reac569a r3c7bf5b 1 1 package finki.paw5.web.controllers; 2 2 3 import jakarta.servlet.http.HttpServletRequest;4 3 import org.springframework.stereotype.Controller; 5 4 import org.springframework.web.bind.annotation.GetMapping; … … 11 10 12 11 @GetMapping 13 public String getHomePage(HttpServletRequest request) { 14 if(request.getSession().getAttribute("user")==null){ 15 return "redirect:/login"; 16 } 12 public String getHomePage(){ 17 13 return "home"; 18 14 } 19 20 15 @GetMapping("/aboutUs") 21 public String getSuccessPage() 16 public String getSuccessPage(){ 22 17 return "/aboutUs"; 23 18 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java
reac569a r3c7bf5b 28 28 public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) { 29 29 30 Pet pet = this.petService.findById(id) ;30 Pet pet = this.petService.findById(id).orElseThrow(InvalidPetIdException::new); 31 31 32 32 User user = (User) request.getSession().getAttribute("user"); -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java
reac569a r3c7bf5b 1 1 package finki.paw5.web.controllers; 2 3 import finki.paw5.model.entities.PersonalProfile; 2 4 import finki.paw5.model.entities.Pet; 3 5 import finki.paw5.model.entities.Post; 4 import finki.paw5.model.entities. Employee;6 import finki.paw5.model.entities.Shelter; 5 7 import finki.paw5.model.enumerations.AgeGroup; 6 8 import finki.paw5.model.enumerations.Gender; … … 35 37 } 36 38 37 @GetMapping(" /create-post")39 @GetMapping("create-post") 38 40 public String get(Model model) { 39 model.addAttribute("pets", this.petService.listpets()); 41 //TODO: vakvo ama za lista so pets 42 // List<Manufacturer> manufacturers = this.manufacturerService.findAll(); 43 // model.addAttribute("manufacturers", manufacturers); 40 44 return "create-post"; 41 45 } 42 46 43 @PostMapping("/submit-post") 44 public String savePost(@RequestParam(required = false) Integer petId, 45 @RequestParam(required = false) boolean newPetCheckbox, 46 @RequestParam(required = false) String name, 47 @RequestParam(required = false) String gender, 48 @RequestParam(required = false) String ageGroup, 49 @RequestParam(required = false) String size, 50 @RequestParam(required = false) String species, 47 @PostMapping("submit-post") 48 public String savePost(@RequestParam(required = false) String name, 49 @RequestParam String gender, 50 @RequestParam String ageGroup, 51 @RequestParam String size, 52 @RequestParam String species, 51 53 @RequestParam(required = false) String breed, 52 54 @RequestParam(required = false) String imageUrl, 53 @RequestParam(required = false) boolean canBeFostered, 54 HttpServletRequest request) { 55 @RequestParam(required = false) boolean canBeFostered) { 55 56 56 Employee employee = (Employee) request.getSession().getAttribute("user"); 57 Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, 1); 58 this.petService.save(pet); 57 59 58 if(newPetCheckbox == true){ 59 60 Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId()); 61 this.petService.save(newPet); 62 63 Post post = new Post(LocalDate.now(), imageUrl, newPet.getId(), null, employee.getId()); 64 this.postService.save(post); 65 66 } else{ 67 68 Pet selectedPet = this.petService.findById(petId); 69 70 Post post = new Post(LocalDate.now(), imageUrl, selectedPet.getId(), null, employee.getId()); 71 this.postService.save(post); 72 73 } 60 Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, 10);//TODO: employee id da se zeme preku session user getid 61 this.postService.save(post); 74 62 75 63 return "redirect:/home"; … … 80 68 81 69 List<Post> posts = this.postService.findAll(); 82 List<Pet> pets = this.petService. listpets();70 List<Pet> pets = this.petService.findAll(); 83 71 //model.addAttribute("posts", posts); 84 72 //model.addAttribute("pets",pets); … … 93 81 94 82 Post post = this.postService.findById(id).get(); 95 Pet pet = this.petService.findById(post.getPetId()) ;83 Pet pet = this.petService.findById(post.getPetId()).get(); 96 84 97 85 //model.addAttribute("pet", pet); -
Prototype Application/Paw5/src/main/resources/templates/aboutUs.html
reac569a r3c7bf5b 1 1 <!DOCTYPE html> 2 <html lang="en" xmlns:th="http://thymeleaf.org">2 <html lang="en"> 3 3 <head> 4 4 <meta charset="UTF-8"> -
Prototype Application/Paw5/src/main/resources/templates/create-post.html
reac569a r3c7bf5b 1 1 <!DOCTYPE html> 2 2 <html xmlns="http://www.w3.org/1999/xhtml" 3 xmlns:th="http:// thymeleaf.org"3 xmlns:th="http://www.thymeleaf.org" 4 4 xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" 5 5 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> … … 7 7 <meta charset="UTF-8"> 8 8 <title>Create a post</title> 9 <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">10 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>11 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>12 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>13 <script>14 function addNewPet(addNewPetCheckBox){15 16 if(addNewPetCheckBox.checked){17 18 document.getElementById("name").disabled = false;19 document.getElementById("gender").disabled = false;20 document.getElementById("ageGroup").disabled = false;21 document.getElementById("size").disabled = false;22 document.getElementById("species").disabled = false;23 document.getElementById("breed").disabled = false;24 document.getElementById("imageUrl").disabled = false;25 document.getElementById("canBeFostered").disabled = false;26 27 document.getElementById("petId").disabled = true;28 } else{29 30 document.getElementById("name").disabled = true;31 document.getElementById("gender").disabled = true;32 document.getElementById("ageGroup").disabled = true;33 document.getElementById("size").disabled = true;34 document.getElementById("species").disabled = true;35 document.getElementById("breed").disabled = true;36 document.getElementById("imageUrl").disabled = true;37 document.getElementById("canBeFostered").disabled = true;38 39 document.getElementById("petId").disabled = false;40 41 }42 }43 </script>44 9 </head> 45 10 <body> 46 <header>47 <nav class="navbar navbar-expand-md navbar-dark bg-dark">48 <div class="container">49 <a class="navbar-brand" href="/home">Paw 5</a>50 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"51 aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">52 <span class="navbar-toggler-icon"></span>53 </button>54 55 <div class="collapse navbar-collapse justify-content-end" id="navbarsExampleDefault">56 <ul class="navbar-nav m-auto">57 <li class="nav-item m-auto">58 <a class="nav-link active" href="/home/aboutUs">About us</a>59 </li>60 <li class="nav-item m-auto">61 <a class="nav-link active" href="/login">Login</a>62 </li>63 <li class="nav-item m-auto">64 <a class="nav-link active" href="/register">Register</a>65 </li>66 </ul>67 </div>68 </div>69 </nav>70 </header>71 11 <h1>Create post</h1> 72 12 <form th:action="@{/submit-post}" method="post"> 73 13 74 14 <div> 75 <label for="petId">Select pet:</label> 76 <select id="petId" name="petId"> 77 <option 78 th:each="pet :${pets}" 79 th:text="${pet.getName()}" 80 th:value="${pet.getId()}"> 81 </option> 15 <label for="pet">Selet pet:</label> 16 <select id="pet"> 82 17 </select> 83 18 </div> 84 19 85 20 <div> 86 <label for="new PetCheckbox">Add new pet:</label>87 <input id="new PetCheckbox" name="newPetCheckbox" type="checkbox" onclick="addNewPet(this)">21 <label for="newpet">Add new pet:</label> 22 <input id="newpet" name="newpet" placeholder="newpet" type="checkbox"> 88 23 </div> 89 24 … … 94 29 name="name" 95 30 class="form-control" 96 placeholder="Enter name" 97 disabled> 31 placeholder="Enter name"> 98 32 </div> 99 33 … … 102 36 <select id="gender" 103 37 name="gender" 104 class="form-control" 105 disabled> 38 class="form-control"> 106 39 <option value = "MALE">male</option> 107 40 <option value = "FEMALE">female</option> … … 113 46 <select id="ageGroup" 114 47 name="ageGroup" 115 class="form-control" 116 disabled> 48 class="form-control"> 117 49 <option value = "YOUNG">young</option> 118 50 <option value = "ADULT">adult</option> … … 125 57 <select id="size" 126 58 name="size" 127 class="form-control" 128 disabled> 59 class="form-control"> 129 60 <option value = "XSMALL">extra small</option> 130 61 <option value = "SMALL">small</option> … … 139 70 <select id="species" 140 71 name="species" 141 class="form-control" 142 disabled> 72 class="form-control"> 143 73 <option value = "CAT">cat</option> 144 74 <option value = "DOG">dog</option> … … 153 83 name="breed" 154 84 class="form-control" 155 placeholder="Enter breed" 156 disabled> 85 placeholder="Enter breed" > 157 86 </div> 158 87 … … 163 92 name="imageUrl" 164 93 class="form-control" 165 placeholder="Enter image URL" 166 disabled> 94 placeholder="Enter image URL"> 167 95 <!-- <label for="upload">Image:</label> 168 96 <input id="upload" type="file" accept="image/*"> … … 176 104 name="canBeFostered" 177 105 class="form-control" 178 value=false 179 disabled> 106 value=false> 180 107 </div> 181 108 -
Prototype Application/Paw5/src/main/resources/templates/home.html
reac569a r3c7bf5b 1 1 <!DOCTYPE html> 2 <html lang="en" xmlns:th="http://thymeleaf.org">2 <html lang="en"> 3 3 <head> 4 4 <meta charset="UTF-8"> … … 35 35 </nav> 36 36 </header> 37 <div> 38 <form method="get" th:action="@{'/create-post'}"> 39 <button id="submit" type="submit">Create an Adoption Post</button> 40 </form> 41 </div> 37 42 38 <div> 43 39 <h1>Welcome to Paw 5</h1> -
Prototype Application/Paw5/src/main/resources/templates/login.html
reac569a r3c7bf5b 1 1 <!DOCTYPE html> 2 <html lang="en" xmlns:th="http://thymeleaf.org">2 <html lang="en"> 3 3 <head> 4 4 <meta charset="UTF-8"> -
Prototype Application/Paw5/src/main/resources/templates/register.html
reac569a r3c7bf5b 1 1 <!DOCTYPE html> 2 <html lang="en" xmlns:th="http:// thymeleaf.org">2 <html lang="en" xmlns:th="http://www.thymeleaf.org"> 3 3 <head> 4 4 <meta charset="UTF-8">
Note:
See TracChangeset
for help on using the changeset viewer.