Changeset 4103eaa for Prototype Application/Paw5/src
- Timestamp:
- 03/04/23 19:29:36 (20 months ago)
- Branches:
- main
- Children:
- f194b4e
- Parents:
- 8f1a362
- Location:
- Prototype Application/Paw5/src/main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Prototype Application/Paw5/src/main/java/finki/paw5/service/PetService.java
r8f1a362 r4103eaa 10 10 11 11 List<Pet> listpets(); 12 13 Pet findById(Integer id); 12 14 } -
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java
r8f1a362 r4103eaa 24 24 @Override 25 25 public List<Pet> listpets() {return this.petRepository.findAll();} 26 27 @Override 28 public Pet findById(Integer id) { 29 return this.petRepository.findById(id).get(); 30 } 26 31 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java
r8f1a362 r4103eaa 38 38 39 39 @PostMapping("/submit-post") 40 public String savePost(@RequestParam(required = false) String name, 41 @RequestParam String gender, 42 @RequestParam String ageGroup, 43 @RequestParam String size, 44 @RequestParam String species, 40 public String savePost(@RequestParam(required = false) Integer petId, 41 @RequestParam(required = false) boolean newPetCheckbox, 42 @RequestParam(required = false) String name, 43 @RequestParam(required = false) String gender, 44 @RequestParam(required = false) String ageGroup, 45 @RequestParam(required = false) String size, 46 @RequestParam(required = false) String species, 45 47 @RequestParam(required = false) String breed, 46 48 @RequestParam(required = false) String imageUrl, … … 50 52 Employee employee = (Employee) request.getSession().getAttribute("user"); 51 53 52 Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId()); 53 this.petService.save(pet); 54 if(newPetCheckbox == true){ 54 55 55 Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, employee.getId()); 56 this.postService.save(post); 56 Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId()); 57 this.petService.save(newPet); 58 59 Post post = new Post(LocalDate.now(), imageUrl, newPet.getId(), null, employee.getId()); 60 this.postService.save(post); 61 62 } else{ 63 64 Pet selectedPet = this.petService.findById(petId); 65 66 Post post = new Post(LocalDate.now(), imageUrl, selectedPet.getId(), null, employee.getId()); 67 this.postService.save(post); 68 69 } 57 70 58 71 return "redirect:/home"; -
Prototype Application/Paw5/src/main/resources/templates/create-post.html
r8f1a362 r4103eaa 11 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 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> 13 44 </head> 14 45 <body> … … 42 73 43 74 <div> 44 <label for="pet ">Select pet:</label>45 <select id="pet ">75 <label for="petId">Select pet:</label> 76 <select id="petId" name="petId"> 46 77 <option 47 78 th:each="pet :${pets}" 48 th:text="${pet.getName()}"> 79 th:text="${pet.getName()}" 80 th:value="${pet.getId()}"> 49 81 </option> 50 82 </select> … … 52 84 53 85 <div> 54 <label for="new pet">Add new pet:</label>55 <input id="new pet" name="newpet" placeholder="newpet" type="checkbox">86 <label for="newPetCheckbox">Add new pet:</label> 87 <input id="newPetCheckbox" name="newPetCheckbox" type="checkbox" onclick="addNewPet(this)"> 56 88 </div> 57 89 … … 62 94 name="name" 63 95 class="form-control" 64 placeholder="Enter name"> 96 placeholder="Enter name" 97 disabled> 65 98 </div> 66 99 … … 69 102 <select id="gender" 70 103 name="gender" 71 class="form-control"> 104 class="form-control" 105 disabled> 72 106 <option value = "MALE">male</option> 73 107 <option value = "FEMALE">female</option> … … 79 113 <select id="ageGroup" 80 114 name="ageGroup" 81 class="form-control"> 115 class="form-control" 116 disabled> 82 117 <option value = "YOUNG">young</option> 83 118 <option value = "ADULT">adult</option> … … 90 125 <select id="size" 91 126 name="size" 92 class="form-control"> 127 class="form-control" 128 disabled> 93 129 <option value = "XSMALL">extra small</option> 94 130 <option value = "SMALL">small</option> … … 103 139 <select id="species" 104 140 name="species" 105 class="form-control"> 141 class="form-control" 142 disabled> 106 143 <option value = "CAT">cat</option> 107 144 <option value = "DOG">dog</option> … … 116 153 name="breed" 117 154 class="form-control" 118 placeholder="Enter breed" > 155 placeholder="Enter breed" 156 disabled> 119 157 </div> 120 158 … … 125 163 name="imageUrl" 126 164 class="form-control" 127 placeholder="Enter image URL"> 165 placeholder="Enter image URL" 166 disabled> 128 167 <!-- <label for="upload">Image:</label> 129 168 <input id="upload" type="file" accept="image/*"> … … 137 176 name="canBeFostered" 138 177 class="form-control" 139 value=false> 178 value=false 179 disabled> 140 180 </div> 141 181
Note:
See TracChangeset
for help on using the changeset viewer.